Add helper functions for file encoding trouble
This will hide the extra line ending markers on windows.
This commit is contained in:
20
init.el
20
init.el
@@ -3,6 +3,8 @@
|
||||
(set-default-coding-systems 'utf-8)
|
||||
(set-language-environment 'utf-8)
|
||||
(set-selection-coding-system 'utf-8)
|
||||
;; Always use Unix line endings
|
||||
(setq-default buffer-file-coding-system 'utf-8-unix)
|
||||
|
||||
;; personal.el - personal settings
|
||||
(setq personal-file "~/.emacs.d/personal.el")
|
||||
@@ -388,6 +390,24 @@
|
||||
(slime-setup '(slime-fancy slime-quicklisp slime-asdf))
|
||||
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
|
||||
|
||||
;; Automatically hide line ending markers when unix/ms differences occur.
|
||||
;; This would usually be the case for files that have been edited on android and opened on windows.
|
||||
(defun hide-eol ()
|
||||
"Hide the ^M markers in the current buffer"
|
||||
(interactive)
|
||||
(setq buffer-display-table (make-display-table))
|
||||
(aset buffer-display-table ?\^M []))
|
||||
|
||||
(defun hide-eol-if-crlf ()
|
||||
"Hide ^M characters if file has CRLF line endings"
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward "\r$" nil t)
|
||||
(hide-eol))))
|
||||
|
||||
;; Add to find-file-hook to run on every file open
|
||||
(add-hook 'find-file-hook 'hide-eol-if-crlf)
|
||||
|
||||
;; Misc functions
|
||||
|
||||
(autoload 'diff-no-select "diff")
|
||||
|
||||
Reference in New Issue
Block a user