From: "João Távora" <joaotavora@gmail.com>
To: Skip Montanaro <skip.montanaro@gmail.com>
Cc: "help-gnu-emacs@gnu.org List" <help-gnu-emacs@gnu.org>
Subject: Re: Temporarily suppress a hook?
Date: Mon, 9 Jul 2018 13:07:06 +0100 [thread overview]
Message-ID: <CALDnm51hbCkdVtZnNa-2cfow52sOk4WCxwf==oRDHdQ2t0Q3AQ@mail.gmail.com> (raw)
In-Reply-To: <CANc-5UwbppCftAZMnYLP81WVcOn7erJRrMMtqsF3L6-Dk3DP2g@mail.gmail.com>
On Mon, Jul 9, 2018, 02:40 Skip Montanaro <skip.montanaro@gmail.com> wrote:
> > I have before-save-hook defined in ~/.emacs
> > > (add-hook 'before-save-hook 'delete-trailing-whitespace)
>
>
> Both `add-hook' and `remove-hook' take an optional
> > LOCAL argument, to affect only the current buffer
> > (the buffer-local value of the hook).
> >
>
> It's not clear how that helps me. In essentially every other file I edit, I
> want to delete trailing whitespace, so I enable it globally. It seems
> buffer-local enabling of that hook would be appropriate if I only
> occasionally wanted to enable it.
>
Indeed, using remove-hook with a local argument in those special buffers
won't help you if you've already affected the global value of
before-save-hook.
But you can add the hook locally, as Drew suggests, in those buffers where
you need it, and refrain from doing so in the buffers where you don't.
Prog-mode is a very pervasive mode: many modes derive from it.
Here's what I mean
(add-hook 'prog-mode-hook
(lambda ()
(add-hook 'before-save-hook 'delete-trailing-whitespace nil t)))
Now, in those special files/buffers (some special major mode?), a
remove-hook should do what you want.
João
next prev parent reply other threads:[~2018-07-09 12:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 0:02 Temporarily suppress a hook? Skip Montanaro
2018-07-09 0:43 ` Drew Adams
2018-07-09 1:39 ` Skip Montanaro
2018-07-09 12:07 ` João Távora [this message]
2018-07-09 4:43 ` Bob Proulx
2018-07-09 5:21 ` Óscar Fuentes
2018-07-09 6:00 ` tomas
2018-07-09 7:53 ` Óscar Fuentes
2018-07-09 11:01 ` Skip Montanaro
2018-07-09 17:33 ` Marcin Borkowski
2018-07-09 14:41 ` Stefan Monnier
[not found] <mailman.3286.1531094567.1292.help-gnu-emacs@gnu.org>
2018-07-12 17:43 ` Emanuel Berg
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='CALDnm51hbCkdVtZnNa-2cfow52sOk4WCxwf==oRDHdQ2t0Q3AQ@mail.gmail.com' \
--to=joaotavora@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=skip.montanaro@gmail.com \
/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.