From unknown Fri Sep 05 22:44:35 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#25478 <25478@debbugs.gnu.org> To: bug#25478 <25478@debbugs.gnu.org> Subject: Status: 26.0.50; No hooks are called when auto-saving Reply-To: bug#25478 <25478@debbugs.gnu.org> Date: Sat, 06 Sep 2025 05:44:35 +0000 retitle 25478 26.0.50; No hooks are called when auto-saving reassign 25478 emacs submitter 25478 Philipp Stephani
> From: Glenn Morris <rgm@gnu.org>
> Date: Thu, 19 Jan 2017 15:29:04 -0500
> Cc: 25478@debbugs.gnu.org
>
> Philipp Stephani wrote:
>
> > The Emacs manual states:
> >
> > "If you want auto-saving to be done in the visited file rath= er than in
> > a separate auto-save file, set the variable
> > 'auto-save-visited-file-name' to a non-'nil' valu= e.=C2=A0 In this mode, there
> > is no real difference between auto-saving and explicit saving.&qu= ot;
> >
> > However, there is a significant difference between auto-saving an= d
> > explicit saving, even in this mode: auto-saving doesn't run > > before-save-hook, after-save-hook, write-contents-functions, or > > write-file-functions.=C2=A0 Either some of these hooks should be = run during
> > auto-saving if auto-save-visited-file-name is t, or new hooks sho= uld be
> > created to run in this case.
>
> The phrasing of the manual can easily be changed if it's creating<= br class=3D"gmail_msg"> > unreasonable expectations.
I've done that now on the release branch.
> Do you have a use case for autosave running hooks?
> One could argue that it is a low-level
> operation that should not be modifiable in this way.
Auto-save has its own hook.=C2=A0 But that's just the tip of an iceberg= ,
because nowadays various modes can completely change what happens at
save-buffer time by using the hooks mentioned above, and those hooks
run only when basic-save-buffer is invoked; they won't be run during
auto-saving.
And there are other differences, too.=C2=A0 E.g., if save-buffer asks the user for a suitable encoding, it will record the value used in
buffer-file-coding-system, so that future saves reuse that
automatically.=C2=A0 Auto-saving doesn't record the value, so if the us= er
doesn't change the buffer's file encoding manually, she will be
prompted to provide an encoding on every auto-save.
All in all, I think this option is subtly dangerous and should be
either deprecated or completely reimplemented to invoke
basic-save-buffer instead.=C2=A0 I'm quite sure this option made sense = in
the past, when complications with encoding and save-related hooks
didn't exist, but that is no longer the case in Emacs these days.
If someone thinks using this option will allow them not to bother with
saving their edits, they are in for an unpleasant surprise.
> From: Philipp Stephani <p.stephani2@gmail.com><= br class=3D"gmail_msg"> > Date: Sun, 26 Mar 2017 18:21:01 +0000
> Cc: 25478@debbugs.gnu.org
>
>=C2=A0 All in all, I think this option is subtly dangerous and should b= e
>=C2=A0 either deprecated or completely reimplemented to invoke
>=C2=A0 basic-save-buffer instead. I'm quite sure this option made s= ense in
>=C2=A0 the past, when complications with encoding and save-related hook= s
>=C2=A0 didn't exist, but that is no longer the case in Emacs these = days.
>=C2=A0 If someone thinks using this option will allow them not to bothe= r with
>=C2=A0 saving their edits, they are in for an unpleasant surprise.
>
> That's quite unfortunate, as not having to bother with saving edit= s manually is a very desirable feature that I
> think Emacs should offer out of the box.
>
> If you really want to deprecate auto-save-visited-file-name, how about= adding a simple global minor mode that
> invokes save-some-buffers from an idle timer to files.el?
As I wrote, I'm also okay with Someone=E2=84=A2 volunteering to reimple= ment
this option such that it invokes basic-save-buffer instead.
A minor mode that you describe would also be fine, but then it should
probably disable auto-saving if auto-save-visited-file-name is set,
right?
> From: Philipp Steph= ani <p.stephani2@gmail.com>
> Date: Sun, 26 Mar 2017 18:21:01 +0000
> Cc: 25478@debbugs.gnu.org
>
>=C2=A0 All in all, I think this option is subtly dangerous and should b= e
>=C2=A0 either deprecated or completely reimplemented to invoke
>=C2=A0 basic-save-buffer instead. I'm quite sure this option made s= ense in
>=C2=A0 the past, when complications with encoding and save-related hook= s
>=C2=A0 didn't exist, but that is no longer the case in Emacs these = days.
>=C2=A0 If someone thinks using this option will allow them not to bothe= r with
>=C2=A0 saving their edits, they are in for an unpleasant surprise.
>
> That's quite unfortunate, as not having to bother with saving edit= s manually is a very desirable feature that I
> think Emacs should offer out of the box.
>
> If you really want to deprecate auto-save-visited-file-name, how about= adding a simple global minor mode that
> invokes save-some-buffers from an idle timer to files.el?
As I wrote, I'm also okay with Someone=E2=84=A2 volunteering to reimple= ment
this option such that it invokes basic-save-buffer instead.
A minor mode that you describe would also be fine, but then it should
probably disable auto-saving if auto-save-visited-file-name is set,
right?
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Sat, 22 Apr 2017 19:01:50 +0000
> Cc: rgm@gnu.org, = 25478@debbugs.gn= u.org
>
> Here's a patch.
Thanks.=C2=A0 A few minor comments:
> --- a/doc/emacs/files.texi
> +++ b/doc/emacs/files.texi
> @@ -1040,14 +1040,13 @@ Auto Save Files
>=C2=A0 this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-= u 1 M-x
>=C2=A0 auto-save-mode}.
>
> -@vindex auto-save-visited-file-name
> +@vindex auto-save-visited-mode
I wonder whether auto-save-files-mode is a better name, as the
"visited" part looks now out of place.=C2=A0 (If you do rename it= , please
also rename the time-interval variable accordingly.)
> +in a separate auto-save file, enable the global minor mode
> +@code{auto-save-visited-mode}.=C2=A0 In this mode, auto-saving is ver= y
> +similar to explicit saving.
"Very similar" begs the question "what's the difference?= "=C2=A0 If there
are differences, let's describe them; if there aren't, let's sa= y
"identical to" or "the same as".
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Note that this mode is orthogonal= to the
> +@code{auto-save} mode described above; you can enable both at the sam= e
> +time.
But if auto-save mode is enabled and auto-save-visited-file-name is
set, then this new mode will not auto-save, right?=C2=A0 This should be
documented.
> @@ -1091,6 +1090,13 @@ Auto Save Control
>=C2=A0 a while; second, it may avoid some auto-saving while you are act= ually
>=C2=A0 typing.
>
> +@vindex auto-save-visited-interval
I suggest to mention this variable where you describe the new mode,
since the two descriptions are several tens of lines apart.
> +=C2=A0 When @code{auto-save-visited-mode} is enabled, Emacs will auto= -save
> +file-visiting buffers after five seconds of idle time.=C2=A0 You can<= br> > +customize the variable @code{auto-save-visited-interval} to change th= e
> +idle time interval.=C2=A0 @code{auto-save-interval} and
> +@code{auto-save-timeout} have no effect on this mode.
I think the last sentence should be part of the description of the
mode, not of the variable.=C2=A0 Doing so will also provide a good
opportunity to mention auto-save-visited-interval.
> +(defcustom auto-save-visited-interval 5
> +=C2=A0 "Interval in seconds for `auto-save-visited-mode'.
> +If `auto-save-visited-mode' is enabled, Emacs will save all
> +buffers visiting a file to the visited file after it has been
> +idle for `auto-save-visited-interval' seconds."
> +=C2=A0 :group 'auto-save
> +=C2=A0 :type 'number
> +=C2=A0 :set (lambda (symbol value)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set-default symbol value)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when auto-save--timer
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(timer-set-idle-time auto-sa= ve--timer value :repeat))))
Please add a :version tag to new defcustoms.
> +(define-minor-mode auto-save-visited-mode
> +=C2=A0 "Toggle automatic saving to file-visiting buffers on or o= ff.
> +With a prefix argument ARG, enable regular saving of all buffers
> +vising a file if ARG is positive, and disable it otherwise.
=C2=A0 =C2=A0^^^^^^
A typo.
> From: Philipp Stephani <p.stephani2@gmail.com>
> Cc: Philipp Stephani <phst@google.com>
> Date: Sat, 29 Apr 2017 20:49:09 +0200
>
> +on @code{auto-save-visited-mode}.=C2=A0 See @xref{Auto Save Control} = for
@xref itself produces "See", so the "See" before it is = unnecessary.
Other than that, I think this can go in.=C2=A0 Thanks for working on this.<= br>