Delete trailing whitespace, globally, by default

Also adds doom|disable-delete-trailing-whitespace hook, which can be
used to disable this behavior on a per-buffer basis. If you want to turn
off this global behavior:

  (remove-hook 'write-file-functions #'delete-trailing-whitespace)
This commit is contained in:
Henrik Lissner 2018-08-30 20:13:43 +02:00
parent fcf2a26329
commit edc9bf70af
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 18 additions and 10 deletions

View file

@ -281,6 +281,14 @@ with weak native support."
;;;###autoload
(defun doom|enable-delete-trailing-whitespace ()
"Enables the automatic deletion of trailing whitespaces upon file save, by
attaching `delete-trailing-whitespace' to a buffer-local `before-save-hook'."
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
"Enables the automatic deletion of trailing whitespaces upon file save.
i.e. adds `delete-trailing-whitespace' to `write-file-functions', buffer-locally."
(add-hook 'write-file-functions #'delete-trailing-whitespace nil t))
;;;###autoload
(defun doom|disable-delete-trailing-whitespace ()
"Disables the automatic deletion of trailing whitespaces upon file save.
i.e. removes `delete-trailing-whitespace' from `write-file-functions'."
(remove-hook 'write-file-functions #'delete-trailing-whitespace t))