diff options
| author | Lars Hansen | 2003-09-30 07:22:22 +0000 |
|---|---|---|
| committer | Lars Hansen | 2003-09-30 07:22:22 +0000 |
| commit | c5b31c4d7923a82a2937877f891a5e67f7ea6511 (patch) | |
| tree | 47b91806ffc9d20bc36270f520bc42777a7fdcef | |
| parent | 00694c2006860711b36e0f6cf559dd17c8bfbc25 (diff) | |
| download | emacs-c5b31c4d7923a82a2937877f891a5e67f7ea6511.tar.gz emacs-c5b31c4d7923a82a2937877f891a5e67f7ea6511.zip | |
A lot of comments updated.
(desktop-save-mode): Minor mode introduced.
(desktop-enable, desktop-clear-preserve-buffers): Variables made obsolete.
(desktop-load-default): Function made obsolete.
(desktop-locals-to-save): Variable made customizable.
(desktop-read): Optional parameter `dirname' added.
(desktop-change-dir, desktop-revert): Parameter `dirname' in `desktop-read' used.
(desktop-save-in-load-dir): Renamed to `desktop-save-in-desktop-dir'.
| -rw-r--r-- | lisp/desktop.el | 284 |
1 files changed, 149 insertions, 135 deletions
diff --git a/lisp/desktop.el b/lisp/desktop.el index 3cf839d1549..73fef5c44b7 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el | |||
| @@ -37,38 +37,19 @@ | |||
| 37 | ;; - buffer-read-only | 37 | ;; - buffer-read-only |
| 38 | ;; - some local variables | 38 | ;; - some local variables |
| 39 | 39 | ||
| 40 | ;; To use this, add these lines to the bottom of your .emacs file: | 40 | ;; To use this, use customize to turn on desktop-save-mode or add the |
| 41 | ;; following line somewhere in your .emacs file: | ||
| 41 | ;; | 42 | ;; |
| 42 | ;; (require 'desktop) | 43 | ;; (desktop-save-mode 1) |
| 43 | ;; (setq desktop-enable t) | ||
| 44 | ;; | 44 | ;; |
| 45 | ;; Between the first two lines you may wish to add something that updates the | 45 | ;; For further usage information, look at the section |
| 46 | ;; variables `desktop-globals-to-save' and/or `desktop-locals-to-save'. If | 46 | ;; "Saving Emacs Sessions" in the GNU Emacs Manual. |
| 47 | ;; for instance you want to save the local variable `foobar' for every buffer | 47 | |
| 48 | ;; in which it is local, you could add the line | 48 | ;; When the desktop module is loaded, the function `desktop-kill' is |
| 49 | ;; | 49 | ;; added to the `kill-emacs-hook'. This function is responsible for |
| 50 | ;; (add-to-list 'desktop-locals-to-save 'foobar) | 50 | ;; saving the desktop when Emacs is killed. Furthermore an anonymous |
| 51 | ;; | 51 | ;; function is added to the `after-init-hook'. This function is |
| 52 | ;; To avoid saving excessive amounts of data you may also wish to add | 52 | ;; responsible for loading the desktop when Emacs is started. |
| 53 | ;; something like the following | ||
| 54 | ;; | ||
| 55 | ;; (add-hook 'kill-emacs-hook | ||
| 56 | ;; '(lambda () | ||
| 57 | ;; (desktop-truncate search-ring 3) | ||
| 58 | ;; (desktop-truncate regexp-search-ring 3))) | ||
| 59 | ;; | ||
| 60 | ;; which will make sure that no more than three search items are saved. You | ||
| 61 | ;; must place this line *after* the `(desktop-load-default)' line. See also | ||
| 62 | ;; the variable `desktop-save-hook'. | ||
| 63 | |||
| 64 | ;; Start Emacs in the root directory of your "project". The desktop saver | ||
| 65 | ;; is inactive by default. You activate it by M-x desktop-save RET. When | ||
| 66 | ;; you exit the next time the above data will be saved. This ensures that | ||
| 67 | ;; all the files you were editing will be reloaded the next time you start | ||
| 68 | ;; Emacs from the same directory and that points will be set where you | ||
| 69 | ;; left them. If you save a desktop file in your home directory it will | ||
| 70 | ;; act as a default desktop when you start Emacs from a directory that | ||
| 71 | ;; doesn't have its own. I never do this, but you may want to. | ||
| 72 | 53 | ||
| 73 | ;; Some words on minor modes: Most minor modes are controlled by | 54 | ;; Some words on minor modes: Most minor modes are controlled by |
| 74 | ;; buffer-local variables, which have a standard save / restore | 55 | ;; buffer-local variables, which have a standard save / restore |
| @@ -121,24 +102,32 @@ backward compatibility.") | |||
| 121 | "Save status of Emacs when you exit." | 102 | "Save status of Emacs when you exit." |
| 122 | :group 'frames) | 103 | :group 'frames) |
| 123 | 104 | ||
| 124 | (defcustom desktop-enable nil | 105 | ;;;###autoload |
| 125 | "*Non-nil enable Desktop to save the state of Emacs when you exit." | 106 | (define-minor-mode desktop-save-mode |
| 126 | :group 'desktop | 107 | "Toggle desktop saving mode. |
| 127 | :type 'boolean | 108 | With numeric ARG, turn desktop saving on if ARG is positive, off |
| 128 | :require 'desktop | 109 | otherwise. See variable `desktop-save' for a description of when the |
| 129 | :initialize 'custom-initialize-default | 110 | desktop is saved." |
| 130 | :version "20.3") | 111 | :global t |
| 112 | :group 'desktop) | ||
| 113 | |||
| 114 | ;; Maintained for backward compatibility | ||
| 115 | (defvaralias 'desktop-enable 'desktop-save-mode) | ||
| 116 | (make-obsolete-variable 'desktop-enable 'desktop-save-mode) | ||
| 131 | 117 | ||
| 132 | (defcustom desktop-save 'ask-if-new | 118 | (defcustom desktop-save 'ask-if-new |
| 133 | "*When the user changes desktop or quits emacs, should the desktop be saved? | 119 | "*Specifies whether the desktop should be saved when it is killed. |
| 134 | \(in the current desktop directory) | 120 | A desktop is killed when the user changes desktop or quits Emacs. |
| 121 | Possible values are: | ||
| 135 | t -- always save. | 122 | t -- always save. |
| 136 | ask -- always ask. | 123 | ask -- always ask. |
| 137 | ask-if-new -- ask if no desktop file exists, otherwise just save. | 124 | ask-if-new -- ask if no desktop file exists, otherwise just save. |
| 138 | ask-if-exists -- ask if desktop file exists, otherwise don't save. | 125 | ask-if-exists -- ask if desktop file exists, otherwise don't save. |
| 139 | if-exists -- save if desktop file exists, otherwise don't save. | 126 | if-exists -- save if desktop file exists, otherwise don't save. |
| 140 | nil -- never save. | 127 | nil -- never save. |
| 141 | The desktop is never saved when `desktop-enable' is nil." | 128 | The desktop is never saved when `desktop-save-mode' is nil. |
| 129 | The variables `desktop-directory' and `desktop-base-file-name' | ||
| 130 | determine where the desktop is saved." | ||
| 142 | :type '(choice | 131 | :type '(choice |
| 143 | (const :tag "Always save" t) | 132 | (const :tag "Always save" t) |
| 144 | (const :tag "Always ask" ask) | 133 | (const :tag "Always ask" ask) |
| @@ -150,7 +139,7 @@ The desktop is never saved when `desktop-enable' is nil." | |||
| 150 | 139 | ||
| 151 | (defcustom desktop-base-file-name | 140 | (defcustom desktop-base-file-name |
| 152 | (convert-standard-filename ".emacs.desktop") | 141 | (convert-standard-filename ".emacs.desktop") |
| 153 | "File for Emacs desktop, not including the directory name." | 142 | "Name of file for Emacs desktop, excluding the directory part." |
| 154 | :type 'file | 143 | :type 'file |
| 155 | :group 'desktop) | 144 | :group 'desktop) |
| 156 | (defvaralias 'desktop-basefilename 'desktop-base-file-name) | 145 | (defvaralias 'desktop-basefilename 'desktop-base-file-name) |
| @@ -162,13 +151,13 @@ The base name of the file is specified in `desktop-base-file-name'." | |||
| 162 | :group 'desktop) | 151 | :group 'desktop) |
| 163 | 152 | ||
| 164 | (defcustom desktop-missing-file-warning nil | 153 | (defcustom desktop-missing-file-warning nil |
| 165 | "*If non-nil then desktop warns when a file no longer exists. | 154 | "*If non-nil then `desktop-read' warns when a file no longer exists. |
| 166 | Otherwise it simply ignores that file." | 155 | Otherwise it simply ignores that file." |
| 167 | :type 'boolean | 156 | :type 'boolean |
| 168 | :group 'desktop) | 157 | :group 'desktop) |
| 169 | 158 | ||
| 170 | (defcustom desktop-no-desktop-file-hook nil | 159 | (defcustom desktop-no-desktop-file-hook nil |
| 171 | "Normal hook run after fail of `desktop-read' due to missing desktop file. | 160 | "Normal hook run when `desktop-read' can't find a desktop file. |
| 172 | May e.g. be used to show a dired buffer." | 161 | May e.g. be used to show a dired buffer." |
| 173 | :type 'hook | 162 | :type 'hook |
| 174 | :group 'desktop) | 163 | :group 'desktop) |
| @@ -180,7 +169,7 @@ May e.g. be used to show a buffer list." | |||
| 180 | :group 'desktop) | 169 | :group 'desktop) |
| 181 | 170 | ||
| 182 | (defcustom desktop-save-hook nil | 171 | (defcustom desktop-save-hook nil |
| 183 | "Hook run before desktop saves the state of Emacs. | 172 | "Normal hook run before the desktop is saved in a desktop file. |
| 184 | This is useful for truncating history lists, for example." | 173 | This is useful for truncating history lists, for example." |
| 185 | :type 'hook | 174 | :type 'hook |
| 186 | :group 'desktop) | 175 | :group 'desktop) |
| @@ -192,11 +181,10 @@ This is useful for truncating history lists, for example." | |||
| 192 | search-ring | 181 | search-ring |
| 193 | regexp-search-ring | 182 | regexp-search-ring |
| 194 | register-alist) | 183 | register-alist) |
| 195 | "List of global variables to save when killing Emacs. | 184 | "List of global variables saved by `desktop-save'. |
| 196 | An element may be variable name (a symbol) | 185 | An element may be variable name (a symbol) or a cons cell of the form |
| 197 | or a cons cell of the form (VAR . MAX-SIZE), | 186 | \(VAR . MAX-SIZE), which means to truncate VAR's value to at most |
| 198 | which means to truncate VAR's value to at most MAX-SIZE elements | 187 | MAX-SIZE elements (if the value is a list) before saving the value. |
| 199 | \(if the value is a list) before saving the value. | ||
| 200 | Feature: Saving `kill-ring' implies saving `kill-ring-yank-pointer'." | 188 | Feature: Saving `kill-ring' implies saving `kill-ring-yank-pointer'." |
| 201 | :type '(repeat (restricted-sexp :match-alternatives (symbolp consp))) | 189 | :type '(repeat (restricted-sexp :match-alternatives (symbolp consp))) |
| 202 | :group 'desktop) | 190 | :group 'desktop) |
| @@ -208,7 +196,7 @@ Feature: Saving `kill-ring' implies saving `kill-ring-yank-pointer'." | |||
| 208 | search-ring-yank-pointer | 196 | search-ring-yank-pointer |
| 209 | regexp-search-ring | 197 | regexp-search-ring |
| 210 | regexp-search-ring-yank-pointer) | 198 | regexp-search-ring-yank-pointer) |
| 211 | "List of global variables set to clear by `desktop-clear'. | 199 | "List of global variables to clear by `desktop-clear'. |
| 212 | An element may be variable name (a symbol) or a cons cell of the form | 200 | An element may be variable name (a symbol) or a cons cell of the form |
| 213 | \(VAR . FORM). Symbols are set to nil and for cons cells VAR is set | 201 | \(VAR . FORM). Symbols are set to nil and for cons cells VAR is set |
| 214 | to the value obtained by evaluateing FORM." | 202 | to the value obtained by evaluateing FORM." |
| @@ -216,19 +204,22 @@ to the value obtained by evaluateing FORM." | |||
| 216 | :group 'desktop) | 204 | :group 'desktop) |
| 217 | 205 | ||
| 218 | (defcustom desktop-clear-preserve-buffers-regexp | 206 | (defcustom desktop-clear-preserve-buffers-regexp |
| 219 | "^\\*tramp/.+\\*$" | 207 | "^\\(\\*scratch\\*\\|\\*Messages\\*\\|\\*tramp/.+\\*\\)$" |
| 220 | "Regexp identifying buffers that `desktop-clear' should not delete." | 208 | "Regexp identifying buffers that `desktop-clear' should not delete." |
| 221 | :type 'regexp | 209 | :type 'regexp |
| 222 | :group 'desktop) | 210 | :group 'desktop) |
| 223 | 211 | ||
| 224 | ;; Maintained for backward compatibility | 212 | ;; Maintained for backward compatibility |
| 225 | (defcustom desktop-clear-preserve-buffers | 213 | (defcustom desktop-clear-preserve-buffers nil |
| 226 | '("*scratch*" "*Messages*") | 214 | "*List of buffer names that `desktop-clear' should not delete. |
| 227 | "*List of buffer names that `desktop-clear' should not delete." | 215 | This variable is maintained for backward compatibility only. Use |
| 216 | `desktop-clear-preserve-buffers-regexp' instead." | ||
| 228 | :type '(repeat string) | 217 | :type '(repeat string) |
| 229 | :group 'desktop) | 218 | :group 'desktop) |
| 219 | (make-obsolete-variable 'desktop-clear-preserve-buffers | ||
| 220 | 'desktop-clear-preserve-buffers-regexp) | ||
| 230 | 221 | ||
| 231 | (defvar desktop-locals-to-save '( | 222 | (defcustom desktop-locals-to-save '( |
| 232 | desktop-locals-to-save ; Itself! Think it over. | 223 | desktop-locals-to-save ; Itself! Think it over. |
| 233 | truncate-lines | 224 | truncate-lines |
| 234 | case-fold-search | 225 | case-fold-search |
| @@ -238,7 +229,9 @@ to the value obtained by evaluateing FORM." | |||
| 238 | change-log-default-name | 229 | change-log-default-name |
| 239 | line-number-mode) | 230 | line-number-mode) |
| 240 | "List of local variables to save for each buffer. | 231 | "List of local variables to save for each buffer. |
| 241 | The variables are saved only when they really are local.") | 232 | The variables are saved only when they really are local." |
| 233 | :type '(repeat symbol) | ||
| 234 | :group 'desktop) | ||
| 242 | (make-variable-buffer-local 'desktop-locals-to-save) | 235 | (make-variable-buffer-local 'desktop-locals-to-save) |
| 243 | 236 | ||
| 244 | ;; We skip .log files because they are normally temporary. | 237 | ;; We skip .log files because they are normally temporary. |
| @@ -250,7 +243,7 @@ The variables are saved only when they really are local.") | |||
| 250 | :type 'regexp | 243 | :type 'regexp |
| 251 | :group 'desktop) | 244 | :group 'desktop) |
| 252 | 245 | ||
| 253 | ;; Skip ange-ftp files | 246 | ;; Skip tramp and ange-ftp files |
| 254 | (defcustom desktop-files-not-to-save | 247 | (defcustom desktop-files-not-to-save |
| 255 | "^/[^/:]*:" | 248 | "^/[^/:]*:" |
| 256 | "Regexp identifying files whose buffers are to be excluded from saving." | 249 | "Regexp identifying files whose buffers are to be excluded from saving." |
| @@ -259,7 +252,7 @@ The variables are saved only when they really are local.") | |||
| 259 | 252 | ||
| 260 | (defcustom desktop-buffer-modes-to-save | 253 | (defcustom desktop-buffer-modes-to-save |
| 261 | '(Info-mode rmail-mode) | 254 | '(Info-mode rmail-mode) |
| 262 | "If a buffer is of one of these major modes, save the buffer name. | 255 | "If a buffer is of one of these major modes, save the buffer state. |
| 263 | It is up to the functions in `desktop-buffer-handlers' to decide | 256 | It is up to the functions in `desktop-buffer-handlers' to decide |
| 264 | whether the buffer should be recreated or not, and how." | 257 | whether the buffer should be recreated or not, and how." |
| 265 | :type '(repeat symbol) | 258 | :type '(repeat symbol) |
| @@ -283,17 +276,18 @@ Possible values are: | |||
| 283 | '(desktop-buffer-info-misc-data | 276 | '(desktop-buffer-info-misc-data |
| 284 | desktop-buffer-dired-misc-data) | 277 | desktop-buffer-dired-misc-data) |
| 285 | "*Functions used to determine auxiliary information for a buffer. | 278 | "*Functions used to determine auxiliary information for a buffer. |
| 286 | These functions are called in order, with no arguments. If a function | 279 | These functions are called by `desktop-save' in order, with no |
| 287 | returns non-nil, its value is saved along with the desktop buffer for | 280 | arguments. If a function returns non-nil, its value is saved along |
| 288 | which it was called; no further functions will be called. | 281 | with the state of the buffer for which it was called; no further |
| 282 | functions will be called. | ||
| 289 | 283 | ||
| 290 | File names should formatted using the call | 284 | When file names are returned, they should be formatted using the call |
| 291 | \"(desktop-file-name FILE-NAME dirname)\". | 285 | \"(desktop-file-name FILE-NAME dirname)\". |
| 292 | 286 | ||
| 293 | Later, when desktop.el restores the buffers it has saved, each of the | 287 | Later, when `desktop-read' restores buffers, each of the functions in |
| 294 | `desktop-buffer-handlers' functions will have access to a buffer local | 288 | `desktop-buffer-handlers' will have access to a buffer local variable, |
| 295 | variable, named `desktop-buffer-misc', whose value is what the | 289 | named `desktop-buffer-misc', whose value is what the function in |
| 296 | \"misc\" function returned previously." | 290 | `desktop-buffer-misc-functions' returned." |
| 297 | :type '(repeat function) | 291 | :type '(repeat function) |
| 298 | :group 'desktop) | 292 | :group 'desktop) |
| 299 | 293 | ||
| @@ -303,7 +297,7 @@ variable, named `desktop-buffer-misc', whose value is what the | |||
| 303 | desktop-buffer-mh | 297 | desktop-buffer-mh |
| 304 | desktop-buffer-info | 298 | desktop-buffer-info |
| 305 | desktop-buffer-file) | 299 | desktop-buffer-file) |
| 306 | "*List of functions to call in order to create a buffer. | 300 | "*Functions called by `desktop-read' in order to create a buffer. |
| 307 | The functions are called without explicit parameters but can use the | 301 | The functions are called without explicit parameters but can use the |
| 308 | following variables: | 302 | following variables: |
| 309 | 303 | ||
| @@ -342,7 +336,7 @@ this table." | |||
| 342 | 336 | ||
| 343 | ;; ---------------------------------------------------------------------------- | 337 | ;; ---------------------------------------------------------------------------- |
| 344 | (defvar desktop-dirname nil | 338 | (defvar desktop-dirname nil |
| 345 | "The directory in which the current desktop file resides.") | 339 | "The directory in which the desktop file should be saved.") |
| 346 | 340 | ||
| 347 | (defconst desktop-header | 341 | (defconst desktop-header |
| 348 | ";; -------------------------------------------------------------------------- | 342 | ";; -------------------------------------------------------------------------- |
| @@ -363,8 +357,9 @@ this table." | |||
| 363 | ;; ---------------------------------------------------------------------------- | 357 | ;; ---------------------------------------------------------------------------- |
| 364 | (defun desktop-clear () | 358 | (defun desktop-clear () |
| 365 | "Empty the Desktop. | 359 | "Empty the Desktop. |
| 366 | This kills all buffers except for internal ones and those listed | 360 | This kills all buffers except for internal ones and those matching |
| 367 | in `desktop-clear-preserve-buffers'. Furthermore, it clears the | 361 | `desktop-clear-preserve-buffers-regexp' or listed in |
| 362 | `desktop-clear-preserve-buffers'. Furthermore, it clears the | ||
| 368 | variables listed in `desktop-globals-to-clear'." | 363 | variables listed in `desktop-globals-to-clear'." |
| 369 | (interactive) | 364 | (interactive) |
| 370 | (dolist (var desktop-globals-to-clear) | 365 | (dolist (var desktop-globals-to-clear) |
| @@ -388,12 +383,12 @@ variables listed in `desktop-globals-to-clear'." | |||
| 388 | (add-hook 'kill-emacs-hook 'desktop-kill) | 383 | (add-hook 'kill-emacs-hook 'desktop-kill) |
| 389 | 384 | ||
| 390 | (defun desktop-kill () | 385 | (defun desktop-kill () |
| 391 | "If `desktop-enable' is non-nil, do what `desktop-save' says to do. | 386 | "If `desktop-save-mode' is non-nil, do what `desktop-save' says to do. |
| 392 | If the desktop should be saved and `desktop-dirname' | 387 | If the desktop should be saved and `desktop-dirname' |
| 393 | is nil, ask the user where to save the desktop." | 388 | is nil, ask the user where to save the desktop." |
| 394 | (when | 389 | (when |
| 395 | (and | 390 | (and |
| 396 | desktop-enable | 391 | desktop-save-mode |
| 397 | (let ((exists (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)))) | 392 | (let ((exists (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)))) |
| 398 | (or | 393 | (or |
| 399 | (eq desktop-save t) | 394 | (eq desktop-save t) |
| @@ -579,7 +574,9 @@ DIRNAME must be the directory in which the desktop file will be saved." | |||
| 579 | 574 | ||
| 580 | ;; ---------------------------------------------------------------------------- | 575 | ;; ---------------------------------------------------------------------------- |
| 581 | (defun desktop-save (dirname) | 576 | (defun desktop-save (dirname) |
| 582 | "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." | 577 | "Save the desktop in a desktop file. |
| 578 | Parameter DIRNAME specifies where to save the desktop file. | ||
| 579 | See also `desktop-base-file-name'." | ||
| 583 | (interactive "DDirectory to save desktop file in: ") | 580 | (interactive "DDirectory to save desktop file in: ") |
| 584 | (run-hooks 'desktop-save-hook) | 581 | (run-hooks 'desktop-save-hook) |
| 585 | (setq dirname (file-name-as-directory (expand-file-name dirname))) | 582 | (setq dirname (file-name-as-directory (expand-file-name dirname))) |
| @@ -664,82 +661,98 @@ DIRNAME must be the directory in which the desktop file will be saved." | |||
| 664 | 661 | ||
| 665 | ;; ---------------------------------------------------------------------------- | 662 | ;; ---------------------------------------------------------------------------- |
| 666 | (defun desktop-remove () | 663 | (defun desktop-remove () |
| 667 | "Delete the Desktop file and inactivate the desktop system." | 664 | "Delete desktop file in `desktop-dirname'. |
| 665 | This function also sets `desktop-dirname' to nil." | ||
| 668 | (interactive) | 666 | (interactive) |
| 669 | (if desktop-dirname | 667 | (when desktop-dirname |
| 670 | (let ((filename (expand-file-name desktop-base-file-name desktop-dirname))) | 668 | (let ((filename (expand-file-name desktop-base-file-name desktop-dirname))) |
| 671 | (setq desktop-dirname nil) | 669 | (setq desktop-dirname nil) |
| 672 | (if (file-exists-p filename) | 670 | (when (file-exists-p filename) |
| 673 | (delete-file filename))))) | 671 | (delete-file filename))))) |
| 672 | |||
| 674 | ;; ---------------------------------------------------------------------------- | 673 | ;; ---------------------------------------------------------------------------- |
| 675 | ;;;###autoload | 674 | ;;;###autoload |
| 676 | (defun desktop-read () | 675 | (defun desktop-read (&optional dirname) |
| 677 | "Read the Desktop file and the files it specifies. | 676 | "Read and process the desktop file in directory DIRNAME. |
| 678 | This is a no-op when Emacs is running in batch mode. | 677 | Look for a desktop file in DIRNAME, or if DIRNAME is omitted, look in |
| 679 | Look for the desktop file according to the variables `desktop-base-file-name' | 678 | directories listed in `desktop-path'. If a desktop file is found, it |
| 680 | and `desktop-path'. If no desktop file is found, clear the desktop. | 679 | is processed and `desktop-after-read-hook' is run. If no desktop file |
| 681 | Returns t if it has read a desktop file, nil otherwise." | 680 | is found, clear the desktop and run `desktop-no-desktop-file-hook'. |
| 681 | This function is a no-op when Emacs is running in batch mode. | ||
| 682 | It returns t if a desktop file was loaded, nil otherwise." | ||
| 682 | (interactive) | 683 | (interactive) |
| 683 | (unless noninteractive | 684 | (unless noninteractive |
| 684 | (let ((dirs desktop-path)) | 685 | (setq desktop-dirname |
| 685 | (while | 686 | (file-name-as-directory |
| 686 | (and | 687 | (expand-file-name |
| 687 | dirs | 688 | (or |
| 688 | (not | 689 | ;; If DIRNAME is specified, use it. |
| 689 | (file-exists-p (expand-file-name desktop-base-file-name (car dirs))))) | 690 | (and (< 0 (length dirname)) dirname) |
| 690 | (setq dirs (cdr dirs))) | 691 | ;; Otherwise search desktop file in desktop-path. |
| 691 | (setq desktop-dirname (and dirs (file-name-as-directory (expand-file-name (car dirs))))) | 692 | (let ((dirs desktop-path)) |
| 692 | (if desktop-dirname | 693 | (while |
| 693 | (let ((desktop-first-buffer nil)) | 694 | (and |
| 694 | ;; Evaluate desktop buffer. | 695 | dirs |
| 695 | (load (expand-file-name desktop-base-file-name desktop-dirname) t t t) | 696 | (not |
| 696 | ;; `desktop-create-buffer' puts buffers at end of the buffer list. | 697 | (file-exists-p (expand-file-name desktop-base-file-name (car dirs))))) |
| 697 | ;; We want buffers existing prior to evaluating the desktop (and not reused) | 698 | (setq dirs (cdr dirs))) |
| 698 | ;; to be placed at the end of the buffer list, so we move them here. | 699 | (and dirs (car dirs))) |
| 699 | (mapcar 'bury-buffer | 700 | ;; If not found and `desktop-path' is non-nil, use its first element. |
| 700 | (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list)))))) | 701 | (and desktop-path (car desktop-path)) |
| 701 | (switch-to-buffer (car (buffer-list))) | 702 | ;; Default: Home directory. |
| 702 | (run-hooks 'desktop-delay-hook) | 703 | "~")))) |
| 703 | (setq desktop-delay-hook nil) | 704 | (if (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)) |
| 704 | (run-hooks 'desktop-after-read-hook) | 705 | ;; Desktop file found, process it. |
| 705 | (message "Desktop loaded.") | 706 | (let ((desktop-first-buffer nil)) |
| 706 | t) | 707 | ;; Evaluate desktop buffer. |
| 707 | (desktop-clear) | 708 | (load (expand-file-name desktop-base-file-name desktop-dirname) t t t) |
| 708 | (run-hooks 'desktop-no-desktop-file-hook) | 709 | ;; `desktop-create-buffer' puts buffers at end of the buffer list. |
| 709 | (message "No desktop file.") | 710 | ;; We want buffers existing prior to evaluating the desktop (and not reused) |
| 710 | nil)))) | 711 | ;; to be placed at the end of the buffer list, so we move them here. |
| 712 | (mapcar 'bury-buffer | ||
| 713 | (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list)))))) | ||
| 714 | (switch-to-buffer (car (buffer-list))) | ||
| 715 | (run-hooks 'desktop-delay-hook) | ||
| 716 | (setq desktop-delay-hook nil) | ||
| 717 | (run-hooks 'desktop-after-read-hook) | ||
| 718 | (message "Desktop loaded.") | ||
| 719 | t) | ||
| 720 | ;; No desktop file found. | ||
| 721 | (desktop-clear) | ||
| 722 | (let ((default-directory desktop-dirname)) | ||
| 723 | (run-hooks 'desktop-no-desktop-file-hook)) | ||
| 724 | (message "No desktop file.") | ||
| 725 | nil))) | ||
| 711 | 726 | ||
| 712 | ;; ---------------------------------------------------------------------------- | 727 | ;; ---------------------------------------------------------------------------- |
| 728 | ;; Maintained for backward compatibility | ||
| 713 | ;;;###autoload | 729 | ;;;###autoload |
| 714 | (defun desktop-load-default () | 730 | (defun desktop-load-default () |
| 715 | "Load the `default' start-up library manually. | 731 | "Load the `default' start-up library manually. |
| 716 | Also inhibit further loading of it. Call this from your `.emacs' file | 732 | Also inhibit further loading of it." |
| 717 | to provide correct modes for autoloaded files." | ||
| 718 | (if (not inhibit-default-init) ; safety check | 733 | (if (not inhibit-default-init) ; safety check |
| 719 | (progn | 734 | (progn |
| 720 | (load "default" t t) | 735 | (load "default" t t) |
| 721 | (setq inhibit-default-init t)))) | 736 | (setq inhibit-default-init t)))) |
| 737 | (make-obsolete 'desktop-load-default 'desktop-save-mode) | ||
| 722 | 738 | ||
| 723 | ;; ---------------------------------------------------------------------------- | 739 | ;; ---------------------------------------------------------------------------- |
| 724 | ;;;###autoload | 740 | ;;;###autoload |
| 725 | (defun desktop-change-dir (dir) | 741 | (defun desktop-change-dir (dirname) |
| 726 | "Save and clear the desktop, then load the desktop from directory DIR. | 742 | "Change to desktop saved in DIRNAME. |
| 727 | However, if `desktop-enable' was nil at call, don't save the old desktop. | 743 | Kill the desktop as specified by variables `desktop-save-mode' and |
| 728 | This function always sets `desktop-enable' to t." | 744 | `desktop-save', then clear the desktop and load the desktop file in |
| 729 | (interactive "DNew directory: ") | 745 | directory DIRNAME." |
| 730 | (setq dir (file-name-as-directory (expand-file-name dir desktop-dirname))) | 746 | (interactive "DChange to directory: ") |
| 747 | (setq dirname (file-name-as-directory (expand-file-name dirname desktop-dirname))) | ||
| 731 | (desktop-kill) | 748 | (desktop-kill) |
| 732 | (desktop-clear) | 749 | (desktop-clear) |
| 733 | (setq desktop-enable t) | 750 | (desktop-read dirname)) |
| 734 | (let ((desktop-path (list dir)) | 751 | |
| 735 | (default-directory dir)) | 752 | ;; ---------------------------------------------------------------------------- |
| 736 | (desktop-read)) | ||
| 737 | ;; Set `desktop-dirname' even in no desktop file was found | ||
| 738 | (setq desktop-dirname dir)) | ||
| 739 | ;; ---------------------------------------------------------------------------- | ||
| 740 | ;;;###autoload | 753 | ;;;###autoload |
| 741 | (defun desktop-save-in-load-dir () | 754 | (defun desktop-save-in-desktop-dir () |
| 742 | "Save desktop in directory from which it was loaded." | 755 | "Save the desktop in directory `desktop-dirname'." |
| 743 | (interactive) | 756 | (interactive) |
| 744 | (if desktop-dirname | 757 | (if desktop-dirname |
| 745 | (desktop-save desktop-dirname) | 758 | (desktop-save desktop-dirname) |
| @@ -751,9 +764,12 @@ This function always sets `desktop-enable' to t." | |||
| 751 | (defun desktop-revert () | 764 | (defun desktop-revert () |
| 752 | "Revert to the last loaded desktop." | 765 | "Revert to the last loaded desktop." |
| 753 | (interactive) | 766 | (interactive) |
| 754 | (unless desktop-dirname (error "No desktop has been loaded")) | 767 | (unless desktop-dirname |
| 755 | (setq desktop-enable nil) | 768 | (error "Unknown desktop directory")) |
| 756 | (desktop-change-dir desktop-dirname)) | 769 | (unless (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)) |
| 770 | (error "No desktop file found")) | ||
| 771 | (desktop-clear) | ||
| 772 | (desktop-read desktop-dirname)) | ||
| 757 | 773 | ||
| 758 | ;; ---------------------------------------------------------------------------- | 774 | ;; ---------------------------------------------------------------------------- |
| 759 | ;; Note: the following functions use the dynamic variable binding in Lisp. | 775 | ;; Note: the following functions use the dynamic variable binding in Lisp. |
| @@ -962,7 +978,7 @@ This function always sets `desktop-enable' to t." | |||
| 962 | (cons 'overwrite-mode (car mim))))) | 978 | (cons 'overwrite-mode (car mim))))) |
| 963 | 979 | ||
| 964 | ;; ---------------------------------------------------------------------------- | 980 | ;; ---------------------------------------------------------------------------- |
| 965 | ;; When `desktop-enable' is non-nil and "--no-desktop" is not specified on the | 981 | ;; When `desktop-save-mode' is non-nil and "--no-desktop" is not specified on the |
| 966 | ;; command line, we do the rest of what it takes to use desktop, but do it | 982 | ;; command line, we do the rest of what it takes to use desktop, but do it |
| 967 | ;; after finishing loading the init file. | 983 | ;; after finishing loading the init file. |
| 968 | ;; We cannot use `command-switch-alist' to process "--no-desktop" because these | 984 | ;; We cannot use `command-switch-alist' to process "--no-desktop" because these |
| @@ -973,9 +989,7 @@ This function always sets `desktop-enable' to t." | |||
| 973 | (let ((key "--no-desktop")) | 989 | (let ((key "--no-desktop")) |
| 974 | (if (member key command-line-args) | 990 | (if (member key command-line-args) |
| 975 | (delete key command-line-args) | 991 | (delete key command-line-args) |
| 976 | (when desktop-enable | 992 | (when desktop-save-mode (desktop-read)))))) |
| 977 | (desktop-load-default) | ||
| 978 | (desktop-read)))))) | ||
| 979 | 993 | ||
| 980 | (provide 'desktop) | 994 | (provide 'desktop) |
| 981 | 995 | ||