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

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

Re: Temporarily suppress a hook?


From: João Távora
Subject: Re: Temporarily suppress a hook?
Date: Mon, 9 Jul 2018 13:07:06 +0100

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


reply via email to

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