Subject: Re: bug#65864: [PATCH] Add option to save a buffer without running save hooks

From: Stefan Kangas <[email-masked]>
Date: Wed, 12 Feb 2025 06:27:41 -0800

Stefan Monnier <[email-masked]> writes:

>> I don't necessarily object, but how can we usefully document this
>> behavior? who are those users that know by heart the hooks run by
>> save-buffer?  And without knowing that, how can a user decide whether
>> she does or doesn't want to use this feature: perhaps omitting some
>> hook disables behavior that is very important to the user?
>
> It does seem like a blunt way to affect `time-stamp`.

Yes, it does seem like a sharp tool.  OTOH, we have some of them in
Emacs already.  Maybe we could make disabled-command cover it, somehow?

> Maybe the time-stamp package should instead provide a prefix command
> `time-stamp-inhibit` which makes the next call to `time-stamp`
> do nothing.

My use case for disabling `before-save-hook` with a prefix argument is
that in `emacs-lisp-mode`, I have this `before-save-hook`:

    (aggressive-indent--process-changed-list-and-indent
     ws-butler-before-save time-stamp)

Sometimes, I would really like to disable all three when saving.
Now, I can of course disable the modes, run special commands for
time-stamp, and so on.  It just seems less convenient.

I have also seen variations on hooks like these recommended online:

    (delete-trailing-whitespace time-stamp
     my-recompile-el check-parens)

Where `my-recompile-el` is some function that would automatically
recompile the file.

In cases such as these, the prefix argument would mean "just save this
file now without doing any other special processing".

That said, if this functionality is not considered generally useful, I'm
of course happy to add it to my local hacks and move on.

> Or a more hackish way would be for `time-stamp` to consult
> `current-prefix-arg`, so as to disable the update of the time stamp when
> you do `C-u - C-x C-s`.

That could work, but yes hackish, and wouldn't it mean that we'd have to
potentially reproduce the hack in `ws-butler-mode`, `check-parens`,
`delete-trailing-whitespace`, and so on?