From 6c8e0ae69b3488e4ff38527cc930202e9cd9a98e Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 16 Dec 2013 23:48:51 +0200 Subject: [PATCH] * lisp/desktop.el (desktop-auto-save-timeout): Change default to `auto-save-timeout'. Doc fix. (desktop-save): Skip the timestamp in desktop-saved-frameset when checking for auto-save changes. (desktop-auto-save): Don't call desktop-auto-save-set-timer since `desktop-auto-save' is called repeatedly by the idle timer. (desktop-auto-save-set-timer): Replace `run-with-timer' with `run-with-idle-timer' and a non-nil arg REPEAT. Doc fix. Fixes: debbugs:15331 --- etc/NEWS | 4 ++-- lisp/ChangeLog | 12 ++++++++++++ lisp/desktop.el | 39 ++++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ad385f4d37..0977accff3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -398,8 +398,8 @@ on the given date. ** Desktop -*** `desktop-auto-save-timeout' defines the number of seconds between -auto-saves of the desktop. +*** `desktop-auto-save-timeout' defines the number of seconds idle time +before auto-save of the desktop. *** `desktop-restore-frames', enabled by default, allows saving and restoring the frame/window configuration (frameset). Additional options diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0cf8ed3da1..1fe7bd62b0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2013-12-16 Juri Linkov + + * desktop.el (desktop-auto-save-timeout): Change default to + `auto-save-timeout'. Doc fix. + (desktop-save): Skip the timestamp in desktop-saved-frameset + when checking for auto-save changes. + (desktop-auto-save): Don't call desktop-auto-save-set-timer since + `desktop-auto-save' is called repeatedly by the idle timer. + (desktop-auto-save-set-timer): Replace `run-with-timer' with + `run-with-idle-timer' and a non-nil arg REPEAT. Doc fix. + (Bug#15331) + 2013-12-16 Juri Linkov * isearch.el (isearch-mode-map): Remove [escape] key bindinds. diff --git a/lisp/desktop.el b/lisp/desktop.el index cff78ba9da..bdb16c0026 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -191,9 +191,9 @@ determine where the desktop is saved." :group 'desktop :version "22.1") -(defcustom desktop-auto-save-timeout nil - "Number of seconds between auto-saves of the desktop. -Zero or nil means disable timer-based auto-saving." +(defcustom desktop-auto-save-timeout auto-save-timeout + "Number of seconds idle time before auto-save of the desktop. +Zero or nil means disable auto-saving due to idleness." :type '(choice (const :tag "Off" nil) (integer :tag "Seconds")) :set (lambda (symbol value) @@ -992,12 +992,21 @@ and don't save the buffer if they are the same." (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. - (let ((checksum (and auto-save (md5 (current-buffer) - (+ (point-min) 300) (point-max) - 'emacs-mule)))) - (unless (and auto-save (equal checksum desktop-file-checksum)) + ;; When auto-saving, avoid writing if nothing has changed since the last write. + (let* ((beg (and auto-save + (save-excursion + (goto-char (point-min)) + ;; Don't check the header with changing timestamp + (and (search-forward "Global section" nil t) + ;; Also skip the timestamp in desktop-saved-frameset + ;; if it's saved in the first non-header line + (search-forward "desktop-saved-frameset" + (line-beginning-position 3) t) + ;; This is saved after the timestamp + (search-forward (format "%S" desktop--app-id) nil t)) + (point)))) + (checksum (and beg (md5 (current-buffer) beg (point-max) 'emacs-mule)))) + (unless (and checksum (equal checksum desktop-file-checksum)) (let ((coding-system-for-write 'emacs-mule)) (write-region (point-min) (point-max) (desktop-full-file-name) nil 'nomessage)) (setq desktop-file-checksum checksum) @@ -1199,21 +1208,21 @@ Called by the timer created in `desktop-auto-save-set-timer'." ;; Save only to own desktop file. (eq (emacs-pid) (desktop-owner)) desktop-dirname) - (desktop-save desktop-dirname nil t)) - (desktop-auto-save-set-timer)) + (desktop-save desktop-dirname nil t))) (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 idle timer to call `desktop-auto-save' repeatedly +after that many seconds of idle time." (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)) (setq desktop-auto-save-timer - (run-with-timer desktop-auto-save-timeout nil - 'desktop-auto-save)))) + (run-with-idle-timer desktop-auto-save-timeout t + 'desktop-auto-save)))) ;; ---------------------------------------------------------------------------- ;;;###autoload -- 2.20.1