bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#16630: desktop-auto-save seems confusing


From: Juri Linkov
Subject: bug#16630: desktop-auto-save seems confusing
Date: Tue, 04 Feb 2014 09:50:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

> emacs -Q
> M-x desktop-save-mode RET
> M-x desktop-save RET /tmp RET
> C-h v desktop-auto-save-timer
>    -> still nil, still no auto-save
>
> As I said, nothing enables desktop-auto-save except after-init-hook.
>
> Whereas if I happen to customize desktop-auto-save-timeout, suddenly it
> will start auto-saving. This doesn't make much sense.

Yes, definitely `desktop-auto-save-set-timer' have to be called
in every place that changes one of the preconditions of
`desktop-auto-save' to save the desktop:

  (when (and desktop-save-mode
             (integerp desktop-auto-save-timeout)
             (> desktop-auto-save-timeout 0)
             ;; Avoid desktop saving during lazy loading.
             (not desktop-lazy-timer)
             ;; Save only to own desktop file.
             (eq (emacs-pid) (desktop-owner))
             desktop-dirname)

Here changes in the value of `desktop-auto-save-timeout'
are handled already by :set in its defcustom, `desktop-lazy-timer'
quickly becomes nil after reading the existing desktop.

So what remains to do is to activate the timer when
the value of `desktop-dirname' changes from nil to non-nil.
This happens in two commands `desktop-read' and `desktop-save'.
In the following patch `desktop-read' and `desktop-save'
will activate the auto-saving timer (its call from `after-init-hook'
is removed because it will be handled by `desktop-read').

Also the condition (eq (emacs-pid) (desktop-owner)) depends on bug#16157.
If it claims the lock only in `desktop-read' and `desktop-save'
then no more calls for `desktop-auto-save-set-timer' are necessary.

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el     2014-01-01 07:43:34 +0000
+++ lisp/desktop.el     2014-02-04 07:48:37 +0000
@@ -1012,7 +1012,10 @@ (defun desktop-save (dirname &optional r
                (write-region (point-min) (point-max) (desktop-full-file-name) 
nil 'nomessage))
              (setq desktop-file-checksum checksum)
              ;; We remember when it was modified (which is presumably just 
now).
-             (setq desktop-file-modtime (nth 5 (file-attributes 
(desktop-full-file-name)))))))))))
+             (setq desktop-file-modtime (nth 5 (file-attributes 
(desktop-full-file-name))))))))))
+  ;; When the desktop is saved not by auto-saving, activate the auto-saving 
timer.
+  (unless auto-save
+    (desktop-auto-save-set-timer)))
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
@@ -1103,5 +1106,8 @@ (defun desktop-read (&optional dirname)
            ;; 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))))
+           ;; Activate the auto-saving timer after setting
+           ;; `desktop-dirname' and `desktop-file-modtime'.
+           (desktop-auto-save-set-timer)
            ;; If it wasn't already, mark it as in-use, to bother other
            ;; desktop instances.
            (unless owner
@@ -1468,7 +1474,6 @@ (add-hook
         (setq desktop-save-mode nil)))
     (when desktop-save-mode
       (desktop-read)
-      (desktop-auto-save-set-timer)
       (setq inhibit-startup-screen t))))
 

> (Also, I guess the ignore-errors in the :set of desktop-auto-save-timeout
> isn't really needed, rather an :initialize is.)

Without ignore-errors, after doing

  emacs -Q
  M-x desktop-save-mode RET

it fails with

  Debugger entered--Lisp error: (void-function desktop-auto-save-set-timer)
    desktop-auto-save-set-timer()
    custom-initialize-reset(desktop-auto-save-timeout ...)
    custom-declare-variable(desktop-auto-save-timeout ...)
    byte-code(...)
    autoload-do-load((autoload "desktop" 870431 t nil) desktop-save-mode)
    command-execute(desktop-save-mode record)
    execute-extended-command(nil "desktop-save-mode")
    call-interactively(execute-extended-command nil nil)
    command-execute(execute-extended-command)





reply via email to

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