[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to exclude a major mode from a hook
From: |
Nicolas Richard |
Subject: |
Re: How to exclude a major mode from a hook |
Date: |
Wed, 11 Feb 2015 11:15:01 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Hi,
Cecil Westerhof <Cecil@decebal.nl> writes:
> I had the following in my .emacs:
> (add-hook 'before-save-hook 'delete-trailing-whitespace)
IMO this is not the right thing to do, because one day you'll want to
edit a file in which trailing white spaces are important and you'll
wonder why it's all screwed up.
I would suggest to use a function that checks for trailing whitespaces
(with exceptions, such as the signature delimiter in message-mode) and
(interactievly) prompts if there is something to fix. I don't know if
such a function exists.
> So I rewrote it to:
> (add-hook 'before-save-hook (lambda () (when (not (string= major-mode
> "message-mode"))
> 'delete-trailing-whitespace)))
The condition
(string= major-mode "message-mode")
can be written as
(eq major-mode 'message-mode)
and would be better written as
(derived-mode-p 'message-mode)
--
Nicolas