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