diff options
author | Juri Linkov <juri@jurta.org> | 2014-06-25 02:23:41 +0300 |
---|---|---|
committer | Juri Linkov <juri@jurta.org> | 2014-06-25 02:23:41 +0300 |
commit | a4d8b73e1cb0f9c59a4f93170248dd85c5ee680c (patch) | |
tree | 1729aa22cfaebeeb13b7f2bedd9c0bed433399eb /lisp/desktop.el | |
parent | 370ceb22102e02a25516e43a61da0c9a9d6e1579 (diff) | |
download | emacs-a4d8b73e1cb0f9c59a4f93170248dd85c5ee680c.tar.gz |
* lisp/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.
Fixes: debbugs:17351
Diffstat (limited to 'lisp/desktop.el')
-rw-r--r-- | lisp/desktop.el | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lisp/desktop.el b/lisp/desktop.el index d420a6416a9..26d288bf9cd 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -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'." |