]> code.delx.au - gnu-emacs/blobdiff - lisp/desktop.el
* net/tramp.el (tramp-ssh-controlmaster-template): Make it a
[gnu-emacs] / lisp / desktop.el
index c60745a6b16012ca4d27aef2b03ee7565f075da2..1151bd434bc9a3fb53def09e91a2e13a6ae1f9d3 100644 (file)
@@ -1,10 +1,11 @@
 ;;; desktop.el --- save partial status of Emacs when killed
 
-;; Copyright (C) 1993-1995, 1997, 2000-2011  Free Software Foundation, Inc.
+;; Copyright (C) 1993-1995, 1997, 2000-2013 Free Software Foundation,
+;; Inc.
 
 ;; Author: Morten Welinder <terra@diku.dk>
 ;; Keywords: convenience
-;; Favourite-brand-of-beer: None, I hate beer.
+;; Favorite-brand-of-beer: None, I hate beer.
 
 ;; This file is part of GNU Emacs.
 
@@ -34,7 +35,7 @@
 ;;             - some local variables
 
 ;; To use this, use customize to turn on desktop-save-mode or add the
-;; following line somewhere in your .emacs file:
+;; following line somewhere in your init file:
 ;;
 ;;     (desktop-save-mode 1)
 ;;
@@ -145,20 +146,21 @@ backward compatibility.")
   "Save status of Emacs when you exit."
   :group 'frames)
 
+;; Maintained for backward compatibility
+(define-obsolete-variable-alias 'desktop-enable 'desktop-save-mode "22.1")
 ;;;###autoload
 (define-minor-mode desktop-save-mode
-  "Toggle desktop saving mode.
-With numeric ARG, turn desktop saving on if ARG is positive, off
-otherwise.  If desktop saving is turned on, the state of Emacs is
-saved from one session to another.  See variable `desktop-save'
-and function `desktop-read' for details."
+  "Toggle desktop saving (Desktop Save mode).
+With a prefix argument ARG, enable Desktop Save mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+If Desktop Save mode is enabled, the state of Emacs is saved from
+one session to another.  See variable `desktop-save' and function
+`desktop-read' for details."
   :global t
   :group 'desktop)
 
-;; Maintained for backward compatibility
-(define-obsolete-variable-alias 'desktop-enable
-                                'desktop-save-mode "22.1")
-
 (defun desktop-save-mode-off ()
   "Disable `desktop-save-mode'.  Provided for use in hooks."
   (desktop-save-mode 0))
@@ -219,7 +221,7 @@ the normal hook `desktop-not-loaded-hook' is run."
   :group 'desktop
   :version "22.2")
 
-(defcustom desktop-path (list "." user-emacs-directory "~")
+(defcustom desktop-path (list user-emacs-directory "~")
   "List of directories to search for the desktop file.
 The base name of the file is specified in `desktop-base-file-name'."
   :type '(repeat directory)
@@ -409,8 +411,7 @@ is passed as the argument DESKTOP-BUFFER-MISC to functions in
                         'desktop-save-buffer "22.1")
 
 ;;;###autoload
-(defvar desktop-buffer-mode-handlers
-  nil
+(defvar desktop-buffer-mode-handlers nil
   "Alist of major mode specific functions to restore a desktop buffer.
 Functions listed are called by `desktop-create-buffer' when `desktop-read'
 evaluates the desktop file.  List elements must have the form
@@ -470,8 +471,7 @@ this table.  See also `desktop-minor-mode-handlers'."
   :group 'desktop)
 
 ;;;###autoload
-(defvar desktop-minor-mode-handlers
-  nil
+(defvar desktop-minor-mode-handlers nil
   "Alist of functions to restore non-standard minor modes.
 Functions are called by `desktop-create-buffer' to restore minor modes.
 List elements must have the form
@@ -699,9 +699,9 @@ is nil, ask the user where to save the desktop."
 ;; ----------------------------------------------------------------------------
 (defun desktop-internal-v2s (value)
   "Convert VALUE to a pair (QUOTE . TXT); (eval (read TXT)) gives VALUE.
-TXT is a string that when read and evaluated yields value.
+TXT is a string that when read and evaluated yields VALUE.
 QUOTE may be `may' (value may be quoted),
-`must' (values must be quoted), or nil (value may not be quoted)."
+`must' (value must be quoted), or nil (value must not be quoted)."
   (cond
     ((or (numberp value) (null value) (eq t value) (keywordp value))
      (cons 'may (prin1-to-string value)))
@@ -826,7 +826,7 @@ MODE is the major mode.
          (or (and filename
                  (stringp desktop-files-not-to-save)
                   (not (string-match desktop-files-not-to-save filename)))
-             (and (eq mode 'dired-mode)
+             (and (memq mode '(dired-mode vc-dir-mode))
                   (with-current-buffer bufname
                     (not (setq dired-skip
                                (string-match desktop-files-not-to-save
@@ -967,8 +967,8 @@ It returns t if a desktop file was loaded, nil otherwise."
                (and dirs (car dirs)))
              ;; If not found and `desktop-path' is non-nil, use its first element.
              (and desktop-path (car desktop-path))
-             ;; Default: Home directory.
-             "~"))))
+             ;; Default: .emacs.d.
+             user-emacs-directory))))
     (if (file-exists-p (desktop-full-file-name))
        ;; Desktop file found, but is it already in use?
        (let ((desktop-first-buffer nil)
@@ -980,6 +980,7 @@ It returns t if a desktop file was loaded, nil otherwise."
          (if (and owner
                   (memq desktop-load-locked-desktop '(nil ask))
                   (or (null desktop-load-locked-desktop)
+                      (daemonp)
                       (not (y-or-n-p (format "Warning: desktop file appears to be in use by PID %s.\n\
 Using it may cause conflicts.  Use it anyway? " owner)))))
              (let ((default-directory desktop-dirname))
@@ -1019,6 +1020,18 @@ Using it may cause conflicts.  Use it anyway? " owner)))))
                         (format ", %d to restore lazily"
                                 (length desktop-buffer-args-list))
                       ""))
+           ;; Bury the *Messages* buffer to not reshow it when burying
+           ;; the buffer we switched to above.
+           (when (buffer-live-p (get-buffer "*Messages*"))
+             (bury-buffer "*Messages*"))
+           ;; Clear all windows' previous and next buffers, these have
+           ;; been corrupted by the `switch-to-buffer' calls in
+           ;; `desktop-restore-file-buffer' (bug#11556).  This is a
+           ;; brute force fix and should be replaced by a more subtle
+           ;; strategy eventually.
+           (walk-window-tree (lambda (window)
+                               (set-window-prev-buffers window nil)
+                               (set-window-next-buffers window nil)))
            t))
       ;; No desktop file found.
       (desktop-clear)
@@ -1033,11 +1046,10 @@ Using it may cause conflicts.  Use it anyway? " owner)))))
 (defun desktop-load-default ()
   "Load the `default' start-up library manually.
 Also inhibit further loading of it."
+  (declare (obsolete desktop-save-mode "22.1"))
   (unless inhibit-default-init         ; safety check
     (load "default" t t)
     (setq inhibit-default-init t)))
-(make-obsolete 'desktop-load-default
-               'desktop-save-mode "22.1")
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
@@ -1107,11 +1119,8 @@ directory DIRNAME."
 
 (defun desktop-load-file (function)
   "Load the file where auto loaded FUNCTION is defined."
-  (when function
-    (let ((fcell (and (fboundp function) (symbol-function function))))
-      (when (and (listp fcell)
-                 (eq 'autoload (car fcell)))
-        (load (cadr fcell))))))
+  (when (fboundp function)
+    (autoload-do-load (symbol-function function) function)))
 
 ;; ----------------------------------------------------------------------------
 ;; Create a buffer, load its file, set its mode, ...;
@@ -1155,7 +1164,7 @@ directory DIRNAME."
       (desktop-load-file desktop-buffer-major-mode)
       (let ((buffer-list (buffer-list))
            (result
-            (condition-case-no-debug err
+            (condition-case-unless-debug err
                 (funcall (or (cdr (assq desktop-buffer-major-mode
                                         desktop-buffer-mode-handlers))
                              'desktop-restore-file-buffer)
@@ -1173,7 +1182,7 @@ directory DIRNAME."
          (setq desktop-buffer-fail-count (1+ desktop-buffer-fail-count))
          (setq result nil))
        ;; Restore buffer list order with new buffer at end. Don't change
-       ;; the order for old desktop files (old desktop module behaviour).
+       ;; the order for old desktop files (old desktop module behavior).
        (unless (< desktop-file-version 206)
          (mapc 'bury-buffer buffer-list)
          (when result (bury-buffer result)))