GNU bug report logs - #15331
Idle timer for desktop

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> jurta.org>

Date: Tue, 10 Sep 2013 21:06:01 UTC

Severity: wishlist

Tags: patch

Done: Juri Linkov <juri <at> jurta.org>

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 15331 in the body.
You can then email your comments to 15331 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#15331; Package emacs. (Tue, 10 Sep 2013 21:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 10 Sep 2013 21:06:01 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: bug-gnu-emacs <at> gnu.org
Subject: Idle timer for desktop
Date: Tue, 10 Sep 2013 23:57:31 +0300
Tags: patch

It's very distracting when periodic desktop saves interrupt the
active editing for approximately 2 seconds to save the desktop.
This is because `desktop-auto-save-timeout' ignores idleness when
better to save the desktop in convenient time without distraction.

This means that another idle timer is necessary in addition
to the idleness-ignoring timer.  As were discussed some time ago
on emacs-devel both timers are needed.  This patch implements
proper interaction between these two timers.

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el	2013-07-01 03:29:46 +0000
+++ lisp/desktop.el	2013-09-10 20:50:10 +0000
@@ -191,7 +191,14 @@ (defcustom desktop-save 'ask-if-new
 
 (defcustom desktop-auto-save-timeout nil
   "Number of seconds between auto-saves of the desktop.
-Zero or nil means disable timer-based auto-saving."
+Zero or nil means disable timer-based auto-saving.
+If `desktop-auto-save-idle-timeout' is non-nil then the desktop is
+not saved immediately after the timeout of `desktop-auto-save-timeout',
+but another idle timer is set that saves the desktop after the number
+of idle seconds defined by `desktop-auto-save-idle-timeout'.
+Thus the total timeout between desktop auto-saves is the sum
+of seconds of `desktop-auto-save-timeout' plus idle seconds
+of `desktop-auto-save-idle-timeout'."
   :type '(choice (const :tag "Off" nil)
                  (integer :tag "Seconds"))
   :set (lambda (symbol value)
@@ -202,6 +209,24 @@ (defcustom desktop-auto-save-timeout nil
   :group 'desktop
   :version "24.4")
 
+(defcustom desktop-auto-save-idle-timeout nil
+  "Number of idle seconds between auto-saves of the desktop.
+Zero or nil means disable timer-based idle auto-saving.
+If `desktop-auto-save-timeout' is non-nil then an idle timer
+is set after the timeout defined by `desktop-auto-save-timeout'.
+Thus the total timeout between desktop auto-saves is the sum
+of seconds of `desktop-auto-save-timeout' plus idle seconds
+of `desktop-auto-save-idle-timeout'."
+  :type '(choice (const :tag "Off" nil)
+                 (integer :tag "Idle Seconds"))
+  :set (lambda (symbol value)
+         (set-default symbol value)
+         (condition-case nil
+	     (desktop-auto-save-set-timer)
+	   (error nil)))
+  :group 'desktop
+  :version "24.4")
+
 (defcustom desktop-load-locked-desktop 'ask
   "Specifies whether the desktop should be loaded if locked.
 Possible values are:
@@ -1219,8 +1244,10 @@ (defun desktop-auto-save ()
   "Save the desktop periodically.
 Called by the timer created in `desktop-auto-save-set-timer'."
   (when (and desktop-save-mode
-	     (integerp desktop-auto-save-timeout)
-	     (> desktop-auto-save-timeout 0)
+	     (or (and (integerp desktop-auto-save-timeout)
+		      (> desktop-auto-save-timeout 0))
+		 (and (integerp desktop-auto-save-idle-timeout)
+		      (> desktop-auto-save-idle-timeout 0)))
 	     ;; Avoid desktop saving during lazy loading.
 	     (not desktop-lazy-timer)
 	     ;; Save only to own desktop file.
@@ -1230,17 +1257,46 @@ (defun desktop-auto-save ()
   (desktop-auto-save-set-timer))
 
 (defun desktop-auto-save-set-timer ()
-  "Reset the auto-save timer.
+  "Set the auto-save timer.
 Cancel any previous timer.  When `desktop-auto-save-timeout' is a positive
-integer, start a new timer to call `desktop-auto-save' in that many seconds."
+integer, start a new timer to call `desktop-auto-save' in that many seconds.
+When `desktop-auto-save-idle-timeout' is a positive integer,
+then start a new timer to call `desktop-auto-save-set-idle-timer'."
+  (when desktop-auto-save-timer
+    (cancel-timer desktop-auto-save-timer)
+    (setq desktop-auto-save-timer nil))
+  (if (and (integerp desktop-auto-save-timeout)
+	   (> desktop-auto-save-timeout 0))
+      (if (and (integerp desktop-auto-save-idle-timeout)
+	       (> desktop-auto-save-idle-timeout 0))
+	  (setq desktop-auto-save-timer
+		(run-with-timer desktop-auto-save-timeout nil
+				'desktop-auto-save-set-idle-timer))
+	(setq desktop-auto-save-timer
+	      (run-with-timer desktop-auto-save-timeout nil
+			      'desktop-auto-save)))
+    (if (and (integerp desktop-auto-save-idle-timeout)
+	     (> desktop-auto-save-idle-timeout 0))
+	(desktop-auto-save-set-idle-timer))))
+
+(defun desktop-auto-save-set-idle-timer ()
+  "Set the auto-save idle timer.
+Cancel any previous timer.  When `desktop-auto-save-idle-timeout' is a positive
+integer, start a new idle timer to call `desktop-auto-save' in that number
+of idle seconds."
   (when desktop-auto-save-timer
     (cancel-timer desktop-auto-save-timer)
     (setq desktop-auto-save-timer nil))
-  (when (and (integerp desktop-auto-save-timeout)
-	     (> desktop-auto-save-timeout 0))
+  (when (and (integerp desktop-auto-save-idle-timeout)
+	     (> desktop-auto-save-idle-timeout 0))
     (setq desktop-auto-save-timer
-	  (run-with-timer desktop-auto-save-timeout nil
-			  'desktop-auto-save))))
+	  (run-with-idle-timer
+	   ;; Compute an idle time desktop-auto-save-idle-timeout
+	   ;; more than the current value.
+	   (time-add (or (current-idle-time) '(0 0 0 0))
+		     (seconds-to-time desktop-auto-save-idle-timeout))
+	   nil
+	   'desktop-auto-save))))
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15331; Package emacs. (Wed, 11 Sep 2013 17:25:02 GMT) Full text and rfc822 format available.

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

From: Sam Steingold <sds <at> gnu.org>
To: 15331 <at> debbugs.gnu.org
Cc: juri <at> jurta.org
Subject: desktop should auto-save on idle time
Date: Wed, 11 Sep 2013 13:23:52 -0400
I think the proposed solution is overly complicated.
I think the better solution is to use idle timer instead and default
`desktop-auto-save-timeout' to `auto-save-timeout' (i.e., enable by default).

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X 11.0.11303000
http://www.childpsy.net/ http://palestinefacts.org http://www.memritv.org
http://pmw.org.il http://ffii.org http://memri.org
Parachute for sale, used once, never opened, small stain.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15331; Package emacs. (Wed, 11 Sep 2013 19:48:01 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Sam Steingold <sds <at> gnu.org>
Cc: 15331 <at> debbugs.gnu.org
Subject: Re: desktop should auto-save on idle time
Date: Wed, 11 Sep 2013 22:45:48 +0300
> I think the proposed solution is overly complicated.
> I think the better solution is to use idle timer instead and default
> `desktop-auto-save-timeout' to `auto-save-timeout' (i.e., enable by default).

You can't use idle timers even with such reasonable timeouts
as 5 minutes between saves, i.e. when the user needs to save
the desktop every 5 minutes, with idle timers the user have to sit
inactively 5 minutes waiting for Godot^H^H^H^H^H desktop saving.
Thus desktop saving requires two different timers out of necessity.

You can see the whole relevant emacs-devel thread
where this problem was discussed here:
http://thread.gmane.org/gmane.emacs.bugs/17096/focus=158816




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15331; Package emacs. (Thu, 12 Sep 2013 00:58:02 GMT) Full text and rfc822 format available.

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

From: Juanma Barranquero <lekktu <at> gmail.com>
To: Juri Linkov <juri <at> jurta.org>
Cc: Sam Steingold <sds <at> gnu.org>, 15331 <at> debbugs.gnu.org
Subject: Re: bug#15331: desktop should auto-save on idle time
Date: Thu, 12 Sep 2013 02:56:20 +0200
On Wed, Sep 11, 2013 at 9:45 PM, Juri Linkov <juri <at> jurta.org> wrote:

> You can't use idle timers even with such reasonable timeouts
> as 5 minutes between saves, i.e. when the user needs to save
> the desktop every 5 minutes, with idle timers the user have to sit
> inactively 5 minutes waiting for Godot^H^H^H^H^H desktop saving.
> Thus desktop saving requires two different timers out of necessity.

Or, the desktop can be saved after 5 minutes (or whatever) of idle
time, and if the user needs more frequency, they can bind
desktop-save-in-desktop-dir and do it manually...

When I'm writing or translating with LibreOffice, I do not trust
autosaving. I type Ctrl-S after every paragraph. Seems saner.

   J




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15331; Package emacs. (Thu, 12 Sep 2013 21:04:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Juanma Barranquero <lekktu <at> gmail.com>
Cc: Sam Steingold <sds <at> gnu.org>, 15331 <at> debbugs.gnu.org
Subject: Re: bug#15331: desktop should auto-save on idle time
Date: Thu, 12 Sep 2013 23:58:16 +0300
>> You can't use idle timers even with such reasonable timeouts
>> as 5 minutes between saves, i.e. when the user needs to save
>> the desktop every 5 minutes, with idle timers the user have to sit
>> inactively 5 minutes waiting for Godot^H^H^H^H^H desktop saving.
>> Thus desktop saving requires two different timers out of necessity.
>
> Or, the desktop can be saved after 5 minutes (or whatever) of idle
> time, and if the user needs more frequency, they can bind
> desktop-save-in-desktop-dir and do it manually...

Or use the timer to display every 5 minutes a message
"Don't forget to type M-x desktop-save-in-desktop-dir RET" :-)

> When I'm writing or translating with LibreOffice, I do not trust
> autosaving. I type Ctrl-S after every paragraph. Seems saner.

Unlike LibreOffice, we can fix desktop.el in a way
that you'll trust Emacs autosaving :-)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15331; Package emacs. (Mon, 16 Sep 2013 21:37:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Juanma Barranquero <lekktu <at> gmail.com>
Cc: Sam Steingold <sds <at> gnu.org>, 15331 <at> debbugs.gnu.org
Subject: Re: bug#15331: desktop should auto-save on idle time
Date: Tue, 17 Sep 2013 00:18:52 +0300
Another problem is that `desktop-saved-frameset' added to the desktop
now prevents auto-saving from detecting whether the contents of the
desktop file changed.  It now auto-saves the desktop always because
`desktop-saved-frameset' now contains a timestamp.

This patch skips these lines with a timestamp, so the remaining
content of the desktop can be checked for changes.

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el	2013-09-15 16:25:02 +0000
+++ lisp/desktop.el	2013-09-16 21:18:39 +0000
@@ -1012,10 +1012,16 @@ (defun desktop-save (dirname &optional r
 		(insert ")\n\n"))))
 
 	  (setq default-directory desktop-dirname)
-	  ;; If auto-saving, avoid writing if nothing has changed since the last write.
-	  ;; Don't check 300 characters of the header that contains the timestamp.
+	  ;; When auto-saving, avoid writing if nothing has changed
+	  ;; since the last write.  Don't check 10 lines of the header
+	  ;; with constantly-changing timestamp and also don't check
+	  ;; the first non-header line with desktop-saved-frameset
+	  ;; that also contains a timestamp.
 	  (let ((checksum (and auto-save (md5 (current-buffer)
-					      (+ (point-min) 300) (point-max)
+					      (save-excursion
+						(goto-char (point-min))
+						(line-beginning-position 11))
+					      (point-max)
 					      'emacs-mule))))
 	    (unless (and auto-save (equal checksum desktop-file-checksum))
 	      (let ((coding-system-for-write 'emacs-mule))





Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Mon, 16 Dec 2013 21:50:02 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> jurta.org>:
bug acknowledged by developer. (Mon, 16 Dec 2013 21:50:05 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Sam Steingold <sds <at> gnu.org>
Cc: 15331-done <at> debbugs.gnu.org
Subject: bug#15331: desktop should auto-save on idle time
Date: Mon, 16 Dec 2013 23:49:06 +0200
> I think the proposed solution is overly complicated.
> I think the better solution is to use idle timer instead and default
> `desktop-auto-save-timeout' to `auto-save-timeout' (i.e., enable by default).

I like the simplicity too, and since there were less
requests for the real-time timer than for the idle timer,
I just replaced the former with the latter.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 14 Jan 2014 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 125 days ago.

Previous Next


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