[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to exclude a major mode from a hook
From: |
Cecil Westerhof |
Subject: |
Re: How to exclude a major mode from a hook |
Date: |
Wed, 11 Feb 2015 13:31:03 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Op Wednesday 11 Feb 2015 10:50 CET schreef Fabrice Niessen:
> Cecil Westerhof wrote:
>> I had the following in my .emacs:
>> (add-hook 'before-save-hook 'delete-trailing-whitespace)
>>
>> But I also use Gnus and a signature starts with '-- ' and now the
>> space is deleted and it is not a signature anymore.
>>
>> So I rewrote it to: (add-hook 'before-save-hook (lambda () (when
>> (not (string= major-mode "message-mode"))
>> 'delete-trailing-whitespace)))
>
> I do have:
>
> ;; Nuke all trailing whitespaces in the buffer.
> (add-hook 'before-save-hook
> (lambda () ; Except for ...
> (unless (or (eq major-mode 'message-mode)
> ; ... where "-- " is the signature
> ; separator (for when using emacsclient
> ; to compose emails and doing C-x #).
> (eq major-mode 'diff-mode))
> ; ... where the patch file can't be
> ; changed!
> (delete-trailing-whitespace))))
At the moment I do not use diff-mode, but it does not hurt to add it.
;-)
Also your solution is a little more clear. (unless instead of not)
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof