unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
To: Cecil Westerhof <Cecil@decebal.nl>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to exclude a major mode from a hook
Date: Wed, 11 Feb 2015 11:15:01 +0100	[thread overview]
Message-ID: <878ug4hhzu.fsf@yahoo.fr> (raw)
In-Reply-To: <87twysx0nz.fsf@Equus.decebal.nl> (Cecil Westerhof's message of "Wed, 11 Feb 2015 10:22:40 +0100")

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



  parent reply	other threads:[~2015-02-11 10:15 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
2015-02-11 12:31   ` Cecil Westerhof
2015-02-11 10:15 ` Nicolas Richard [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=878ug4hhzu.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --cc=Cecil@decebal.nl \
    --cc=help-gnu-emacs@gnu.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).