]> code.delx.au - gnu-emacs/blobdiff - lisp/desktop.el
Close bug#3992.
[gnu-emacs] / lisp / desktop.el
index 8be86571f1335e71660b55df7ab0368c6939e4f1..c247565af20dcc53ae53b56874263a3b3cf4c028 100644 (file)
@@ -1,7 +1,8 @@
 ;;; desktop.el --- save partial status of Emacs when killed
 
 ;; Copyright (C) 1993, 1994, 1995, 1997, 2000, 2001, 2002, 2003,
 ;;; desktop.el --- save partial status of Emacs when killed
 
 ;; Copyright (C) 1993, 1994, 1995, 1997, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation, Inc.
 
 ;; Author: Morten Welinder <terra@diku.dk>
 ;; Keywords: convenience
 
 ;; Author: Morten Welinder <terra@diku.dk>
 ;; Keywords: convenience
 
 ;; This file is part of GNU Emacs.
 
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +21,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
@@ -42,7 +41,7 @@
 ;;     (desktop-save-mode 1)
 ;;
 ;; For further usage information, look at the section
 ;;     (desktop-save-mode 1)
 ;;
 ;; For further usage information, look at the section
-;; "Saving Emacs Sessions" in the GNU Emacs Manual.
+;; (info "(emacs)Saving Emacs Sessions") in the GNU Emacs Manual.
 
 ;; When the desktop module is loaded, the function `desktop-kill' is
 ;; added to the `kill-emacs-hook'.  This function is responsible for
 
 ;; When the desktop module is loaded, the function `desktop-kill' is
 ;; added to the `kill-emacs-hook'.  This function is responsible for
@@ -84,7 +83,7 @@
 ;;    (add-to-list 'desktop-minor-mode-handlers
 ;;                 '(bar-mode . bar-desktop-restore))
 
 ;;    (add-to-list 'desktop-minor-mode-handlers
 ;;                 '(bar-mode . bar-desktop-restore))
 
-;; in the module itself, and make shure that the mode function is
+;; in the module itself, and make sure that the mode function is
 ;; autoloaded.  See the docstrings of `desktop-buffer-mode-handlers' and
 ;; `desktop-minor-mode-handlers' for more info.
 
 ;; autoloaded.  See the docstrings of `desktop-buffer-mode-handlers' and
 ;; `desktop-minor-mode-handlers' for more info.
 
@@ -167,7 +166,7 @@ and function `desktop-read' for details."
   (desktop-save-mode 0))
 
 (defcustom desktop-save 'ask-if-new
   (desktop-save-mode 0))
 
 (defcustom desktop-save 'ask-if-new
-  "*Specifies whether the desktop should be saved when it is killed.
+  "Specifies whether the desktop should be saved when it is killed.
 A desktop is killed when the user changes desktop or quits Emacs.
 Possible values are:
    t             -- always save.
 A desktop is killed when the user changes desktop or quits Emacs.
 Possible values are:
    t             -- always save.
@@ -206,13 +205,14 @@ the normal hook `desktop-not-loaded-hook' is run."
   :group 'desktop
   :version "22.2")
 
   :group 'desktop
   :version "22.2")
 
+(define-obsolete-variable-alias 'desktop-basefilename
+                                'desktop-base-file-name "22.1")
+
 (defcustom desktop-base-file-name
   (convert-standard-filename ".emacs.desktop")
   "Name of file for Emacs desktop, excluding the directory part."
   :type 'file
   :group 'desktop)
 (defcustom desktop-base-file-name
   (convert-standard-filename ".emacs.desktop")
   "Name of file for Emacs desktop, excluding the directory part."
   :type 'file
   :group 'desktop)
-(define-obsolete-variable-alias 'desktop-basefilename
-                                'desktop-base-file-name "22.1")
 
 (defcustom desktop-base-lock-name
   (convert-standard-filename ".emacs.desktop.lock")
 
 (defcustom desktop-base-lock-name
   (convert-standard-filename ".emacs.desktop.lock")
@@ -221,12 +221,12 @@ the normal hook `desktop-not-loaded-hook' is run."
   :group 'desktop
   :version "22.2")
 
   :group 'desktop
   :version "22.2")
 
-(defcustom desktop-path '("." "~")
+(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)
   :group 'desktop
   "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)
   :group 'desktop
-  :version "22.1")
+  :version "23.2")                      ; user-emacs-directory added
 
 (defcustom desktop-missing-file-warning nil
   "If non-nil, offer to recreate the buffer of a deleted file.
 
 (defcustom desktop-missing-file-warning nil
   "If non-nil, offer to recreate the buffer of a deleted file.
@@ -277,7 +277,8 @@ for example."
     tags-table-list
     search-ring
     regexp-search-ring
     tags-table-list
     search-ring
     regexp-search-ring
-    register-alist)
+    register-alist
+    file-name-history)
   "List of global variables saved by `desktop-save'.
 An element may be variable name (a symbol) or a cons cell of the form
 \(VAR . MAX-SIZE), which means to truncate VAR's value to at most
   "List of global variables saved by `desktop-save'.
 An element may be variable name (a symbol) or a cons cell of the form
 \(VAR . MAX-SIZE), which means to truncate VAR's value to at most
@@ -302,10 +303,12 @@ to the value obtained by evaluating FORM."
   :version "22.1")
 
 (defcustom desktop-clear-preserve-buffers
   :version "22.1")
 
 (defcustom desktop-clear-preserve-buffers
-  '("\\*scratch\\*" "\\*Messages\\*" "\\*server\\*" "\\*tramp/.+\\*")
-  "*List of buffers that `desktop-clear' should not delete.
+  '("\\*scratch\\*" "\\*Messages\\*" "\\*server\\*" "\\*tramp/.+\\*"
+    "\\*Warnings\\*")
+  "List of buffers that `desktop-clear' should not delete.
 Each element is a regular expression.  Buffers with a name matched by any of
 these won't be deleted."
 Each element is a regular expression.  Buffers with a name matched by any of
 these won't be deleted."
+  :version "23.3"                       ; added Warnings - bug#6336
   :type '(repeat string)
   :group 'desktop)
 
   :type '(repeat string)
   :group 'desktop)
 
@@ -333,19 +336,19 @@ modes are restored automatically; they should not be listed here."
   :type '(repeat symbol)
   :group 'desktop)
 
   :type '(repeat symbol)
   :group 'desktop)
 
-;; We skip .log files because they are normally temporary.
-;;         (ftp) files because they require passwords and whatnot.
-(defcustom desktop-buffers-not-to-save
-  "\\(^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\)$"
+(defcustom desktop-buffers-not-to-save nil
   "Regexp identifying buffers that are to be excluded from saving."
   "Regexp identifying buffers that are to be excluded from saving."
-  :type 'regexp
+  :type '(choice (const :tag "None" nil)
+                regexp)
+  :version "23.2"                       ; set to nil
   :group 'desktop)
 
 ;; Skip tramp and ange-ftp files
 (defcustom desktop-files-not-to-save
   :group 'desktop)
 
 ;; Skip tramp and ange-ftp files
 (defcustom desktop-files-not-to-save
-  "^/[^/:]*:"
+  "\\(^/[^/:]*:\\|(ftp)$\\)"
   "Regexp identifying files whose buffers are to be excluded from saving."
   "Regexp identifying files whose buffers are to be excluded from saving."
-  :type 'regexp
+  :type '(choice (const :tag "None" nil)
+                regexp)
   :group 'desktop)
 
 ;; We skip TAGS files to save time (tags-file-name is saved instead).
   :group 'desktop)
 
 ;; We skip TAGS files to save time (tags-file-name is saved instead).
@@ -356,7 +359,7 @@ modes are restored automatically; they should not be listed here."
   :group 'desktop)
 
 (defcustom desktop-file-name-format 'absolute
   :group 'desktop)
 
 (defcustom desktop-file-name-format 'absolute
-  "*Format in which desktop file names should be saved.
+  "Format in which desktop file names should be saved.
 Possible values are:
    absolute -- Absolute file name.
    tilde    -- Relative to ~.
 Possible values are:
    absolute -- Absolute file name.
    tilde    -- Relative to ~.
@@ -454,7 +457,9 @@ Furthermore the major mode function must be autoloaded.")
 (defcustom desktop-minor-mode-table
   '((auto-fill-function auto-fill-mode)
     (vc-mode nil)
 (defcustom desktop-minor-mode-table
   '((auto-fill-function auto-fill-mode)
     (vc-mode nil)
-    (vc-dired-mode nil))
+    (vc-dired-mode nil)
+    (erc-track-minor-mode nil)
+    (savehist-mode nil))
   "Table mapping minor mode variables to minor mode functions.
 Each entry has the form (NAME RESTORE-FUNCTION).
 NAME is the name of the buffer-local variable indicating that the minor
   "Table mapping minor mode variables to minor mode functions.
 Each entry has the form (NAME RESTORE-FUNCTION).
 NAME is the name of the buffer-local variable indicating that the minor
@@ -809,16 +814,23 @@ which means to truncate VAR's value to at most MAX-SIZE elements
 FILENAME is the visited file name, BUFNAME is the buffer name, and
 MODE is the major mode.
 \n\(fn FILENAME BUFNAME MODE)"
 FILENAME is the visited file name, BUFNAME is the buffer name, and
 MODE is the major mode.
 \n\(fn FILENAME BUFNAME MODE)"
-  (let ((case-fold-search nil))
-    (and (not (string-match desktop-buffers-not-to-save bufname))
+  (let ((case-fold-search nil)
+        dired-skip)
+    (and (not (and (stringp desktop-buffers-not-to-save)
+                  (not filename)
+                  (string-match desktop-buffers-not-to-save bufname)))
          (not (memq mode desktop-modes-not-to-save))
          (not (memq mode desktop-modes-not-to-save))
+         ;; FIXME this is broken if desktop-files-not-to-save is nil.
          (or (and filename
          (or (and filename
+                 (stringp desktop-files-not-to-save)
                   (not (string-match desktop-files-not-to-save filename)))
              (and (eq mode 'dired-mode)
                   (with-current-buffer bufname
                   (not (string-match desktop-files-not-to-save filename)))
              (and (eq mode 'dired-mode)
                   (with-current-buffer bufname
-                    (not (string-match desktop-files-not-to-save
-                                       default-directory))))
+                    (not (setq dired-skip
+                               (string-match desktop-files-not-to-save
+                                             default-directory)))))
              (and (null filename)
              (and (null filename)
+                  (null dired-skip)     ; bug#5755
                  (with-current-buffer bufname desktop-save-buffer))))))
 
 ;; ----------------------------------------------------------------------------
                  (with-current-buffer bufname desktop-save-buffer))))))
 
 ;; ----------------------------------------------------------------------------
@@ -837,6 +849,7 @@ DIRNAME must be the directory in which the desktop file will be saved."
     ((eq desktop-file-name-format 'local) (file-relative-name filename dirname))
     (t (expand-file-name filename))))
 
     ((eq desktop-file-name-format 'local) (file-relative-name filename dirname))
     (t (expand-file-name filename))))
 
+
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
 (defun desktop-save (dirname &optional release)
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
 (defun desktop-save (dirname &optional release)
@@ -895,8 +908,9 @@ See also `desktop-base-file-name'."
                          "desktop-append-buffer-args")
                        " "
                        desktop-file-version)
                          "desktop-append-buffer-args")
                        " "
                        desktop-file-version)
-               ;; If the base name is non-nil, we save it instead of the buffer name
-               (when base (setcar (nthcdr 1 l) base))
+               ;; If there's a non-empty base name, we save it instead of the buffer name
+               (when (and base (not (string= base "")))
+                 (setcar (nthcdr 1 l) base))
                (dolist (e l)
                  (insert "\n  " (desktop-value-to-string e)))
                (insert ")\n\n"))))
                (dolist (e l)
                  (insert "\n  " (desktop-value-to-string e)))
                (insert ")\n\n"))))
@@ -966,11 +980,11 @@ It returns t if a desktop file was loaded, nil otherwise."
                   (or (null desktop-load-locked-desktop)
                       (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)))))
                   (or (null desktop-load-locked-desktop)
                       (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)))))
-             (progn
-               (let ((default-directory desktop-dirname))
-                 (run-hooks 'desktop-not-loaded-hook))
+             (let ((default-directory desktop-dirname))
                (setq desktop-dirname nil)
                (setq desktop-dirname nil)
-               (message "Desktop file in use; not loaded."))
+               (run-hooks 'desktop-not-loaded-hook)
+               (unless desktop-dirname
+                 (message "Desktop file in use; not loaded.")))
            (desktop-lazy-abort)
            ;; Evaluate desktop buffer and remember when it was modified.
            (load (desktop-full-file-name) t t t)
            (desktop-lazy-abort)
            ;; Evaluate desktop buffer and remember when it was modified.
            (load (desktop-full-file-name) t t t)
@@ -1044,7 +1058,7 @@ directory DIRNAME."
   (if desktop-dirname
       (desktop-save desktop-dirname)
     (call-interactively 'desktop-save))
   (if desktop-dirname
       (desktop-save desktop-dirname)
     (call-interactively 'desktop-save))
-  (message "Desktop saved in %s" desktop-dirname))
+  (message "Desktop saved in %s" (abbreviate-file-name desktop-dirname)))
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
@@ -1127,7 +1141,7 @@ directory DIRNAME."
     (desktop-load-file desktop-buffer-major-mode)
     (let ((buffer-list (buffer-list))
           (result
     (desktop-load-file desktop-buffer-major-mode)
     (let ((buffer-list (buffer-list))
           (result
-           (condition-case err
+           (condition-case-no-debug err
                (funcall (or (cdr (assq desktop-buffer-major-mode
                                        desktop-buffer-mode-handlers))
                             'desktop-restore-file-buffer)
                (funcall (or (cdr (assq desktop-buffer-major-mode
                                        desktop-buffer-mode-handlers))
                             'desktop-restore-file-buffer)
@@ -1273,7 +1287,7 @@ If there are no buffers left to create, kill the timer."
     (setq desktop-lazy-timer nil))
   (when desktop-buffer-args-list
     (setq desktop-buffer-args-list nil)
     (setq desktop-lazy-timer nil))
   (when desktop-buffer-args-list
     (setq desktop-buffer-args-list nil)
-    (when (interactive-p)
+    (when (called-interactively-p 'interactive)
       (message "Lazy desktop load aborted"))))
 
 ;; ----------------------------------------------------------------------------
       (message "Lazy desktop load aborted"))))
 
 ;; ----------------------------------------------------------------------------