Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My emacs deletes trailing white space. How can I disable this behaviour?

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?

like image 519
Geo Avatar asked Jan 04 '13 20:01

Geo


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

like image 84
François Févotte Avatar answered Oct 16 '22 16:10

François Févotte


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-:).

like image 28
Bleeding Fingers Avatar answered Oct 16 '22 16:10

Bleeding Fingers


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

like image 2
Noah Avatar answered Oct 16 '22 15:10

Noah