Emacs: Turn on `delete-trailing-whitespace' locally

master
Pierre Neidhardt 2017-06-22 18:09:31 +01:00
parent 8f3042fb71
commit 9f9370d196
2 changed files with 8 additions and 3 deletions

View File

@ -412,6 +412,11 @@ This does not interfere with `subword-mode'."
"Unconditionally add the `fmt' function to `before-save-hook'."
(add-hook 'before-save-hook 'fmt nil t))
(defun turn-on-delete-trailing-whitespace ()
"Unconditionally add the `delete-trailing-whitespace' function to `before-save-hook'."
(unless (string= (file-name-extension buffer-file-name) "csv")
(add-hook 'before-save-hook 'delete-trailing-whitespace nil t)))
(defun turn-off-indent-tabs ()
"Unconditionally turn off tab indentation."
(setq indent-tabs-mode nil))

View File

@ -110,12 +110,12 @@
;;; Reported at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23740.
;; (setq whitespace-action '(report-on-bogus))
;;; Add formatting functions to the buffer-local `before-save-hook'.
;;; WARNING: this can break some configuration files needing whitespaces at the
;;; end. This can also slow down saving on big files. Some modes (e.g. lisp) run
;;; `fmt' in their local hook, which is redundant with this.
;; (require 'functions) ; for `fmt'
;; (add-hook 'before-save-hook 'fmt)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; (add-hook 'find-file-hook 'turn-on-fmt-before-save)
(add-hook 'find-file-hook 'turn-on-delete-trailing-whitespace)
;;; Hippie expand
;; (global-set-key (kbd "M-/") 'hippie-expand)