Upon save ( I think ), my emacs is deleting trailing white space. I don't want to commit those changes, only the parts I manually modify. Is there a way to disable that behaviour?
-
1For future reference, this [question](http://stackoverflow.com/q/14131492/1225607) is related to whitespace management only in modified parts of the file. – François Févotte Jan 04 '13 at 20:38
-
Did you get the answer? I see you neither accepted nor commented on replies — do you need maybe some more help? – Hi-Angel Nov 23 '17 at 21:07
3 Answers
This behaviour is not standard. It is however a very common customization that you might have borrowed somewhere. Look for something like the following in you init file and comment out those lines to get rid of this behaviour (and have Emacs save files as they are, without removing whitespace altogether):
(add-to-list 'write-file-functions 'delete-trailing-whitespace)
or
(add-hook 'before-save-hook 'delete-trailing-whitespace)
This emacswiki page gives tons of advice on handling trailing whitespace.
If you want to delete trailing whitespace only on lines you modify, you could try the ws-trim package

- 19,520
- 4
- 51
- 74
-
1Tempus: Yes, get rid of your existing customisation and use `ws-trim` -- it does exactly what you want when working under version control (and you can easily toggle the mode off, if you ever encounter a reason to do so). – phils Jan 05 '13 at 00:22
-
2Not sure if this helps anyone but ws-trim didn't work too well for me, so I made this: https://github.com/lewang/ws-butler ... It's less obstrusive. – event_jr Jan 05 '13 at 14:56
Like suggested in this answer the deleting-trailing-whitespace
hook might have been added to the before-save-hook
hook.
To disable this eval (remove-hook 'before-save-hook 'delete-trailing-whitespace)
(type M-:).

- 1
- 1

- 6,993
- 7
- 46
- 74
Take a look at ethan-wspace. It will clean up any whitespace that you made dirty yourself. However any incorrect whitespace that was there when you opened the file is left intact. This way you can avoid those messy diffs full of whitespace changes

- 33,851
- 5
- 37
- 32
-
From the description, it sounds like it won't clean up any whitespace unless the entire file had been in a clean state to begin with? That's not quite as useful as the approaches taken by ws-trim and ws-butler. – phils Apr 09 '13 at 13:48