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: Skip Montanaro
Subject: Re: Temporarily suppress a hook?
Date: Mon, 9 Jul 2018 06:01:16 -0500

On Mon, Jul 9, 2018, 1:00 AM <tomas@tuxteam.de> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Mon, Jul 09, 2018 at 07:21:12AM +0200, Óscar Fuentes wrote:
> > Skip Montanaro <skip.montanaro@gmail.com> writes:
>
> [...]
>
> > AFAIK, no. But you can use your own function instead of
> > delete-trailing-whitespace:
> >
> > (defun my-delete-trailing-whitespace ()
> >   (interactive)
> >   (unless my-special-buffer
> >     (delete-trailing-whitespace)))
>
> > (add-hook 'before-save-hook 'my-delete-trailing-whitespace)
> >
> > Or advice delete-trailing-whitespace.
>
> Or perhaps make the hook read a local variable you set in
> the file (see "file local variables") and act accordingly.
>
> This way you could declare whithin those special files that you
> don't want trailing space removed.
>

Thanks all. Óscar's idea seems to come closest to a solution. I might use
that to suppress the hook for files with, say, a ".txt" extension. Those
would benefit least from scrubbing all trailing whitespace. Or... I could
use a prefix argument and check to see if it's been set to a magic value.
C-u -7 C-x C-s. Assuming I can read any prefix arg set by the user.

Unfortunately, file local variables aren't too helpful here. "grep -f file"
reads a series of patterns from the named file, so interprets every line as
a pattern. While it might work to track on a file local variable section,
you run the risk of a line being a false positive match for a line in the
file(s) you're running grep against.

Skip

>


reply via email to

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