all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Fabrice Niessen <fni-news-TA4HMoP+1wHrZ44/DZwexQ@public.gmane.org>
To: help-gnu-emacs-mXXj517/zsQ@public.gmane.org
Subject: Re: How to exclude a major mode from a hook
Date: Wed, 11 Feb 2015 10:50:11 +0100	[thread overview]
Message-ID: <86iof86alo.fsf@example.com> (raw)
In-Reply-To: 87twysx0nz.fsf@Equus.decebal.nl

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	other threads:[~2015-02-11  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11  9:22 How to exclude a major mode from a hook Cecil Westerhof
2015-02-11  9:50 ` Fabrice Niessen [this message]
2015-02-11 12:31   ` Cecil Westerhof
2015-02-11 10:15 ` Nicolas Richard
2015-02-12  2:39   ` Robert Thorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86iof86alo.fsf@example.com \
    --to=fni-news-ta4hmop+1whrz44/dzwexq@public.gmane.org \
    --cc=help-gnu-emacs-mXXj517/zsQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.