Discussion:
delete-trailing-whitespace on save
(too old to reply)
j***@gmail.com
2007-11-27 14:34:08 UTC
Permalink
I would like to automatically call delete-trailing-whitespace in
python-mode when I execute save-buffer. I assume there is some way
using advice, but my emacs lisp skills are very rusty! At first I
thought I could use an after-save-hook


(add-hook 'python-mode-hook
(lambda ()
(setq show-trailing-whitespace t)
(make-local-hook 'after-save-hook)
(add-hook 'after-save-hook 'delete-trailing-whitespace)))

but that deletes the whitespace *after* saving. I need something like
a before-save-hook. I googled before-save-hook and it appears there
was once such a beast, but it does not appear to be a variable in my
version of emacs (GNU Emacs 21.3.1)

Thanks,
JDH
Joost Kremers
2007-11-27 14:42:13 UTC
Permalink
Post by j***@gmail.com
thought I could use an after-save-hook
but that deletes the whitespace *after* saving.
as the name implies... ;-)
Post by j***@gmail.com
I need something like
a before-save-hook. I googled before-save-hook and it appears there
was once such a beast, but it does not appear to be a variable in my
version of emacs (GNU Emacs 21.3.1)
there is in my version (GNU Emacs 23.0.0.1), so i find it odd that you
don't have it. have you tried <C-h v before-save-hook RET>?
--
Joost Kremers ***@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
j***@gmail.com
2007-11-27 14:56:59 UTC
Permalink
Post by Joost Kremers
there is in my version (GNU Emacs 23.0.0.1), so i find it odd that you
don't have it. have you tried <C-h v before-save-hook RET>?
Yes, and it is not there... Unfortunately, upgrading is probably not
an option for me.

JDH
Will Parsons
2007-11-27 17:27:51 UTC
Permalink
Post by j***@gmail.com
I would like to automatically call delete-trailing-whitespace in
python-mode when I execute save-buffer. I assume there is some way
using advice, but my emacs lisp skills are very rusty! At first I
thought I could use an after-save-hook
(add-hook 'python-mode-hook
(lambda ()
(setq show-trailing-whitespace t)
(make-local-hook 'after-save-hook)
(add-hook 'after-save-hook 'delete-trailing-whitespace)))
but that deletes the whitespace *after* saving. I need something like
a before-save-hook. I googled before-save-hook and it appears there
was once such a beast, but it does not appear to be a variable in my
version of emacs (GNU Emacs 21.3.1)
Try 'write-file-hooks.

- Will

Loading...