I am aware that it is a good idea to have one blank line at the end of each file. I am also aware that extra white space in a file is bad. Currently in my .emacs file I have (add-hook 'before-save-hook 'delete-trailing-whitespace)
so that whitespace is removed during saving.
However, despite what the wiki says, this also deletes the final newline from my file.
I tried setting '(require-final-newline (quote visit-save))
but that had no effect.
Is there a way that I can force a newline to be added and all other extra whitespace removed?
ws-trim
orws-butler
libraries to ensure that lines you edit do not have trailing whitespace. You can always calldelete-trailing-whitespace
manually if you genuinely want to do this to a given file.ws-trim
due to inertia (it's been around much longer), but I thinkws-butler
has had some good improvements since it first appeared, and is possibly the better option, so I'd suggest trying that one first.package-install
it from MELPA and then put(ws-butler-global-mode 1)
in your init file, it looks like it should be enabled for all buffers. If you only want it for programming, start with(add-hook 'prog-mode-hook 'ws-butler-mode)
instead, as the majority of programming modes are derived fromprog-mode
.