diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 16:50:17 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 16:50:17 +0100 |
commit | 9434f1c213bb6f47b89200c61696268b9a3c38b7 (patch) | |
tree | aeff73c4d186789d7247d7234bbd9946e6a5616a /.config | |
parent | de334e5c0626492dbe0241d9c5bbc5e0adcef25e (diff) |
emacs: Auto-trim trailing whitespace
Diffstat (limited to '.config')
-rw-r--r-- | .config/emacs/init.el | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 86e1ca1..8c86c86 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -156,10 +156,12 @@ buffer suppressed." (kill-do-not-save-duplicates t) (large-file-warning-threshold nil) (make-backup-files nil) + (mode-require-final-newline nil) (next-error-recenter '(4)) ; ‘center of window’ (read-extended-command-predicate #'command-completion-default-include-p) (remote-file-name-inhibit-auto-save t) (remote-file-name-inhibit-delete-by-moving-to-trash t) + (require-final-newline nil) (save-interprogram-paste-before-kill t) (scroll-conservatively 101) ; (info "(Emacs)Auto Scrolling") (scroll-error-top-bottom t) @@ -177,6 +179,14 @@ buffer suppressed." (defun mm-set-fill-column () (setq-local fill-column 73)))) (add-hook 'text-mode-hook #'auto-fill-mode) + (add-hook 'before-save-hook + (defun mm-delete-final-newline () + (let ((end (point-max))) + (unless (or require-final-newline + mode-require-final-newline + (not (= (char-before end) ?\n))) + (delete-region (1- end) end))))) + (add-hook 'before-save-hook #'delete-trailing-whitespace) (prefer-coding-system 'utf-8) ;; Show trailing whitespace but only in relevant buffers |