help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to exclude a major mode from a hook


From: Fabrice Niessen
Subject: Re: How to exclude a major mode from a hook
Date: Wed, 11 Feb 2015 10:50:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt)

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:

--8<---------------cut here---------------start------------->8---
  ;; 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))))
--8<---------------cut here---------------end--------------->8---

Best regards,
Fabrice

-- 
Fabrice Niessen
Leuven, Belgium
http://www.pirilampo.org/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]