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: Stefan Monnier
Subject: Re: Temporarily suppress a hook?
Date: Mon, 09 Jul 2018 10:41:02 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> I have before-save-hook defined in ~/.emacs
> (add-hook 'before-save-hook 'delete-trailing-whitespace)
[...]
> possible.  Is it possible to suppress the before-save-hook on a
> per-file basis?

I suggest you file a feature request (via M-x report-emacs-bug)

I think it should be possible to buffer-locally "remove" a function from
a hook, even if that function was added globally (I toyed with an
implementation of that idea which added `(not . FUNCTION)` to the
(buffer-local part of the) hook, and then `run-hook` would honor such
a value by disregarding any subsequent occurrence of FUNCTION).

With my hack, you'd be able to do:

    (add-hook 'my-special-mode-hook
              (lambda ()
                (remove-hook 'before-save-hook
                             #'delete-trailing-whitespace 'local)))

so that buffers using `my-special-mode` won't delete their trailing spaces.


        Stefan




reply via email to

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