:global t
:group 'desktop
(if desktop-save-mode
- (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."
(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))
+ (desktop-auto-save-enable value)
+ (desktop-auto-save-disable))))
:group 'desktop
:version "24.4")
:group 'desktop)
(defcustom desktop-restore-frames t
- "When non-nil, save frames to desktop file."
+ "When non-nil, save and restore the frame and window configuration.
+See related options `desktop-restore-reuses-frames',
+`desktop-restore-in-current-display', and `desktop-restore-forces-onscreen'."
:type 'boolean
:group 'desktop
:version "24.4")
(defcustom desktop-restore-in-current-display nil
- "If t, frames are restored in the current display.
-If nil, frames are restored, if possible, in their original displays.
-If `delete', frames on other displays are deleted instead of restored."
+ "Controls how restoring of frames treats displays.
+If t, restores frames into the current display.
+If nil, restores frames into their original displays (if possible).
+If `delete', deletes frames on other displays instead of restoring them."
:type '(choice (const :tag "Restore in current display" t)
(const :tag "Restore in original display" nil)
(const :tag "Delete frames in other displays" delete))
:version "24.4")
(defcustom desktop-restore-forces-onscreen t
- "If t, offscreen frames are restored onscreen instead.
-If `all', frames that are partially offscreen are also forced onscreen.
-NOTE: Checking of frame boundaries is only approximate and can fail
-to reliably detect frames whose onscreen/offscreen state depends on a
-few pixels, especially near the right / bottom borders of the screen."
+ "If t, restores frames that are fully offscreen onscreen instead.
+If `all', also restores frames that are partially offscreen onscreen.
+
+Note that checking of frame boundaries is only approximate.
+It can fail to reliably detect frames whose onscreen/offscreen state
+depends on a few pixels, especially near the right / bottom borders
+of the screen."
:type '(choice (const :tag "Only fully offscreen frames" t)
(const :tag "Also partially offscreen frames" all)
(const :tag "Do not force frames onscreen" nil))
(defcustom desktop-restore-reuses-frames t
"If t, restoring frames reuses existing frames.
-If nil, existing frames are deleted.
-If `keep', existing frames are kept and not reused."
+If nil, deletes existing frames.
+If `keep', keeps existing frames and does not reuse them."
:type '(choice (const :tag "Reuse existing frames" t)
(const :tag "Delete existing frames" nil)
(const :tag "Keep existing frames" :keep))
"Convert VALUE to a string that when read evaluates to the same value.
Not all types of values are supported."
(let* ((print-escape-newlines t)
+ (print-length nil)
+ (print-level nil)
(float-output-format nil)
(quote.sexp (desktop--v2s value))
(quote (car quote.sexp))
- (txt
- (let ((print-quoted t))
- (prin1-to-string (cdr quote.sexp)))))
+ (print-quoted t)
+ (txt (prin1-to-string (cdr quote.sexp))))
(if (eq quote 'must)
(concat "'" txt)
txt)))
(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))))
(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)
;; 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'."
(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
'desktop-auto-save))))
(defun desktop-auto-save-cancel-timer ()