GNU bug report logs - #25478
26.0.50; No hooks are called when auto-saving

Previous Next

Package: emacs;

Reported by: Philipp Stephani <p.stephani2 <at> gmail.com>

Date: Wed, 18 Jan 2017 21:40:01 UTC

Severity: wishlist

Found in version 26.0.50

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 25478 in the body.
You can then email your comments to 25478 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Wed, 18 Jan 2017 21:40:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philipp Stephani <p.stephani2 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 18 Jan 2017 21:40:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; No hooks are called when auto-saving
Date: Wed, 18 Jan 2017 22:39:13 +0100
The Emacs manual states:

"If you want auto-saving to be done in the visited file rather than in
a separate auto-save file, set the variable
‘auto-save-visited-file-name’ to a non-‘nil’ value.  In this mode, there
is no real difference between auto-saving and explicit saving."

However, there is a significant difference between auto-saving and
explicit saving, even in this mode: auto-saving doesn't run
before-save-hook, after-save-hook, write-contents-functions, or
write-file-functions.  Either some of these hooks should be run during
auto-saving if auto-save-visited-file-name is t, or new hooks should be
created to run in this case.


In GNU Emacs 26.0.50.38 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.8)
 of 2017-01-18 built on localhost
Repository revision: 5fefaaa8c0696ba4b7b6e1e89267aa10fff88b31
Windowing system distributor 'The X.Org Foundation', version 11.0.11501000
System Description:	Ubuntu 14.04 LTS

Recent messages:
Sending email 
Sending email done
Sending...done

Configured using:
 'configure --with-modules --enable-checking
 --enable-check-lisp-object-type 'CFLAGS=-ggdb3 -O0''

Configured features:
XPM JPEG TIFF GIF PNG SOUND GSETTINGS NOTIFY GNUTLS FREETYPE XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(network-stream nsm starttls tls gnutls mailalias smtpmail auth-source
cl-seq eieio eieio-core cl-macs eieio-loaddefs qp cus-edit cus-start
cus-load wid-edit pp shadow sort mail-extr emacsbug message subr-x puny
seq byte-opt gv bytecomp byte-compile cl-extra help-mode cconv
cl-loaddefs pcase cl-lib dired dired-loaddefs format-spec rfc822 mml
easymenu mml-sec password-cache epa derived epg epg-config gnus-util
rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript case-table epa-hook jka-cmpr-hook help
simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button
faces cus-face macroexp files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote inotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 125369 10956)
 (symbols 48 22403 1)
 (miscs 40 373 277)
 (strings 32 23633 8700)
 (string-bytes 1 753869)
 (vectors 16 22889)
 (vector-slots 8 1256392 202843)
 (floats 8 225 207)
 (intervals 56 502 0)
 (buffers 976 16)
 (heap 1024 42683 5682))

-- 
Google Germany GmbH
Erika-Mann-Straße 33
80636 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle

Diese E-Mail ist vertraulich.  Wenn Sie nicht der richtige Adressat sind,
leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen
Sie die E-Mail und alle Anhänge.  Vielen Dank.

This e-mail is confidential.  If you are not the right addressee please do not
forward it, please inform the sender, and please erase this e-mail including
any attachments.  Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Thu, 19 Jan 2017 20:30:03 GMT) Full text and rfc822 format available.

Message #8 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Thu, 19 Jan 2017 15:29:04 -0500
Philipp Stephani wrote:

> The Emacs manual states:
>
> "If you want auto-saving to be done in the visited file rather than in
> a separate auto-save file, set the variable
> 'auto-save-visited-file-name' to a non-'nil' value.  In this mode, there
> is no real difference between auto-saving and explicit saving."
>
> However, there is a significant difference between auto-saving and
> explicit saving, even in this mode: auto-saving doesn't run
> before-save-hook, after-save-hook, write-contents-functions, or
> write-file-functions.  Either some of these hooks should be run during
> auto-saving if auto-save-visited-file-name is t, or new hooks should be
> created to run in this case.


The phrasing of the manual can easily be changed if it's creating
unreasonable expectations.
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Fri, 20 Jan 2017 08:46:02 GMT) Full text and rfc822 format available.

Message #11 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: p.stephani2 <at> gmail.com, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Fri, 20 Jan 2017 10:45:05 +0200
> From: Glenn Morris <rgm <at> gnu.org>
> Date: Thu, 19 Jan 2017 15:29:04 -0500
> Cc: 25478 <at> debbugs.gnu.org
> 
> Philipp Stephani wrote:
> 
> > The Emacs manual states:
> >
> > "If you want auto-saving to be done in the visited file rather than in
> > a separate auto-save file, set the variable
> > 'auto-save-visited-file-name' to a non-'nil' value.  In this mode, there
> > is no real difference between auto-saving and explicit saving."
> >
> > However, there is a significant difference between auto-saving and
> > explicit saving, even in this mode: auto-saving doesn't run
> > before-save-hook, after-save-hook, write-contents-functions, or
> > write-file-functions.  Either some of these hooks should be run during
> > auto-saving if auto-save-visited-file-name is t, or new hooks should be
> > created to run in this case.
> 
> The phrasing of the manual can easily be changed if it's creating
> 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.  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.  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.  Auto-saving doesn't record the value, so if the user
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.  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.

(Not sure whether we should close this bug now that the documentation
is fixed.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Fri, 20 Jan 2017 17:43:02 GMT) Full text and rfc822 format available.

Message #14 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: p.stephani2 <at> gmail.com, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Fri, 20 Jan 2017 12:42:48 -0500
Eli Zaretskii wrote:

> All in all, I think this option is subtly dangerous and should be
> either deprecated or completely reimplemented to invoke
> basic-save-buffer instead.  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.

Deprecation sounds good to me.
I believe there's a "real-auto-save" package that does a standard save
at intervals.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sun, 26 Mar 2017 18:22:02 GMT) Full text and rfc822 format available.

Message #17 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Glenn Morris <rgm <at> gnu.org>
Cc: 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Sun, 26 Mar 2017 18:21:01 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> schrieb am Fr., 20. Jan. 2017 um 09:45 Uhr:

> > From: Glenn Morris <rgm <at> gnu.org>
> > Date: Thu, 19 Jan 2017 15:29:04 -0500
> > Cc: 25478 <at> debbugs.gnu.org
> >
> > Philipp Stephani wrote:
> >
> > > The Emacs manual states:
> > >
> > > "If you want auto-saving to be done in the visited file rather than in
> > > a separate auto-save file, set the variable
> > > 'auto-save-visited-file-name' to a non-'nil' value.  In this mode,
> there
> > > is no real difference between auto-saving and explicit saving."
> > >
> > > However, there is a significant difference between auto-saving and
> > > explicit saving, even in this mode: auto-saving doesn't run
> > > before-save-hook, after-save-hook, write-contents-functions, or
> > > write-file-functions.  Either some of these hooks should be run during
> > > auto-saving if auto-save-visited-file-name is t, or new hooks should be
> > > created to run in this case.
> >
> > The phrasing of the manual can easily be changed if it's creating
> > 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.  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.  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.  Auto-saving doesn't record the value, so if the user
> 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.  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.
>
>
That's quite unfortunate, as not having to bother with saving edits
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?
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sun, 26 Mar 2017 18:47:02 GMT) Full text and rfc822 format available.

Message #20 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Sun, 26 Mar 2017 21:45:59 +0300
> From: Philipp Stephani <p.stephani2 <at> gmail.com>
> Date: Sun, 26 Mar 2017 18:21:01 +0000
> Cc: 25478 <at> debbugs.gnu.org
> 
>  All in all, I think this option is subtly dangerous and should be
>  either deprecated or completely reimplemented to invoke
>  basic-save-buffer instead. 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.
> 
> That's quite unfortunate, as not having to bother with saving edits 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™ volunteering to reimplement
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?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sun, 26 Mar 2017 19:19:02 GMT) Full text and rfc822 format available.

Message #23 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Sun, 26 Mar 2017 19:17:53 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> schrieb am So., 26. März 2017 um 20:46 Uhr:

> > From: Philipp Stephani <p.stephani2 <at> gmail.com>
> > Date: Sun, 26 Mar 2017 18:21:01 +0000
> > Cc: 25478 <at> debbugs.gnu.org
> >
> >  All in all, I think this option is subtly dangerous and should be
> >  either deprecated or completely reimplemented to invoke
> >  basic-save-buffer instead. 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.
> >
> > That's quite unfortunate, as not having to bother with saving edits
> 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™ volunteering to reimplement
> 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?
>

Sounds reasonable. I'll try to come up with something by next weekend.
Probably it will be just

(defvar auto-save--timer nil)
(defcustom auto-save-visited-interval 5
  "seconds"
  :group 'files
  :type 'number
  :set (lambda (symbol value)
         (set-default symbol value)
         (when auto-save--timer
           (timer-set-idle-time auto-save--timer value :repeat))))
(define-minor-mode auto-save-visited-mode nil
  :group 'files
  :global t
  (when auto-save--timer (kill-timer auto-save--timer))
  (setq auto-save--timer
        (when auto-save-visited-mode
          (run-with-idle-timer
           auto-save-visited-interval :repeat
           #'save-some-buffers :no-prompt
           (lambda ()
             (not (and buffer-auto-save-file-name
auto-save-visited-file-name)))))))

but it will also need tests and documentation, which take a bit more time.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sat, 22 Apr 2017 19:03:01 GMT) Full text and rfc822 format available.

Message #26 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Sat, 22 Apr 2017 19:01:50 +0000
[Message part 1 (text/plain, inline)]
Philipp Stephani <p.stephani2 <at> gmail.com> schrieb am So., 26. März 2017 um
21:17 Uhr:

> Eli Zaretskii <eliz <at> gnu.org> schrieb am So., 26. März 2017 um 20:46 Uhr:
>
>> > From: Philipp Stephani <p.stephani2 <at> gmail.com>
>> > Date: Sun, 26 Mar 2017 18:21:01 +0000
>> > Cc: 25478 <at> debbugs.gnu.org
>> >
>> >  All in all, I think this option is subtly dangerous and should be
>> >  either deprecated or completely reimplemented to invoke
>> >  basic-save-buffer instead. 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.
>> >
>> > That's quite unfortunate, as not having to bother with saving edits
>> 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™ volunteering to reimplement
>> 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?
>>
>
> Sounds reasonable. I'll try to come up with something by next weekend.
> Probably it will be just
>
> (defvar auto-save--timer nil)
> (defcustom auto-save-visited-interval 5
>   "seconds"
>   :group 'files
>   :type 'number
>   :set (lambda (symbol value)
>          (set-default symbol value)
>          (when auto-save--timer
>            (timer-set-idle-time auto-save--timer value :repeat))))
> (define-minor-mode auto-save-visited-mode nil
>   :group 'files
>   :global t
>   (when auto-save--timer (kill-timer auto-save--timer))
>   (setq auto-save--timer
>         (when auto-save-visited-mode
>           (run-with-idle-timer
>            auto-save-visited-interval :repeat
>            #'save-some-buffers :no-prompt
>            (lambda ()
>              (not (and buffer-auto-save-file-name
> auto-save-visited-file-name)))))))
>
> but it will also need tests and documentation, which take a bit more time.
>

Here's a patch.
[Message part 2 (text/html, inline)]
[0001-Reimplement-auto-saving-to-visited-files.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Fri, 28 Apr 2017 09:29:01 GMT) Full text and rfc822 format available.

Message #29 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Fri, 28 Apr 2017 12:27:19 +0300
> From: Philipp Stephani <p.stephani2 <at> gmail.com>
> Date: Sat, 22 Apr 2017 19:01:50 +0000
> Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
> 
> Here's a patch. 

Thanks.  A few minor comments:

> --- a/doc/emacs/files.texi
> +++ b/doc/emacs/files.texi
> @@ -1040,14 +1040,13 @@ Auto Save Files
>  this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
>  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.  (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}.  In this mode, auto-saving is very
> +similar to explicit saving.

"Very similar" begs the question "what's the difference?"  If there
are differences, let's describe them; if there aren't, let's say
"identical to" or "the same as".

>                                Note that this mode is orthogonal to the
> +@code{auto-save} mode described above; you can enable both at the same
> +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?  This should be
documented.

> @@ -1091,6 +1090,13 @@ Auto Save Control
>  a while; second, it may avoid some auto-saving while you are actually
>  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.

> +  When @code{auto-save-visited-mode} is enabled, Emacs will auto-save
> +file-visiting buffers after five seconds of idle time.  You can
> +customize the variable @code{auto-save-visited-interval} to change the
> +idle time interval.  @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.  Doing so will also provide a good
opportunity to mention auto-save-visited-interval.

> +(defcustom auto-save-visited-interval 5
> +  "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."
> +  :group 'auto-save
> +  :type 'number
> +  :set (lambda (symbol value)
> +         (set-default symbol value)
> +         (when auto-save--timer
> +           (timer-set-idle-time auto-save--timer value :repeat))))

Please add a :version tag to new defcustoms.

> +(define-minor-mode auto-save-visited-mode
> +  "Toggle automatic saving to file-visiting buffers on or off.
> +With a prefix argument ARG, enable regular saving of all buffers
> +vising a file if ARG is positive, and disable it otherwise.
   ^^^^^^
A typo.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sat, 29 Apr 2017 18:48:01 GMT) Full text and rfc822 format available.

Message #32 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: 26.0.50; No hooks are called when auto-saving
Date: Sat, 29 Apr 2017 18:47:24 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> schrieb am Fr., 28. Apr. 2017 um 11:28 Uhr:

> > From: Philipp Stephani <p.stephani2 <at> gmail.com>
> > Date: Sat, 22 Apr 2017 19:01:50 +0000
> > Cc: rgm <at> gnu.org, 25478 <at> debbugs.gnu.org
> >
> > Here's a patch.
>
> Thanks.  A few minor comments:
>
> > --- a/doc/emacs/files.texi
> > +++ b/doc/emacs/files.texi
> > @@ -1040,14 +1040,13 @@ Auto Save Files
> >  this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
> >  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.  (If you do rename it, please
> also rename the time-interval variable accordingly.)
>

I think the name should be sufficiently different from auto-save-mode so
that the modes can't be confused. auto-save-files-mode would be confusing,
because auto-save-mode also saves files. I think including the "visited"
word is useful here because it's the meaningful distinction between the
modes: one uses the visited file name, the other doesn't.


>
> > +in a separate auto-save file, enable the global minor mode
> > +@code{auto-save-visited-mode}.  In this mode, auto-saving is very
> > +similar to explicit saving.
>
> "Very similar" begs the question "what's the difference?"  If there
> are differences, let's describe them; if there aren't, let's say
> "identical to" or "the same as".
>

Done.


>
> >                                Note that this mode is orthogonal to the
> > +@code{auto-save} mode described above; you can enable both at the same
> > +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?  This should be
> documented.
>

Done.


>
> > @@ -1091,6 +1090,13 @@ Auto Save Control
> >  a while; second, it may avoid some auto-saving while you are actually
> >  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.
>

Done.


>
> > +  When @code{auto-save-visited-mode} is enabled, Emacs will auto-save
> > +file-visiting buffers after five seconds of idle time.  You can
> > +customize the variable @code{auto-save-visited-interval} to change the
> > +idle time interval.  @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.  Doing so will also provide a good
> opportunity to mention auto-save-visited-interval.
>

Done.


>
> > +(defcustom auto-save-visited-interval 5
> > +  "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."
> > +  :group 'auto-save
> > +  :type 'number
> > +  :set (lambda (symbol value)
> > +         (set-default symbol value)
> > +         (when auto-save--timer
> > +           (timer-set-idle-time auto-save--timer value :repeat))))
>
> Please add a :version tag to new defcustoms.
>

Done.


>
> > +(define-minor-mode auto-save-visited-mode
> > +  "Toggle automatic saving to file-visiting buffers on or off.
> > +With a prefix argument ARG, enable regular saving of all buffers
> > +vising a file if ARG is positive, and disable it otherwise.
>    ^^^^^^
> A typo.
>

Done.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sat, 29 Apr 2017 18:50:02 GMT) Full text and rfc822 format available.

Message #35 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: eliz <at> gnu.org,
	emacs-devel <at> gnu.org,
	25478 <at> debbugs.gnu.org,
	rgm <at> gnu.org
Cc: Philipp Stephani <phst <at> google.com>
Subject: [PATCH] Reimplement auto-saving to visited files
Date: Sat, 29 Apr 2017 20:49:09 +0200
This reacts to confusing behavior of 'auto-save-visited-file-name',
cf. Bug#25478.

* lisp/files.el (auto-save-visited-interval): New customization option.
(auto-save-visited-mode): New global minor mode.
(auto-save-visited-file-name): Make obsolete.
(auto-save--timer): New internal helper variable.

* doc/emacs/files.texi (Auto Save Files): Document
'auto-save-visited-mode' instead of obsolete
'auto-save-visited-file-name'.
(Auto Save Control): Document customization option
'auto-save-visited-interval'.
---
 doc/emacs/files.texi | 29 ++++++++++++++++++++++-------
 etc/NEWS             |  6 ++++++
 lisp/files.el        | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index ed17f66ca2..55eda00d0c 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1040,14 +1040,23 @@ Auto Save Files
 this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
 auto-save-mode}.
 
-@vindex auto-save-visited-file-name
+@vindex auto-save-visited-mode
   If you want auto-saving to be done in the visited file rather than
-in a separate auto-save file, set the variable
-@code{auto-save-visited-file-name} to a non-@code{nil} value.  In this
-mode, auto-saving is very similar to explicit saving.  However,
-differences still exist, in particular for modes which modify the
-buffer-saving process in non-trivial ways via various hooks
-(@pxref{Saving Buffers,,, elisp, The Emacs Lisp Reference Manual}).
+in a separate auto-save file, enable the global minor mode
+@code{auto-save-visited-mode}.  In this mode, auto-saving is identical
+to explicit saving.  Note that this mode is orthogonal to the
+@code{auto-save} mode described above; you can enable both at the same
+time.  However, if @code{auto-save} mode is active in some buffer and
+the obsolete @code{auto-save-visited-file-name} variable is set to a
+non-@code{nil} value, that buffer won't be affected by
+@code{auto-save-visited-mode}.
+
+  You can use the variable @code{auto-save-visited-interval} to
+customize the interval between auto-save operations in
+@code{auto-save-visited-mode}; by default it's five seconds.
+@code{auto-save-interval} and @code{auto-save-timeout} have no effect
+on @code{auto-save-visited-mode}.  See @xref{Auto Save Control} for
+details on these variables.
 
 @vindex delete-auto-save-files
   A buffer's auto-save file is deleted when you save the buffer in its
@@ -1091,6 +1100,12 @@ Auto Save Control
 a while; second, it may avoid some auto-saving while you are actually
 typing.
 
+@vindex auto-save-visited-interval
+  When @code{auto-save-visited-mode} is enabled, Emacs will auto-save
+file-visiting buffers after five seconds of idle time.  You can
+customize the variable @code{auto-save-visited-interval} to change the
+idle time interval.
+
   Emacs also does auto-saving whenever it gets a fatal error.  This
 includes killing the Emacs job with a shell command such as @samp{kill
 %emacs}, or disconnecting a phone line or network connection.
diff --git a/etc/NEWS b/etc/NEWS
index 9d4c72d6dc..173c4e466b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -383,6 +383,12 @@ Strings such as ΌΣΟΣ are now correctly converted to Όσος when
 capitalized instead of incorrect Όσοσ (compare lowercase sigma at the
 end of the word).
 
+** Emacs can now auto-save buffers to visited files in a more robust
+manner via the new mode 'auto-save-visited-mode'.  Unlike
+'auto-save-visited-file-name', this mode uses the normal saving
+procedure and therefore obeys saving hooks.
+'auto-save-visited-file-name' is now obsolete.
+
 
 * Changes in Specialized Modes and Packages in Emacs 26.1
 
diff --git a/lisp/files.el b/lisp/files.el
index 6848818cad..d3958b5643 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -393,6 +393,46 @@ auto-save-file-name-transforms
   :initialize 'custom-initialize-delay
   :version "21.1")
 
+(defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.")
+
+(defcustom auto-save-visited-interval 5
+  "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."
+  :group 'auto-save
+  :type 'number
+  :version "26.1"
+  :set (lambda (symbol value)
+         (set-default symbol value)
+         (when auto-save--timer
+           (timer-set-idle-time auto-save--timer value :repeat))))
+
+(define-minor-mode auto-save-visited-mode
+  "Toggle automatic saving to file-visiting buffers on or off.
+With a prefix argument ARG, enable regular saving of all buffers
+visiting a file if ARG is positive, and disable it otherwise.
+Unlike `auto-save-mode', this mode will auto-save buffer contents
+to the visited files directly and will also run all save-related
+hooks.  See Info node `Saving' for details of the save process.
+
+If called from Lisp, enable the mode if ARG is omitted or nil,
+and toggle it if ARG is `toggle'."
+  :group 'auto-save
+  :global t
+  (when auto-save--timer (kill-timer auto-save--timer))
+  (setq auto-save--timer
+        (when auto-save-visited-mode
+          (run-with-idle-timer
+           auto-save-visited-interval :repeat
+           #'save-some-buffers :no-prompt
+           (lambda ()
+             (not (and buffer-auto-save-file-name
+                       auto-save-visited-file-name)))))))
+
+(make-obsolete-variable 'auto-save-visited-file-name 'auto-save-visited-mode
+                        "Emacs 26.1")
+
 (defcustom save-abbrevs t
   "Non-nil means save word abbrevs too when files are saved.
 If `silently', don't ask the user before saving."
-- 
2.12.2





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sat, 29 Apr 2017 19:22:02 GMT) Full text and rfc822 format available.

Message #38 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: phst <at> google.com, rgm <at> gnu.org, 25478 <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: Re: [PATCH] Reimplement auto-saving to visited files
Date: Sat, 29 Apr 2017 22:20:18 +0300
> From: Philipp Stephani <p.stephani2 <at> gmail.com>
> Cc: Philipp Stephani <phst <at> google.com>
> Date: Sat, 29 Apr 2017 20:49:09 +0200
> 
> +on @code{auto-save-visited-mode}.  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.  Thanks for working on this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Sat, 29 Apr 2017 19:32:02 GMT) Full text and rfc822 format available.

Message #41 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: phst <at> google.com, rgm <at> gnu.org, 25478 <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: Re: [PATCH] Reimplement auto-saving to visited files
Date: Sat, 29 Apr 2017 19:31:06 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> schrieb am Sa., 29. Apr. 2017 um 21:21 Uhr:

> > From: Philipp Stephani <p.stephani2 <at> gmail.com>
> > Cc: Philipp Stephani <phst <at> google.com>
> > Date: Sat, 29 Apr 2017 20:49:09 +0200
> >
> > +on @code{auto-save-visited-mode}.  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.  Thanks for working on this.
>

Thanks, pushed as 4db844a453 and 89159e78bb.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25478; Package emacs. (Tue, 11 Aug 2020 08:09:01 GMT) Full text and rfc822 format available.

Message #44 received at 25478 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: phst <at> google.com, rgm <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 25478 <at> debbugs.gnu.org
Subject: Re: bug#25478: [PATCH] Reimplement auto-saving to visited files
Date: Tue, 11 Aug 2020 01:08:34 -0700
Philipp Stephani <p.stephani2 <at> gmail.com> writes:

> Eli Zaretskii <eliz <at> gnu.org> schrieb am Sa., 29. Apr. 2017 um 21:21 Uhr:
>
>  > From: Philipp Stephani <p.stephani2 <at> gmail.com>
>  > Cc: Philipp Stephani <phst <at> google.com>
>  > Date: Sat, 29 Apr 2017 20:49:09 +0200
>  >
>  > +on @code{auto-save-visited-mode}.  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.  Thanks for working on this.
>
> Thanks, pushed as 4db844a453 and 89159e78bb.

It seems like all the patches here were pushed.  Should this therefore
also be closed, or is there more to do here?

Best regards,
Stefan Kangas




Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Thu, 01 Oct 2020 12:12:02 GMT) Full text and rfc822 format available.

Notification sent to Philipp Stephani <p.stephani2 <at> gmail.com>:
bug acknowledged by developer. (Thu, 01 Oct 2020 12:12:02 GMT) Full text and rfc822 format available.

Message #49 received at 25478-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: phst <at> google.com, rgm <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 25478-done <at> debbugs.gnu.org
Subject: Re: bug#25478: [PATCH] Reimplement auto-saving to visited files
Date: Thu, 1 Oct 2020 05:11:50 -0700
Stefan Kangas <stefan <at> marxist.se> writes:

> Philipp Stephani <p.stephani2 <at> gmail.com> writes:
>
>> Eli Zaretskii <eliz <at> gnu.org> schrieb am Sa., 29. Apr. 2017 um 21:21 Uhr:
>>
>>  > From: Philipp Stephani <p.stephani2 <at> gmail.com>
>>  > Cc: Philipp Stephani <phst <at> google.com>
>>  > Date: Sat, 29 Apr 2017 20:49:09 +0200
>>  >
>>  > +on @code{auto-save-visited-mode}.  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.  Thanks for working on this.
>>
>> Thanks, pushed as 4db844a453 and 89159e78bb.
>
> It seems like all the patches here were pushed.  Should this therefore
> also be closed, or is there more to do here?

More information was requested, but none was given within 7 weeks, so
I'm closing this bug.  If this is still an issue, please reply to this
email (use "Reply to all" in your email client) and we can reopen the
bug report.

Best regards,
Stefan Kangas




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 30 Oct 2020 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 172 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.