]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/desktop.el (desktop-auto-save-enable)
authorJuri Linkov <juri@jurta.org>
Tue, 24 Jun 2014 23:23:41 +0000 (02:23 +0300)
committerJuri Linkov <juri@jurta.org>
Tue, 24 Jun 2014 23:23:41 +0000 (02:23 +0300)
(desktop-auto-save-disable): New functions.
(desktop-save-mode, desktop-auto-save-timeout): Use them.
(desktop-read): Disable the autosave before loading the desktop,
and enable afterwards.

Fixes: debbugs:17351
lisp/ChangeLog
lisp/desktop.el

index da8d49ae0a9cf4a7690b6e06cae7b6faf3bff10f..5981c50af77465da7d97b464a600f140b950af9f 100644 (file)
@@ -1,3 +1,11 @@
+2014-06-24  Juri Linkov  <juri@jurta.org>
+
+       * desktop.el (desktop-auto-save-enable)
+       (desktop-auto-save-disable): New functions.
+       (desktop-save-mode, desktop-auto-save-timeout): Use them.
+       (desktop-read): Disable the autosave before loading the desktop,
+       and enable afterwards.  (Bug#17351)
+
 2014-06-24  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        Fix some indentation problem with \; and pipes (bug#17842).
index d420a6416a961ff9bd22f37b638edfeefcff600f..26d288bf9cd7924b964a20500630de313f7ff04a 100644 (file)
@@ -174,11 +174,8 @@ For further details, see info node `(emacs)Saving Emacs Sessions'."
   :global t
   :group 'desktop
   (if desktop-save-mode
-      (when (and (integerp desktop-auto-save-timeout)
-                (> desktop-auto-save-timeout 0))
-       (add-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer))
-    (remove-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)
-    (desktop-auto-save-cancel-timer)))
+      (desktop-auto-save-enable)
+    (desktop-auto-save-disable)))
 
 (defun desktop-save-mode-off ()
   "Disable `desktop-save-mode'.  Provided for use in hooks."
@@ -219,9 +216,8 @@ Zero or nil means disable auto-saving due to idleness."
          (set-default symbol value)
          (ignore-errors
           (if (and (integerp value) (> value 0))
-              (add-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)
-            (remove-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)
-            (desktop-auto-save-cancel-timer))))
+              (desktop-auto-save-enable value)
+            (desktop-auto-save-disable))))
   :group 'desktop
   :version "24.4")
 
@@ -1132,6 +1128,10 @@ Using it may cause conflicts.  Use it anyway? " owner)))))
                (unless desktop-dirname
                  (message "Desktop file in use; not loaded.")))
            (desktop-lazy-abort)
+           ;; Temporarily disable the autosave that will leave it
+           ;; disabled when loading the desktop fails with errors,
+           ;; thus not overwriting the desktop with broken contents.
+           (desktop-auto-save-disable)
            ;; Evaluate desktop buffer and remember when it was modified.
            (load (desktop-full-file-name) t t t)
            (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name))))
@@ -1184,6 +1184,7 @@ Using it may cause conflicts.  Use it anyway? " owner)))))
                                  (set-window-prev-buffers window nil)
                                  (set-window-next-buffers window nil))))
            (setq desktop-saved-frameset nil)
+           (desktop-auto-save-enable)
            t))
       ;; No desktop file found.
       (desktop-clear)
@@ -1230,6 +1231,15 @@ directory DIRNAME."
 ;; Auto-Saving.
 (defvar desktop-auto-save-timer nil)
 
+(defun desktop-auto-save-enable (&optional timeout)
+  (when (and (integerp (or timeout desktop-auto-save-timeout))
+            (> (or timeout desktop-auto-save-timeout) 0))
+    (add-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)))
+
+(defun desktop-auto-save-disable ()
+  (remove-hook 'window-configuration-change-hook 'desktop-auto-save-set-timer)
+  (desktop-auto-save-cancel-timer))
+
 (defun desktop-auto-save ()
   "Save the desktop periodically.
 Called by the timer created in `desktop-auto-save-set-timer'."