From 9f9370d196e9739f614a70ff3cdd923aa94b6575 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 22 Jun 2017 18:09:31 +0100 Subject: [PATCH] Emacs: Turn on `delete-trailing-whitespace' locally --- .emacs.d/lisp/functions.el | 5 +++++ .emacs.d/lisp/main.el | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.emacs.d/lisp/functions.el b/.emacs.d/lisp/functions.el index ba6ed27a..9f268798 100644 --- a/.emacs.d/lisp/functions.el +++ b/.emacs.d/lisp/functions.el @@ -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)) diff --git a/.emacs.d/lisp/main.el b/.emacs.d/lisp/main.el index 383d330c..8cded5ed 100644 --- a/.emacs.d/lisp/main.el +++ b/.emacs.d/lisp/main.el @@ -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)