[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: desktop-auto-save-timeout

From: Juri Linkov
Subject: Re: desktop-auto-save-timeout
Date: Fri, 06 Jun 2014 02:35:42 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

>> I realized now that the right way to implement the desktop auto-saving
>> is to activate an idle timer only on changes in the window configuration
>> by window-configuration-change-hook.
>> The desktop file is mostly about remembering a list of buffers and
>> windows.  There is no point in auto-saving each time point moves.
>> This is what web browsers do by auto-saving a list of tabs
>> only when you open/close a tab.
> Agreed.  We might lose some window-points and some buffers that have not
> been displayed yet in that case but this is no great harm.

This is implemented by this patch.  Not sure whether it fixes a regression or 

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el     2014-04-27 08:22:11 +0000
+++ lisp/desktop.el     2014-06-05 23:34:41 +0000
@@ -174,7 +174,8 @@ (define-minor-mode desktop-save-mode
   :global t
   :group 'desktop
   (if desktop-save-mode
-      (desktop-auto-save-set-timer)
+      (add-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)
+    (remove-hook 'window-configuration-change-hook 
 (defun desktop-save-mode-off ()
@@ -207,13 +208,18 @@ (defcustom desktop-save 'ask-if-new
 (defcustom desktop-auto-save-timeout auto-save-timeout
   "Number of seconds idle time before auto-save of the desktop.
+The idle timer activates auto-saving only when window configuration changes.
 This applies to an existing desktop file when `desktop-save-mode' is enabled.
 Zero or nil means disable auto-saving due to idleness."
   :type '(choice (const :tag "Off" nil)
                  (integer :tag "Seconds"))
   :set (lambda (symbol value)
          (set-default symbol value)
-         (ignore-errors (desktop-auto-save-set-timer)))
+         (ignore-errors
+          (if (and (integerp value) (> value 0))
+              (add-hook 'window-configuration-change-hook 
+            (remove-hook 'window-configuration-change-hook 
+            (desktop-auto-save-cancel-timer))))
   :group 'desktop
   :version "24.4")
@@ -1244,7 +1250,7 @@ (defun desktop-auto-save-set-timer ()
   (when (and (integerp desktop-auto-save-timeout)
             (> desktop-auto-save-timeout 0))
     (setq desktop-auto-save-timer
-         (run-with-idle-timer desktop-auto-save-timeout t
+         (run-with-idle-timer desktop-auto-save-timeout nil
 (defun desktop-auto-save-cancel-timer ()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]