* bug#15331: Idle timer for desktop
@ 2013-09-10 20:57 Juri Linkov
2013-09-11 17:23 ` bug#15331: desktop should auto-save on idle time Sam Steingold
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2013-09-10 20:57 UTC (permalink / raw)
To: 15331
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-10 20:57 bug#15331: Idle timer for desktop Juri Linkov
@ 2013-09-11 17:23 ` Sam Steingold
2013-09-11 19:45 ` Juri Linkov
2013-12-16 21:49 ` Juri Linkov
0 siblings, 2 replies; 7+ messages in thread
From: Sam Steingold @ 2013-09-11 17:23 UTC (permalink / raw)
To: 15331
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-11 17:23 ` bug#15331: desktop should auto-save on idle time Sam Steingold
@ 2013-09-11 19:45 ` Juri Linkov
2013-09-12 0:56 ` Juanma Barranquero
2013-12-16 21:49 ` Juri Linkov
1 sibling, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2013-09-11 19:45 UTC (permalink / raw)
To: Sam Steingold; +Cc: 15331
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-11 19:45 ` Juri Linkov
@ 2013-09-12 0:56 ` Juanma Barranquero
2013-09-12 20:58 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Juanma Barranquero @ 2013-09-12 0:56 UTC (permalink / raw)
To: Juri Linkov; +Cc: Sam Steingold, 15331
On Wed, Sep 11, 2013 at 9:45 PM, Juri Linkov <juri@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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-12 0:56 ` Juanma Barranquero
@ 2013-09-12 20:58 ` Juri Linkov
2013-09-16 21:18 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2013-09-12 20:58 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Sam Steingold, 15331
>> 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 :-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-12 20:58 ` Juri Linkov
@ 2013-09-16 21:18 ` Juri Linkov
0 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2013-09-16 21:18 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Sam Steingold, 15331
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))
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15331: desktop should auto-save on idle time
2013-09-11 17:23 ` bug#15331: desktop should auto-save on idle time Sam Steingold
2013-09-11 19:45 ` Juri Linkov
@ 2013-12-16 21:49 ` Juri Linkov
1 sibling, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2013-12-16 21:49 UTC (permalink / raw)
To: Sam Steingold; +Cc: 15331-done
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-12-16 21:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-10 20:57 bug#15331: Idle timer for desktop Juri Linkov
2013-09-11 17:23 ` bug#15331: desktop should auto-save on idle time Sam Steingold
2013-09-11 19:45 ` Juri Linkov
2013-09-12 0:56 ` Juanma Barranquero
2013-09-12 20:58 ` Juri Linkov
2013-09-16 21:18 ` Juri Linkov
2013-12-16 21:49 ` Juri Linkov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.