3404
|
1 ;;; desktop.el --- save partial status of Emacs when killed
|
|
2
|
64762
|
3 ;; Copyright (C) 1993, 1994, 1995, 1997, 2000, 2001, 2002, 2003,
|
79721
|
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
3404
|
5
|
|
6 ;; Author: Morten Welinder <terra@diku.dk>
|
27577
|
7 ;; Keywords: convenience
|
5314
|
8 ;; Favourite-brand-of-beer: None, I hate beer.
|
3404
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
94678
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
3404
|
13 ;; it under the terms of the GNU General Public License as published by
|
94678
|
14 ;; the Free Software Foundation, either version 3 of the License, or
|
|
15 ;; (at your option) any later version.
|
3404
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
94678
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
3404
|
24
|
|
25 ;;; Commentary:
|
|
26
|
4830
|
27 ;; Save the Desktop, i.e.,
|
|
28 ;; - some global variables
|
|
29 ;; - the list of buffers with associated files. For each buffer also
|
|
30 ;; - the major mode
|
|
31 ;; - the default directory
|
|
32 ;; - the point
|
|
33 ;; - the mark & mark-active
|
|
34 ;; - buffer-read-only
|
5465
|
35 ;; - some local variables
|
3404
|
36
|
52674
|
37 ;; To use this, use customize to turn on desktop-save-mode or add the
|
|
38 ;; following line somewhere in your .emacs file:
|
4830
|
39 ;;
|
52674
|
40 ;; (desktop-save-mode 1)
|
5465
|
41 ;;
|
52674
|
42 ;; For further usage information, look at the section
|
|
43 ;; "Saving Emacs Sessions" in the GNU Emacs Manual.
|
3404
|
44
|
52674
|
45 ;; When the desktop module is loaded, the function `desktop-kill' is
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
46 ;; added to the `kill-emacs-hook'. This function is responsible for
|
52674
|
47 ;; saving the desktop when Emacs is killed. Furthermore an anonymous
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
48 ;; function is added to the `after-init-hook'. This function is
|
52674
|
49 ;; responsible for loading the desktop when Emacs is started.
|
5465
|
50
|
64893
|
51 ;; Special handling.
|
|
52 ;; -----------------
|
|
53 ;; Variables `desktop-buffer-mode-handlers' and `desktop-minor-mode-handlers'
|
|
54 ;; are supplied to handle special major and minor modes respectively.
|
|
55 ;; `desktop-buffer-mode-handlers' is an alist of major mode specific functions
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
56 ;; to restore a desktop buffer. Elements must have the form
|
68775
|
57 ;;
|
64893
|
58 ;; (MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
|
68775
|
59 ;;
|
64893
|
60 ;; Functions listed are called by `desktop-create-buffer' when `desktop-read'
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
61 ;; evaluates the desktop file. Buffers with a major mode not specified here,
|
64893
|
62 ;; are restored by the default handler `desktop-restore-file-buffer'.
|
|
63 ;; `desktop-minor-mode-handlers' is an alist of functions to restore
|
|
64 ;; non-standard minor modes. Elements must have the form
|
68775
|
65 ;;
|
64893
|
66 ;; (MINOR-MODE . RESTORE-FUNCTION).
|
68775
|
67 ;;
|
64893
|
68 ;; Functions are called by `desktop-create-buffer' to restore minor modes.
|
|
69 ;; Minor modes not specified here, are restored by the standard minor mode
|
|
70 ;; function. If you write a module that defines a major or minor mode that
|
|
71 ;; needs a special handler, then place code like
|
|
72
|
|
73 ;; (defun foo-restore-desktop-buffer
|
|
74 ;; ...
|
|
75 ;; (add-to-list 'desktop-buffer-mode-handlers
|
|
76 ;; '(foo-mode . foo-restore-desktop-buffer))
|
|
77
|
|
78 ;; or
|
|
79
|
|
80 ;; (defun bar-desktop-restore
|
|
81 ;; ...
|
|
82 ;; (add-to-list 'desktop-minor-mode-handlers
|
|
83 ;; '(bar-mode . bar-desktop-restore))
|
|
84
|
94425
|
85 ;; in the module itself, and make sure that the mode function is
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
86 ;; autoloaded. See the docstrings of `desktop-buffer-mode-handlers' and
|
64893
|
87 ;; `desktop-minor-mode-handlers' for more info.
|
|
88
|
|
89 ;; Minor modes.
|
|
90 ;; ------------
|
|
91 ;; Conventional minor modes (see node "Minor Mode Conventions" in the elisp
|
|
92 ;; manual) are handled in the following way:
|
|
93 ;; When `desktop-save' saves the state of a buffer to the desktop file, it
|
|
94 ;; saves as `desktop-minor-modes' the list of names of those variables in
|
|
95 ;; `minor-mode-alist' that have a non-nil value.
|
|
96 ;; When `desktop-create' restores the buffer, each of the symbols in
|
|
97 ;; `desktop-minor-modes' is called as function with parameter 1.
|
|
98 ;; The variables `desktop-minor-mode-table' and `desktop-minor-mode-handlers'
|
|
99 ;; are used to handle non-conventional minor modes. `desktop-save' uses
|
|
100 ;; `desktop-minor-mode-table' to map minor mode variables to minor mode
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
101 ;; functions before writing `desktop-minor-modes'. If a minor mode has a
|
64893
|
102 ;; variable name that is different form its function name, an entry
|
|
103
|
|
104 ;; (NAME RESTORE-FUNCTION)
|
|
105
|
|
106 ;; should be added to `desktop-minor-mode-table'. If a minor mode should not
|
|
107 ;; be restored, RESTORE-FUNCTION should be set to nil. `desktop-create' uses
|
|
108 ;; `desktop-minor-mode-handlers' to lookup minor modes that needs a restore
|
|
109 ;; function different from the usual minor mode function.
|
|
110 ;; ---------------------------------------------------------------------------
|
28719
|
111
|
5465
|
112 ;; By the way: don't use desktop.el to customize Emacs -- the file .emacs
|
|
113 ;; in your home directory is used for that. Saving global default values
|
|
114 ;; for buffers is an example of misuse.
|
|
115
|
4830
|
116 ;; PLEASE NOTE: The kill ring can be saved as specified by the variable
|
|
117 ;; `desktop-globals-to-save' (by default it isn't). This may result in saving
|
|
118 ;; things you did not mean to keep. Use M-x desktop-clear RET.
|
5465
|
119
|
7240
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
120 ;; Thanks to hetrick@phys.uva.nl (Jim Hetrick) for useful ideas.
|
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
121 ;; avk@rtsg.mot.com (Andrew V. Klein) for a dired tip.
|
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
122 ;; chris@tecc.co.uk (Chris Boucher) for a mark tip.
|
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
123 ;; f89-kam@nada.kth.se (Klas Mellbourn) for a mh-e tip.
|
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
124 ;; kifer@sbkifer.cs.sunysb.edu (M. Kifer) for a bug hunt.
|
11224
|
125 ;; treese@lcs.mit.edu (Win Treese) for ange-ftp tips.
|
14172
|
126 ;; pot@cnuce.cnr.it (Francesco Potorti`) for misc. tips.
|
4830
|
127 ;; ---------------------------------------------------------------------------
|
|
128 ;; TODO:
|
|
129 ;;
|
|
130 ;; Save window configuration.
|
|
131 ;; Recognize more minor modes.
|
|
132 ;; Save mark rings.
|
3404
|
133
|
|
134 ;;; Code:
|
|
135
|
50507
|
136 (defvar desktop-file-version "206"
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
137 "Version number of desktop file format.
|
50507
|
138 Written into the desktop file and used at desktop read to provide
|
|
139 backward compatibility.")
|
|
140
|
5465
|
141 ;; ----------------------------------------------------------------------------
|
4830
|
142 ;; USER OPTIONS -- settings you might want to play with.
|
|
143 ;; ----------------------------------------------------------------------------
|
17411
|
144
|
|
145 (defgroup desktop nil
|
|
146 "Save status of Emacs when you exit."
|
|
147 :group 'frames)
|
|
148
|
52674
|
149 ;;;###autoload
|
|
150 (define-minor-mode desktop-save-mode
|
|
151 "Toggle desktop saving mode.
|
|
152 With numeric ARG, turn desktop saving on if ARG is positive, off
|
71453
|
153 otherwise. If desktop saving is turned on, the state of Emacs is
|
|
154 saved from one session to another. See variable `desktop-save'
|
|
155 and function `desktop-read' for details."
|
52674
|
156 :global t
|
|
157 :group 'desktop)
|
|
158
|
|
159 ;; Maintained for backward compatibility
|
64674
|
160 (define-obsolete-variable-alias 'desktop-enable
|
|
161 'desktop-save-mode "22.1")
|
20526
|
162
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
163 (defun desktop-save-mode-off ()
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
164 "Disable `desktop-save-mode'. Provided for use in hooks."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
165 (desktop-save-mode 0))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
166
|
50507
|
167 (defcustom desktop-save 'ask-if-new
|
52674
|
168 "*Specifies whether the desktop should be saved when it is killed.
|
|
169 A desktop is killed when the user changes desktop or quits Emacs.
|
|
170 Possible values are:
|
50507
|
171 t -- always save.
|
|
172 ask -- always ask.
|
|
173 ask-if-new -- ask if no desktop file exists, otherwise just save.
|
|
174 ask-if-exists -- ask if desktop file exists, otherwise don't save.
|
|
175 if-exists -- save if desktop file exists, otherwise don't save.
|
|
176 nil -- never save.
|
52674
|
177 The desktop is never saved when `desktop-save-mode' is nil.
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
178 The variables `desktop-dirname' and `desktop-base-file-name'
|
52674
|
179 determine where the desktop is saved."
|
71453
|
180 :type
|
|
181 '(choice
|
50507
|
182 (const :tag "Always save" t)
|
|
183 (const :tag "Always ask" ask)
|
|
184 (const :tag "Ask if desktop file is new, else do save" ask-if-new)
|
|
185 (const :tag "Ask if desktop file exists, else don't save" ask-if-exists)
|
|
186 (const :tag "Save if desktop file exists, else don't" if-exists)
|
|
187 (const :tag "Never save" nil))
|
58140
|
188 :group 'desktop
|
59996
|
189 :version "22.1")
|
50507
|
190
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
191 (defcustom desktop-load-locked-desktop 'ask
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
192 "Specifies whether the desktop should be loaded if locked.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
193 Possible values are:
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
194 t -- load anyway.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
195 nil -- don't load.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
196 ask -- ask the user.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
197 If the value is nil, or `ask' and the user chooses not to load the desktop,
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
198 the normal hook `desktop-not-loaded-hook' is run."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
199 :type
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
200 '(choice
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
201 (const :tag "Load anyway" t)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
202 (const :tag "Don't load" nil)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
203 (const :tag "Ask the user" ask))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
204 :group 'desktop
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
205 :version "22.2")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
206
|
94026
|
207 (define-obsolete-variable-alias 'desktop-basefilename
|
|
208 'desktop-base-file-name "22.1")
|
|
209
|
50507
|
210 (defcustom desktop-base-file-name
|
16037
|
211 (convert-standard-filename ".emacs.desktop")
|
52674
|
212 "Name of file for Emacs desktop, excluding the directory part."
|
20526
|
213 :type 'file
|
|
214 :group 'desktop)
|
3404
|
215
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
216 (defcustom desktop-base-lock-name
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
217 (convert-standard-filename ".emacs.desktop.lock")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
218 "Name of lock file for Emacs desktop, excluding the directory part."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
219 :type 'file
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
220 :group 'desktop
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
221 :version "22.2")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
222
|
50507
|
223 (defcustom desktop-path '("." "~")
|
|
224 "List of directories to search for the desktop file.
|
|
225 The base name of the file is specified in `desktop-base-file-name'."
|
|
226 :type '(repeat directory)
|
58140
|
227 :group 'desktop
|
59996
|
228 :version "22.1")
|
50507
|
229
|
17411
|
230 (defcustom desktop-missing-file-warning nil
|
70653
|
231 "If non-nil, offer to recreate the buffer of a deleted file.
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
232 Also pause for a moment to display message about errors signaled in
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
233 `desktop-buffer-mode-handlers'.
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
234
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
235 If nil, just print error messages in the message buffer."
|
17411
|
236 :type 'boolean
|
58140
|
237 :group 'desktop
|
59996
|
238 :version "22.1")
|
3404
|
239
|
50507
|
240 (defcustom desktop-no-desktop-file-hook nil
|
52674
|
241 "Normal hook run when `desktop-read' can't find a desktop file.
|
71453
|
242 Run in the directory in which the desktop file was sought.
|
61236
65075d5373df
(desktop-no-desktop-file-hook, desktop-after-read-hook): Fix docstring.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
243 May be used to show a dired buffer."
|
50507
|
244 :type 'hook
|
58140
|
245 :group 'desktop
|
59996
|
246 :version "22.1")
|
50507
|
247
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
248 (defcustom desktop-not-loaded-hook nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
249 "Normal hook run when the user declines to re-use a desktop file.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
250 Run in the directory in which the desktop file was found.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
251 May be used to deal with accidental multiple Emacs jobs."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
252 :type 'hook
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
253 :group 'desktop
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
254 :options '(desktop-save-mode-off save-buffers-kill-emacs)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
255 :version "22.2")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
256
|
50507
|
257 (defcustom desktop-after-read-hook nil
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
258 "Normal hook run after a successful `desktop-read'.
|
61236
65075d5373df
(desktop-no-desktop-file-hook, desktop-after-read-hook): Fix docstring.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
259 May be used to show a buffer list."
|
50507
|
260 :type 'hook
|
58140
|
261 :group 'desktop
|
71453
|
262 :options '(list-buffers)
|
59996
|
263 :version "22.1")
|
50507
|
264
|
|
265 (defcustom desktop-save-hook nil
|
52674
|
266 "Normal hook run before the desktop is saved in a desktop file.
|
71453
|
267 Run with the desktop buffer current with only the header present.
|
|
268 May be used to add to the desktop code or to truncate history lists,
|
|
269 for example."
|
50507
|
270 :type 'hook
|
|
271 :group 'desktop)
|
|
272
|
57038
|
273 (defcustom desktop-globals-to-save
|
|
274 '(desktop-missing-file-warning
|
|
275 tags-file-name
|
|
276 tags-table-list
|
|
277 search-ring
|
|
278 regexp-search-ring
|
|
279 register-alist)
|
52674
|
280 "List of global variables saved by `desktop-save'.
|
|
281 An element may be variable name (a symbol) or a cons cell of the form
|
|
282 \(VAR . MAX-SIZE), which means to truncate VAR's value to at most
|
|
283 MAX-SIZE elements (if the value is a list) before saving the value.
|
50507
|
284 Feature: Saving `kill-ring' implies saving `kill-ring-yank-pointer'."
|
|
285 :type '(repeat (restricted-sexp :match-alternatives (symbolp consp)))
|
|
286 :group 'desktop)
|
|
287
|
57038
|
288 (defcustom desktop-globals-to-clear
|
|
289 '(kill-ring
|
|
290 kill-ring-yank-pointer
|
|
291 search-ring
|
|
292 search-ring-yank-pointer
|
|
293 regexp-search-ring
|
|
294 regexp-search-ring-yank-pointer)
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
295 "List of global variables that `desktop-clear' will clear.
|
50507
|
296 An element may be variable name (a symbol) or a cons cell of the form
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
297 \(VAR . FORM). Symbols are set to nil and for cons cells VAR is set
|
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
298 to the value obtained by evaluating FORM."
|
50507
|
299 :type '(repeat (restricted-sexp :match-alternatives (symbolp consp)))
|
58140
|
300 :group 'desktop
|
59996
|
301 :version "22.1")
|
3404
|
302
|
64893
|
303 (defcustom desktop-clear-preserve-buffers
|
|
304 '("\\*scratch\\*" "\\*Messages\\*" "\\*server\\*" "\\*tramp/.+\\*")
|
|
305 "*List of buffers that `desktop-clear' should not delete.
|
|
306 Each element is a regular expression. Buffers with a name matched by any of
|
|
307 these won't be deleted."
|
50507
|
308 :type '(repeat string)
|
|
309 :group 'desktop)
|
|
310
|
64893
|
311 ;;;###autoload
|
57038
|
312 (defcustom desktop-locals-to-save
|
|
313 '(desktop-locals-to-save ; Itself! Think it over.
|
|
314 truncate-lines
|
|
315 case-fold-search
|
|
316 case-replace
|
|
317 fill-column
|
|
318 overwrite-mode
|
|
319 change-log-default-name
|
|
320 line-number-mode
|
64893
|
321 column-number-mode
|
|
322 size-indication-mode
|
|
323 buffer-file-coding-system
|
|
324 indent-tabs-mode
|
71453
|
325 tab-width
|
64893
|
326 indicate-buffer-boundaries
|
|
327 indicate-empty-lines
|
|
328 show-trailing-whitespace)
|
10595
|
329 "List of local variables to save for each buffer.
|
64893
|
330 The variables are saved only when they really are local. Conventional minor
|
|
331 modes are restored automatically; they should not be listed here."
|
52674
|
332 :type '(repeat symbol)
|
|
333 :group 'desktop)
|
5465
|
334
|
4830
|
335 ;; We skip .log files because they are normally temporary.
|
14040
|
336 ;; (ftp) files because they require passwords and whatnot.
|
17411
|
337 (defcustom desktop-buffers-not-to-save
|
66278
|
338 "\\(^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\)$"
|
50507
|
339 "Regexp identifying buffers that are to be excluded from saving."
|
|
340 :type 'regexp
|
|
341 :group 'desktop)
|
3404
|
342
|
52674
|
343 ;; Skip tramp and ange-ftp files
|
17411
|
344 (defcustom desktop-files-not-to-save
|
7240
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
345 "^/[^/:]*:"
|
17411
|
346 "Regexp identifying files whose buffers are to be excluded from saving."
|
|
347 :type 'regexp
|
|
348 :group 'desktop)
|
7240
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
349
|
66278
|
350 ;; We skip TAGS files to save time (tags-file-name is saved instead).
|
|
351 (defcustom desktop-modes-not-to-save
|
|
352 '(tags-table-mode)
|
32366
|
353 "List of major modes whose buffers should not be saved."
|
|
354 :type '(repeat symbol)
|
|
355 :group 'desktop)
|
|
356
|
50507
|
357 (defcustom desktop-file-name-format 'absolute
|
|
358 "*Format in which desktop file names should be saved.
|
|
359 Possible values are:
|
|
360 absolute -- Absolute file name.
|
|
361 tilde -- Relative to ~.
|
|
362 local -- Relative to directory of desktop file."
|
|
363 :type '(choice (const absolute) (const tilde) (const local))
|
58140
|
364 :group 'desktop
|
59996
|
365 :version "22.1")
|
14755
|
366
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
367 (defcustom desktop-restore-eager t
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
368 "Number of buffers to restore immediately.
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
369 Remaining buffers are restored lazily (when Emacs is idle).
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
370 If value is t, all buffers are restored immediately."
|
59436
|
371 :type '(choice (const t) integer)
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
372 :group 'desktop
|
59996
|
373 :version "22.1")
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
374
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
375 (defcustom desktop-lazy-verbose t
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
376 "Verbose reporting of lazily created buffers."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
377 :type 'boolean
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
378 :group 'desktop
|
59996
|
379 :version "22.1")
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
380
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
381 (defcustom desktop-lazy-idle-delay 5
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
382 "Idle delay before starting to create buffers.
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
383 See `desktop-restore-eager'."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
384 :type 'integer
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
385 :group 'desktop
|
59996
|
386 :version "22.1")
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
387
|
55059
|
388 ;;;###autoload
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
389 (defvar desktop-save-buffer nil
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
390 "When non-nil, save buffer status in desktop file.
|
55059
|
391 This variable becomes buffer local when set.
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
392
|
64674
|
393 If the value is a function, it is called by `desktop-save' with argument
|
|
394 DESKTOP-DIRNAME to obtain auxiliary information to save in the desktop
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
395 file along with the state of the buffer for which it was called.
|
32447
cfae1c82d702
Added extensible special buffer support to desktop.el. See the
John Wiegley <johnw@newartisans.com>
diff
changeset
|
396
|
52674
|
397 When file names are returned, they should be formatted using the call
|
55059
|
398 \"(desktop-file-name FILE-NAME DESKTOP-DIRNAME)\".
|
50507
|
399
|
64893
|
400 Later, when `desktop-read' evaluates the desktop file, auxiliary information
|
|
401 is passed as the argument DESKTOP-BUFFER-MISC to functions in
|
|
402 `desktop-buffer-mode-handlers'.")
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
403 (make-variable-buffer-local 'desktop-save-buffer)
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
404 (make-obsolete-variable 'desktop-buffer-modes-to-save
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
405 'desktop-save-buffer "22.1")
|
55059
|
406 (make-obsolete-variable 'desktop-buffer-misc-functions
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
407 'desktop-save-buffer "22.1")
|
32447
cfae1c82d702
Added extensible special buffer support to desktop.el. See the
John Wiegley <johnw@newartisans.com>
diff
changeset
|
408
|
64893
|
409 ;;;###autoload
|
|
410 (defvar desktop-buffer-mode-handlers
|
|
411 nil
|
55059
|
412 "Alist of major mode specific functions to restore a desktop buffer.
|
64893
|
413 Functions listed are called by `desktop-create-buffer' when `desktop-read'
|
|
414 evaluates the desktop file. List elements must have the form
|
|
415
|
|
416 (MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
|
55059
|
417
|
|
418 Buffers with a major mode not specified here, are restored by the default
|
|
419 handler `desktop-restore-file-buffer'.
|
|
420
|
55413
|
421 Handlers are called with argument list
|
55059
|
422
|
55418
|
423 (DESKTOP-BUFFER-FILE-NAME DESKTOP-BUFFER-NAME DESKTOP-BUFFER-MISC)
|
55059
|
424
|
|
425 Furthermore, they may use the following variables:
|
50507
|
426
|
|
427 desktop-file-version
|
|
428 desktop-buffer-major-mode
|
|
429 desktop-buffer-minor-modes
|
|
430 desktop-buffer-point
|
|
431 desktop-buffer-mark
|
|
432 desktop-buffer-read-only
|
|
433 desktop-buffer-locals
|
|
434
|
55059
|
435 If a handler returns a buffer, then the saved mode settings
|
64893
|
436 and variable values for that buffer are copied into it.
|
|
437
|
|
438 Modules that define a major mode that needs a special handler should contain
|
|
439 code like
|
|
440
|
|
441 (defun foo-restore-desktop-buffer
|
|
442 ...
|
|
443 (add-to-list 'desktop-buffer-mode-handlers
|
|
444 '(foo-mode . foo-restore-desktop-buffer))
|
|
445
|
|
446 Furthermore the major mode function must be autoloaded.")
|
5465
|
447
|
64963
|
448 ;;;###autoload
|
55059
|
449 (put 'desktop-buffer-mode-handlers 'risky-local-variable t)
|
|
450 (make-obsolete-variable 'desktop-buffer-handlers
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
451 'desktop-buffer-mode-handlers "22.1")
|
32447
cfae1c82d702
Added extensible special buffer support to desktop.el. See the
John Wiegley <johnw@newartisans.com>
diff
changeset
|
452
|
28719
|
453 (defcustom desktop-minor-mode-table
|
|
454 '((auto-fill-function auto-fill-mode)
|
67560
|
455 (vc-mode nil)
|
85771
a7aa5ee6bc3a
Revert bad erc-track change; ignore erc-track-minor-mode properly in desktop
Michael Olson <mwolson@gnu.org>
diff
changeset
|
456 (vc-dired-mode nil)
|
94425
|
457 (erc-track-minor-mode nil)
|
|
458 (savehist-mode nil))
|
28719
|
459 "Table mapping minor mode variables to minor mode functions.
|
|
460 Each entry has the form (NAME RESTORE-FUNCTION).
|
|
461 NAME is the name of the buffer-local variable indicating that the minor
|
|
462 mode is active. RESTORE-FUNCTION is the function to activate the minor mode.
|
77991
|
463 RESTORE-FUNCTION nil means don't try to restore the minor mode.
|
28719
|
464 Only minor modes for which the name of the buffer-local variable
|
55871
27173676bedf
(desktop-save): Don't save minor modes without a known mode initialization function.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
465 and the name of the minor mode function are different have to be added to
|
64893
|
466 this table. See also `desktop-minor-mode-handlers'."
|
28719
|
467 :type 'sexp
|
|
468 :group 'desktop)
|
|
469
|
64893
|
470 ;;;###autoload
|
|
471 (defvar desktop-minor-mode-handlers
|
|
472 nil
|
|
473 "Alist of functions to restore non-standard minor modes.
|
|
474 Functions are called by `desktop-create-buffer' to restore minor modes.
|
|
475 List elements must have the form
|
|
476
|
|
477 (MINOR-MODE . RESTORE-FUNCTION).
|
|
478
|
|
479 Minor modes not specified here, are restored by the standard minor mode
|
|
480 function.
|
|
481
|
|
482 Handlers are called with argument list
|
|
483
|
|
484 (DESKTOP-BUFFER-LOCALS)
|
|
485
|
|
486 Furthermore, they may use the following variables:
|
|
487
|
|
488 desktop-file-version
|
|
489 desktop-buffer-file-name
|
|
490 desktop-buffer-name
|
|
491 desktop-buffer-major-mode
|
|
492 desktop-buffer-minor-modes
|
|
493 desktop-buffer-point
|
|
494 desktop-buffer-mark
|
|
495 desktop-buffer-read-only
|
|
496 desktop-buffer-misc
|
|
497
|
|
498 When a handler is called, the buffer has been created and the major mode has
|
|
499 been set, but local variables listed in desktop-buffer-locals has not yet been
|
|
500 created and set.
|
|
501
|
|
502 Modules that define a minor mode that needs a special handler should contain
|
|
503 code like
|
|
504
|
|
505 (defun foo-desktop-restore
|
|
506 ...
|
|
507 (add-to-list 'desktop-minor-mode-handlers
|
|
508 '(foo-mode . foo-desktop-restore))
|
|
509
|
|
510 Furthermore the minor mode function must be autoloaded.
|
|
511
|
|
512 See also `desktop-minor-mode-table'.")
|
|
513
|
64963
|
514 ;;;###autoload
|
64893
|
515 (put 'desktop-minor-mode-handlers 'risky-local-variable t)
|
|
516
|
4830
|
517 ;; ----------------------------------------------------------------------------
|
|
518 (defvar desktop-dirname nil
|
52674
|
519 "The directory in which the desktop file should be saved.")
|
3404
|
520
|
71453
|
521 (defun desktop-full-file-name (&optional dirname)
|
|
522 "Return the full name of the desktop file in DIRNAME.
|
|
523 DIRNAME omitted or nil means use `desktop-dirname'."
|
|
524 (expand-file-name desktop-base-file-name (or dirname desktop-dirname)))
|
|
525
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
526 (defun desktop-full-lock-name (&optional dirname)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
527 "Return the full name of the desktop lock file in DIRNAME.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
528 DIRNAME omitted or nil means use `desktop-dirname'."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
529 (expand-file-name desktop-base-lock-name (or dirname desktop-dirname)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
530
|
3404
|
531 (defconst desktop-header
|
4830
|
532 ";; --------------------------------------------------------------------------
|
|
533 ;; Desktop File for Emacs
|
|
534 ;; --------------------------------------------------------------------------
|
3404
|
535 " "*Header to place in Desktop file.")
|
5788
|
536
|
|
537 (defvar desktop-delay-hook nil
|
|
538 "Hooks run after all buffers are loaded; intended for internal use.")
|
20526
|
539
|
4830
|
540 ;; ----------------------------------------------------------------------------
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
541 ;; Desktop file conflict detection
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
542 (defvar desktop-file-modtime nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
543 "When the desktop file was last modified to the knowledge of this Emacs.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
544 Used to detect desktop file conflicts.")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
545
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
546 (defun desktop-owner (&optional dirname)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
547 "Return the PID of the Emacs process that owns the desktop file in DIRNAME.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
548 Return nil if no desktop file found or no Emacs process is using it.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
549 DIRNAME omitted or nil means use `desktop-dirname'."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
550 (let (owner)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
551 (and (file-exists-p (desktop-full-lock-name dirname))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
552 (condition-case nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
553 (with-temp-buffer
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
554 (insert-file-contents-literally (desktop-full-lock-name dirname))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
555 (goto-char (point-min))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
556 (setq owner (read (current-buffer)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
557 (integerp owner))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
558 (error nil))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
559 owner)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
560
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
561 (defun desktop-claim-lock (&optional dirname)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
562 "Record this Emacs process as the owner of the desktop file in DIRNAME.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
563 DIRNAME omitted or nil means use `desktop-dirname'."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
564 (write-region (number-to-string (emacs-pid)) nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
565 (desktop-full-lock-name dirname)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
566
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
567 (defun desktop-release-lock (&optional dirname)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
568 "Remove the lock file for the desktop in DIRNAME.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
569 DIRNAME omitted or nil means use `desktop-dirname'."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
570 (let ((file (desktop-full-lock-name dirname)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
571 (when (file-exists-p file) (delete-file file))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
572
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
573 ;; ----------------------------------------------------------------------------
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
574 (defun desktop-truncate (list n)
|
5465
|
575 "Truncate LIST to at most N elements destructively."
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
576 (let ((here (nthcdr (1- n) list)))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
577 (when (consp here)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
578 (setcdr here nil))))
|
50507
|
579
|
5465
|
580 ;; ----------------------------------------------------------------------------
|
71453
|
581 ;;;###autoload
|
18581
|
582 (defun desktop-clear ()
|
|
583 "Empty the Desktop.
|
64893
|
584 This kills all buffers except for internal ones and those with names matched by
|
|
585 a regular expression in the list `desktop-clear-preserve-buffers'.
|
|
586 Furthermore, it clears the variables listed in `desktop-globals-to-clear'."
|
3404
|
587 (interactive)
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
588 (desktop-lazy-abort)
|
50507
|
589 (dolist (var desktop-globals-to-clear)
|
|
590 (if (symbolp var)
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
591 (eval `(setq-default ,var nil))
|
50507
|
592 (eval `(setq-default ,(car var) ,(cdr var)))))
|
64893
|
593 (let ((buffers (buffer-list))
|
|
594 (preserve-regexp (concat "^\\("
|
|
595 (mapconcat (lambda (regexp)
|
|
596 (concat "\\(" regexp "\\)"))
|
|
597 desktop-clear-preserve-buffers
|
|
598 "\\|")
|
|
599 "\\)$")))
|
18581
|
600 (while buffers
|
50507
|
601 (let ((bufname (buffer-name (car buffers))))
|
|
602 (or
|
|
603 (null bufname)
|
64893
|
604 (string-match preserve-regexp bufname)
|
50507
|
605 ;; Don't kill buffers made for internal purposes.
|
64519
|
606 (and (not (equal bufname "")) (eq (aref bufname 0) ?\s))
|
50507
|
607 (kill-buffer (car buffers))))
|
18581
|
608 (setq buffers (cdr buffers))))
|
5314
|
609 (delete-other-windows))
|
50507
|
610
|
4830
|
611 ;; ----------------------------------------------------------------------------
|
5788
|
612 (add-hook 'kill-emacs-hook 'desktop-kill)
|
5465
|
613
|
3404
|
614 (defun desktop-kill ()
|
52674
|
615 "If `desktop-save-mode' is non-nil, do what `desktop-save' says to do.
|
50507
|
616 If the desktop should be saved and `desktop-dirname'
|
|
617 is nil, ask the user where to save the desktop."
|
71453
|
618 (when (and desktop-save-mode
|
|
619 (let ((exists (file-exists-p (desktop-full-file-name))))
|
|
620 (or (eq desktop-save t)
|
|
621 (and exists (memq desktop-save '(ask-if-new if-exists)))
|
|
622 (and
|
|
623 (or (memq desktop-save '(ask ask-if-new))
|
|
624 (and exists (eq desktop-save 'ask-if-exists)))
|
|
625 (y-or-n-p "Save desktop? ")))))
|
50507
|
626 (unless desktop-dirname
|
|
627 (setq desktop-dirname
|
71453
|
628 (file-name-as-directory
|
|
629 (expand-file-name
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
630 (read-directory-name "Directory for desktop file: " nil nil t)))))
|
50507
|
631 (condition-case err
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
632 (desktop-save desktop-dirname t)
|
50507
|
633 (file-error
|
71453
|
634 (unless (yes-or-no-p "Error while saving the desktop. Ignore? ")
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
635 (signal (car err) (cdr err))))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
636 ;; If we own it, we don't anymore.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
637 (when (eq (emacs-pid) (desktop-owner)) (desktop-release-lock)))
|
50507
|
638
|
4830
|
639 ;; ----------------------------------------------------------------------------
|
14754
|
640 (defun desktop-list* (&rest args)
|
|
641 (if (null (cdr args))
|
|
642 (car args)
|
|
643 (setq args (nreverse args))
|
|
644 (let ((value (cons (nth 1 args) (car args))))
|
|
645 (setq args (cdr (cdr args)))
|
|
646 (while args
|
|
647 (setq value (cons (car args) value))
|
|
648 (setq args (cdr args)))
|
|
649 value)))
|
|
650
|
50507
|
651 ;; ----------------------------------------------------------------------------
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
652 (defun desktop-buffer-info (buffer)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
653 (set-buffer buffer)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
654 (list
|
91841
|
655 ;; base name of the buffer; replaces the buffer name if managed by uniquify
|
|
656 (and (fboundp 'uniquify-buffer-base-name) (uniquify-buffer-base-name))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
657 ;; basic information
|
78110
33c9a00ace1e
(desktop-buffer-info, desktop-save): Use `desktop-dirname' instead of `dirname'.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
658 (desktop-file-name (buffer-file-name) desktop-dirname)
|
91841
|
659 (buffer-name)
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
660 major-mode
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
661 ;; minor modes
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
662 (let (ret)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
663 (mapc
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
664 #'(lambda (minor-mode)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
665 (and (boundp minor-mode)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
666 (symbol-value minor-mode)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
667 (let* ((special (assq minor-mode desktop-minor-mode-table))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
668 (value (cond (special (cadr special))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
669 ((functionp minor-mode) minor-mode))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
670 (when value (add-to-list 'ret value)))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
671 (mapcar #'car minor-mode-alist))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
672 ret)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
673 ;; point and mark, and read-only status
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
674 (point)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
675 (list (mark t) mark-active)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
676 buffer-read-only
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
677 ;; auxiliary information
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
678 (when (functionp desktop-save-buffer)
|
78110
33c9a00ace1e
(desktop-buffer-info, desktop-save): Use `desktop-dirname' instead of `dirname'.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
679 (funcall desktop-save-buffer desktop-dirname))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
680 ;; local variables
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
681 (let ((locals desktop-locals-to-save)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
682 (loclist (buffer-local-variables))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
683 (ll))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
684 (while locals
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
685 (let ((here (assq (car locals) loclist)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
686 (if here
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
687 (setq ll (cons here ll))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
688 (when (member (car locals) loclist)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
689 (setq ll (cons (car locals) ll)))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
690 (setq locals (cdr locals)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
691 ll)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
692
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
693 ;; ----------------------------------------------------------------------------
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
694 (defun desktop-internal-v2s (value)
|
10595
|
695 "Convert VALUE to a pair (QUOTE . TXT); (eval (read TXT)) gives VALUE.
|
|
696 TXT is a string that when read and evaluated yields value.
|
|
697 QUOTE may be `may' (value may be quoted),
|
|
698 `must' (values must be quoted), or nil (value may not be quoted)."
|
5788
|
699 (cond
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
700 ((or (numberp value) (null value) (eq t value) (keywordp value))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
701 (cons 'may (prin1-to-string value)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
702 ((stringp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
703 (let ((copy (copy-sequence value)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
704 (set-text-properties 0 (length copy) nil copy)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
705 ;; Get rid of text properties because we cannot read them
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
706 (cons 'may (prin1-to-string copy))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
707 ((symbolp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
708 (cons 'must (prin1-to-string value)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
709 ((vectorp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
710 (let* ((special nil)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
711 (pass1 (mapcar
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
712 (lambda (el)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
713 (let ((res (desktop-internal-v2s el)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
714 (if (null (car res))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
715 (setq special t))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
716 res))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
717 value)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
718 (if special
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
719 (cons nil (concat "(vector "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
720 (mapconcat (lambda (el)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
721 (if (eq (car el) 'must)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
722 (concat "'" (cdr el))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
723 (cdr el)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
724 pass1
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
725 " ")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
726 ")"))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
727 (cons 'may (concat "[" (mapconcat 'cdr pass1 " ") "]")))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
728 ((consp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
729 (let ((p value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
730 newlist
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
731 use-list*
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
732 anynil)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
733 (while (consp p)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
734 (let ((q.txt (desktop-internal-v2s (car p))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
735 (or anynil (setq anynil (null (car q.txt))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
736 (setq newlist (cons q.txt newlist)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
737 (setq p (cdr p)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
738 (if p
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
739 (let ((last (desktop-internal-v2s p)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
740 (or anynil (setq anynil (null (car last))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
741 (or anynil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
742 (setq newlist (cons '(must . ".") newlist)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
743 (setq use-list* t)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
744 (setq newlist (cons last newlist))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
745 (setq newlist (nreverse newlist))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
746 (if anynil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
747 (cons nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
748 (concat (if use-list* "(desktop-list* " "(list ")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
749 (mapconcat (lambda (el)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
750 (if (eq (car el) 'must)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
751 (concat "'" (cdr el))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
752 (cdr el)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
753 newlist
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
754 " ")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
755 ")"))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
756 (cons 'must
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
757 (concat "(" (mapconcat 'cdr newlist " ") ")")))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
758 ((subrp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
759 (cons nil (concat "(symbol-function '"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
760 (substring (prin1-to-string value) 7 -1)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
761 ")")))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
762 ((markerp value)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
763 (let ((pos (prin1-to-string (marker-position value)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
764 (buf (prin1-to-string (buffer-name (marker-buffer value)))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
765 (cons nil (concat "(let ((mk (make-marker)))"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
766 " (add-hook 'desktop-delay-hook"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
767 " (list 'lambda '() (list 'set-marker mk "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
768 pos " (get-buffer " buf ")))) mk)"))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
769 (t ; save as text
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
770 (cons 'may "\"Unprintable entity\""))))
|
5788
|
771
|
50507
|
772 ;; ----------------------------------------------------------------------------
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
773 (defun desktop-value-to-string (value)
|
10595
|
774 "Convert VALUE to a string that when read evaluates to the same value.
|
|
775 Not all types of values are supported."
|
5788
|
776 (let* ((print-escape-newlines t)
|
|
777 (float-output-format nil)
|
54206
ecf0e7a0567a
(desktop-file-version, desktop-after-read-hook): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
778 (quote.txt (desktop-internal-v2s value))
|
5788
|
779 (quote (car quote.txt))
|
|
780 (txt (cdr quote.txt)))
|
|
781 (if (eq quote 'must)
|
|
782 (concat "'" txt)
|
|
783 txt)))
|
50507
|
784
|
5465
|
785 ;; ----------------------------------------------------------------------------
|
13154
|
786 (defun desktop-outvar (varspec)
|
|
787 "Output a setq statement for variable VAR to the desktop file.
|
|
788 The argument VARSPEC may be the variable name VAR (a symbol),
|
68775
|
789 or a cons cell of the form (VAR . MAX-SIZE),
|
13154
|
790 which means to truncate VAR's value to at most MAX-SIZE elements
|
|
791 \(if the value is a list) before saving the value."
|
|
792 (let (var size)
|
|
793 (if (consp varspec)
|
|
794 (setq var (car varspec) size (cdr varspec))
|
|
795 (setq var varspec))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
796 (when (boundp var)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
797 (when (and (integerp size)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
798 (> size 0)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
799 (listp (eval var)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
800 (desktop-truncate (eval var) size))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
801 (insert "(setq "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
802 (symbol-name var)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
803 " "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
804 (desktop-value-to-string (symbol-value var))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
805 ")\n"))))
|
50507
|
806
|
4830
|
807 ;; ----------------------------------------------------------------------------
|
5465
|
808 (defun desktop-save-buffer-p (filename bufname mode &rest dummy)
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
809 "Return t if buffer should have its state saved in the desktop file.
|
4830
|
810 FILENAME is the visited file name, BUFNAME is the buffer name, and
|
68775
|
811 MODE is the major mode.
|
|
812 \n\(fn FILENAME BUFNAME MODE)"
|
7240
195e64dad1eb
(desktop-files-not-to-save): New variable to exclude certain files -- magic
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
813 (let ((case-fold-search nil))
|
32366
|
814 (and (not (string-match desktop-buffers-not-to-save bufname))
|
55155
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
815 (not (memq mode desktop-modes-not-to-save))
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
816 (or (and filename
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
817 (not (string-match desktop-files-not-to-save filename)))
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
818 (and (eq mode 'dired-mode)
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
819 (with-current-buffer bufname
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
820 (not (string-match desktop-files-not-to-save
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
821 default-directory))))
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
822 (and (null filename)
|
519f44af960a
(desktop-buffer-misc-data-function): Rename to desktop-save-buffer and change docstring.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
823 (with-current-buffer bufname desktop-save-buffer))))))
|
50507
|
824
|
4830
|
825 ;; ----------------------------------------------------------------------------
|
50507
|
826 (defun desktop-file-name (filename dirname)
|
|
827 "Convert FILENAME to format specified in `desktop-file-name-format'.
|
|
828 DIRNAME must be the directory in which the desktop file will be saved."
|
|
829 (cond
|
|
830 ((not filename) nil)
|
|
831 ((eq desktop-file-name-format 'tilde)
|
|
832 (let ((relative-name (file-relative-name (expand-file-name filename) "~")))
|
|
833 (cond
|
|
834 ((file-name-absolute-p relative-name) relative-name)
|
|
835 ((string= "./" relative-name) "~/")
|
|
836 ((string= "." relative-name) "~")
|
|
837 (t (concat "~/" relative-name)))))
|
|
838 ((eq desktop-file-name-format 'local) (file-relative-name filename dirname))
|
|
839 (t (expand-file-name filename))))
|
48143
|
840
|
90951
|
841
|
50507
|
842 ;; ----------------------------------------------------------------------------
|
71453
|
843 ;;;###autoload
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
844 (defun desktop-save (dirname &optional release)
|
52674
|
845 "Save the desktop in a desktop file.
|
|
846 Parameter DIRNAME specifies where to save the desktop file.
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
847 Optional parameter RELEASE says whether we're done with this desktop.
|
52674
|
848 See also `desktop-base-file-name'."
|
3404
|
849 (interactive "DDirectory to save desktop file in: ")
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
850 (setq desktop-dirname (file-name-as-directory (expand-file-name dirname)))
|
3404
|
851 (save-excursion
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
852 (let ((eager desktop-restore-eager)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
853 (new-modtime (nth 5 (file-attributes (desktop-full-file-name)))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
854 (when
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
855 (or (not new-modtime) ; nothing to overwrite
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
856 (equal desktop-file-modtime new-modtime)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
857 (yes-or-no-p (if desktop-file-modtime
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
858 (if (> (float-time new-modtime) (float-time desktop-file-modtime))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
859 "Desktop file is more recent than the one loaded. Save anyway? "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
860 "Desktop file isn't the one loaded. Overwrite it? ")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
861 "Current desktop was not loaded from a file. Overwrite this desktop file? "))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
862 (unless release (error "Desktop file conflict")))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
863
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
864 ;; If we're done with it, release the lock.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
865 ;; Otherwise, claim it if it's unclaimed or if we created it.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
866 (if release
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
867 (desktop-release-lock)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
868 (unless (and new-modtime (desktop-owner)) (desktop-claim-lock)))
|
3404
|
869
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
870 (with-temp-buffer
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
871 (insert
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
872 ";; -*- mode: emacs-lisp; coding: emacs-mule; -*-\n"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
873 desktop-header
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
874 ";; Created " (current-time-string) "\n"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
875 ";; Desktop file format version " desktop-file-version "\n"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
876 ";; Emacs version " emacs-version "\n")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
877 (save-excursion (run-hooks 'desktop-save-hook))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
878 (goto-char (point-max))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
879 (insert "\n;; Global section:\n")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
880 (mapc (function desktop-outvar) desktop-globals-to-save)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
881 (when (memq 'kill-ring desktop-globals-to-save)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
882 (insert
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
883 "(setq kill-ring-yank-pointer (nthcdr "
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
884 (int-to-string (- (length kill-ring) (length kill-ring-yank-pointer)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
885 " kill-ring))\n"))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
886
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
887 (insert "\n;; Buffer section -- buffers listed in same order as in buffer list:\n")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
888 (dolist (l (mapcar 'desktop-buffer-info (buffer-list)))
|
91841
|
889 (let ((base (pop l)))
|
|
890 (when (apply 'desktop-save-buffer-p l)
|
|
891 (insert "("
|
|
892 (if (or (not (integerp eager))
|
|
893 (if (zerop eager)
|
|
894 nil
|
|
895 (setq eager (1- eager))))
|
|
896 "desktop-create-buffer"
|
|
897 "desktop-append-buffer-args")
|
|
898 " "
|
|
899 desktop-file-version)
|
92328
04dddf68dfc0
(desktop-save): Save the buffer name if the uniquified base name is empty.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
900 ;; If there's a non-empty base name, we save it instead of the buffer name
|
04dddf68dfc0
(desktop-save): Save the buffer name if the uniquified base name is empty.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
901 (when (and base (not (string= base "")))
|
04dddf68dfc0
(desktop-save): Save the buffer name if the uniquified base name is empty.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
902 (setcar (nthcdr 1 l) base))
|
91841
|
903 (dolist (e l)
|
|
904 (insert "\n " (desktop-value-to-string e)))
|
|
905 (insert ")\n\n"))))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
906
|
78110
33c9a00ace1e
(desktop-buffer-info, desktop-save): Use `desktop-dirname' instead of `dirname'.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
907 (setq default-directory desktop-dirname)
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
908 (let ((coding-system-for-write 'emacs-mule))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
909 (write-region (point-min) (point-max) (desktop-full-file-name) nil 'nomessage))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
910 ;; We remember when it was modified (which is presumably just now).
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
911 (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name)))))))))
|
50507
|
912
|
4830
|
913 ;; ----------------------------------------------------------------------------
|
71453
|
914 ;;;###autoload
|
3404
|
915 (defun desktop-remove ()
|
52674
|
916 "Delete desktop file in `desktop-dirname'.
|
|
917 This function also sets `desktop-dirname' to nil."
|
3404
|
918 (interactive)
|
52674
|
919 (when desktop-dirname
|
71453
|
920 (let ((filename (desktop-full-file-name)))
|
52674
|
921 (setq desktop-dirname nil)
|
|
922 (when (file-exists-p filename)
|
|
923 (delete-file filename)))))
|
50507
|
924
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
925 (defvar desktop-buffer-args-list nil
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
926 "List of args for `desktop-create-buffer'.")
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
927
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
928 (defvar desktop-lazy-timer nil)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
929
|
4830
|
930 ;; ----------------------------------------------------------------------------
|
21303
|
931 ;;;###autoload
|
52674
|
932 (defun desktop-read (&optional dirname)
|
|
933 "Read and process the desktop file in directory DIRNAME.
|
|
934 Look for a desktop file in DIRNAME, or if DIRNAME is omitted, look in
|
|
935 directories listed in `desktop-path'. If a desktop file is found, it
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
936 is processed and `desktop-after-read-hook' is run. If no desktop file
|
52674
|
937 is found, clear the desktop and run `desktop-no-desktop-file-hook'.
|
|
938 This function is a no-op when Emacs is running in batch mode.
|
|
939 It returns t if a desktop file was loaded, nil otherwise."
|
|
940 (interactive)
|
|
941 (unless noninteractive
|
|
942 (setq desktop-dirname
|
71453
|
943 (file-name-as-directory
|
|
944 (expand-file-name
|
|
945 (or
|
|
946 ;; If DIRNAME is specified, use it.
|
|
947 (and (< 0 (length dirname)) dirname)
|
|
948 ;; Otherwise search desktop file in desktop-path.
|
|
949 (let ((dirs desktop-path))
|
|
950 (while (and dirs
|
|
951 (not (file-exists-p
|
|
952 (desktop-full-file-name (car dirs)))))
|
|
953 (setq dirs (cdr dirs)))
|
|
954 (and dirs (car dirs)))
|
|
955 ;; If not found and `desktop-path' is non-nil, use its first element.
|
|
956 (and desktop-path (car desktop-path))
|
|
957 ;; Default: Home directory.
|
|
958 "~"))))
|
|
959 (if (file-exists-p (desktop-full-file-name))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
960 ;; Desktop file found, but is it already in use?
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
961 (let ((desktop-first-buffer nil)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
962 (desktop-buffer-ok-count 0)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
963 (desktop-buffer-fail-count 0)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
964 (owner (desktop-owner))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
965 ;; Avoid desktop saving during evaluation of desktop buffer.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
966 (desktop-save nil))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
967 (if (and owner
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
968 (memq desktop-load-locked-desktop '(nil ask))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
969 (or (null desktop-load-locked-desktop)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
970 (not (y-or-n-p (format "Warning: desktop file appears to be in use by PID %s.\n\
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
971 Using it may cause conflicts. Use it anyway? " owner)))))
|
92364
4cf1d5a7cc52
(desktop-read): Set `desktop-dirname' to nil before running
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
972 (let ((default-directory desktop-dirname))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
973 (setq desktop-dirname nil)
|
92364
4cf1d5a7cc52
(desktop-read): Set `desktop-dirname' to nil before running
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
974 (run-hooks 'desktop-not-loaded-hook)
|
4cf1d5a7cc52
(desktop-read): Set `desktop-dirname' to nil before running
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
975 (unless desktop-dirname
|
4cf1d5a7cc52
(desktop-read): Set `desktop-dirname' to nil before running
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
976 (message "Desktop file in use; not loaded.")))
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
977 (desktop-lazy-abort)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
978 ;; Evaluate desktop buffer and remember when it was modified.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
979 (load (desktop-full-file-name) t t t)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
980 (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
981 ;; If it wasn't already, mark it as in-use, to bother other
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
982 ;; desktop instances.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
983 (unless owner
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
984 (condition-case nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
985 (desktop-claim-lock)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
986 (file-error (message "Couldn't record use of desktop file")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
987 (sit-for 1))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
988
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
989 ;; `desktop-create-buffer' puts buffers at end of the buffer list.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
990 ;; We want buffers existing prior to evaluating the desktop (and
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
991 ;; not reused) to be placed at the end of the buffer list, so we
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
992 ;; move them here.
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
993 (mapc 'bury-buffer
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
994 (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list))))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
995 (switch-to-buffer (car (buffer-list)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
996 (run-hooks 'desktop-delay-hook)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
997 (setq desktop-delay-hook nil)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
998 (run-hooks 'desktop-after-read-hook)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
999 (message "Desktop: %d buffer%s restored%s%s."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1000 desktop-buffer-ok-count
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1001 (if (= 1 desktop-buffer-ok-count) "" "s")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1002 (if (< 0 desktop-buffer-fail-count)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1003 (format ", %d failed to restore" desktop-buffer-fail-count)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1004 "")
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1005 (if desktop-buffer-args-list
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1006 (format ", %d to restore lazily"
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1007 (length desktop-buffer-args-list))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1008 ""))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1009 t))
|
52674
|
1010 ;; No desktop file found.
|
|
1011 (desktop-clear)
|
|
1012 (let ((default-directory desktop-dirname))
|
|
1013 (run-hooks 'desktop-no-desktop-file-hook))
|
|
1014 (message "No desktop file.")
|
|
1015 nil)))
|
|
1016
|
|
1017 ;; ----------------------------------------------------------------------------
|
|
1018 ;; Maintained for backward compatibility
|
|
1019 ;;;###autoload
|
3404
|
1020 (defun desktop-load-default ()
|
10595
|
1021 "Load the `default' start-up library manually.
|
52674
|
1022 Also inhibit further loading of it."
|
64674
|
1023 (unless inhibit-default-init ; safety check
|
|
1024 (load "default" t t)
|
|
1025 (setq inhibit-default-init t)))
|
|
1026 (make-obsolete 'desktop-load-default
|
|
1027 'desktop-save-mode "22.1")
|
50507
|
1028
|
|
1029 ;; ----------------------------------------------------------------------------
|
|
1030 ;;;###autoload
|
52674
|
1031 (defun desktop-change-dir (dirname)
|
|
1032 "Change to desktop saved in DIRNAME.
|
|
1033 Kill the desktop as specified by variables `desktop-save-mode' and
|
|
1034 `desktop-save', then clear the desktop and load the desktop file in
|
|
1035 directory DIRNAME."
|
|
1036 (interactive "DChange to directory: ")
|
|
1037 (setq dirname (file-name-as-directory (expand-file-name dirname desktop-dirname)))
|
50507
|
1038 (desktop-kill)
|
|
1039 (desktop-clear)
|
52674
|
1040 (desktop-read dirname))
|
59996
|
1041
|
52674
|
1042 ;; ----------------------------------------------------------------------------
|
50507
|
1043 ;;;###autoload
|
52674
|
1044 (defun desktop-save-in-desktop-dir ()
|
|
1045 "Save the desktop in directory `desktop-dirname'."
|
50507
|
1046 (interactive)
|
|
1047 (if desktop-dirname
|
64674
|
1048 (desktop-save desktop-dirname)
|
50507
|
1049 (call-interactively 'desktop-save))
|
|
1050 (message "Desktop saved in %s" desktop-dirname))
|
|
1051
|
|
1052 ;; ----------------------------------------------------------------------------
|
|
1053 ;;;###autoload
|
|
1054 (defun desktop-revert ()
|
|
1055 "Revert to the last loaded desktop."
|
|
1056 (interactive)
|
52674
|
1057 (unless desktop-dirname
|
|
1058 (error "Unknown desktop directory"))
|
71453
|
1059 (unless (file-exists-p (desktop-full-file-name))
|
52674
|
1060 (error "No desktop file found"))
|
|
1061 (desktop-clear)
|
|
1062 (desktop-read desktop-dirname))
|
50507
|
1063
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1064 (defvar desktop-buffer-major-mode)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1065 (defvar desktop-buffer-locals)
|
4830
|
1066 ;; ----------------------------------------------------------------------------
|
55059
|
1067 (defun desktop-restore-file-buffer (desktop-buffer-file-name
|
|
1068 desktop-buffer-name
|
|
1069 desktop-buffer-misc)
|
|
1070 "Restore a file buffer."
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1071 (when desktop-buffer-file-name
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1072 (if (or (file-exists-p desktop-buffer-file-name)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1073 (let ((msg (format "Desktop: File \"%s\" no longer exists."
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1074 desktop-buffer-file-name)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1075 (if desktop-missing-file-warning
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1076 (y-or-n-p (concat msg " Re-create buffer? "))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1077 (message "%s" msg)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1078 nil)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1079 (let* ((auto-insert nil) ; Disable auto insertion
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1080 (coding-system-for-read
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1081 (or coding-system-for-read
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1082 (cdr (assq 'buffer-file-coding-system
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1083 desktop-buffer-locals))))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1084 (buf (find-file-noselect desktop-buffer-file-name)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1085 (condition-case nil
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1086 (switch-to-buffer buf)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1087 (error (pop-to-buffer buf)))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1088 (and (not (eq major-mode desktop-buffer-major-mode))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1089 (functionp desktop-buffer-major-mode)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1090 (funcall desktop-buffer-major-mode))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1091 buf)
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1092 nil)))
|
50507
|
1093
|
64893
|
1094 (defun desktop-load-file (function)
|
|
1095 "Load the file where auto loaded FUNCTION is defined."
|
66037
|
1096 (when function
|
68344
ffdb60daf52a
(desktop-load-file): Check for `fboundp' before calling `symbol-function'.
Juri Linkov <juri@jurta.org>
diff
changeset
|
1097 (let ((fcell (and (fboundp function) (symbol-function function))))
|
66037
|
1098 (when (and (listp fcell)
|
|
1099 (eq 'autoload (car fcell)))
|
|
1100 (load (cadr fcell))))))
|
64893
|
1101
|
4830
|
1102 ;; ----------------------------------------------------------------------------
|
55179
|
1103 ;; Create a buffer, load its file, set its mode, ...;
|
|
1104 ;; called from Desktop file only.
|
40210
|
1105
|
64893
|
1106 ;; Just to silence the byte compiler.
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1107
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1108 (defvar desktop-first-buffer) ; Dynamically bound in `desktop-read'
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1109
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1110 ;; Bound locally in `desktop-read'.
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1111 (defvar desktop-buffer-ok-count)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1112 (defvar desktop-buffer-fail-count)
|
40210
|
1113
|
57038
|
1114 (defun desktop-create-buffer
|
|
1115 (desktop-file-version
|
|
1116 desktop-buffer-file-name
|
|
1117 desktop-buffer-name
|
|
1118 desktop-buffer-major-mode
|
|
1119 desktop-buffer-minor-modes
|
|
1120 desktop-buffer-point
|
|
1121 desktop-buffer-mark
|
|
1122 desktop-buffer-read-only
|
|
1123 desktop-buffer-misc
|
|
1124 &optional
|
|
1125 desktop-buffer-locals)
|
50507
|
1126 ;; To make desktop files with relative file names possible, we cannot
|
|
1127 ;; allow `default-directory' to change. Therefore we save current buffer.
|
|
1128 (save-current-buffer
|
64893
|
1129 ;; Give major mode module a chance to add a handler.
|
|
1130 (desktop-load-file desktop-buffer-major-mode)
|
57038
|
1131 (let ((buffer-list (buffer-list))
|
|
1132 (result
|
92944
6dea71380597
(desktop-create-buffer): Don't catch errors if debug-on-error is set.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1133 (condition-case-no-debug err
|
57038
|
1134 (funcall (or (cdr (assq desktop-buffer-major-mode
|
|
1135 desktop-buffer-mode-handlers))
|
|
1136 'desktop-restore-file-buffer)
|
|
1137 desktop-buffer-file-name
|
|
1138 desktop-buffer-name
|
|
1139 desktop-buffer-misc)
|
|
1140 (error
|
|
1141 (message "Desktop: Can't load buffer %s: %s"
|
|
1142 desktop-buffer-name
|
|
1143 (error-message-string err))
|
|
1144 (when desktop-missing-file-warning (sit-for 1))
|
|
1145 nil))))
|
55059
|
1146 (if (bufferp result)
|
|
1147 (setq desktop-buffer-ok-count (1+ desktop-buffer-ok-count))
|
|
1148 (setq desktop-buffer-fail-count (1+ desktop-buffer-fail-count))
|
|
1149 (setq result nil))
|
51107
0c33d2fd9ae4
(desktop-save): Ensure parameter is expanded and ends with a slash before
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1150 ;; Restore buffer list order with new buffer at end. Don't change
|
0c33d2fd9ae4
(desktop-save): Ensure parameter is expanded and ends with a slash before
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1151 ;; the order for old desktop files (old desktop module behaviour).
|
50507
|
1152 (unless (< desktop-file-version 206)
|
58537
|
1153 (mapc 'bury-buffer buffer-list)
|
51107
0c33d2fd9ae4
(desktop-save): Ensure parameter is expanded and ends with a slash before
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1154 (when result (bury-buffer result)))
|
50507
|
1155 (when result
|
51107
0c33d2fd9ae4
(desktop-save): Ensure parameter is expanded and ends with a slash before
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1156 (unless (or desktop-first-buffer (< desktop-file-version 206))
|
0c33d2fd9ae4
(desktop-save): Ensure parameter is expanded and ends with a slash before
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1157 (setq desktop-first-buffer result))
|
50507
|
1158 (set-buffer result)
|
|
1159 (unless (equal (buffer-name) desktop-buffer-name)
|
79237
|
1160 (rename-buffer desktop-buffer-name t))
|
50507
|
1161 ;; minor modes
|
57038
|
1162 (cond ((equal '(t) desktop-buffer-minor-modes) ; backwards compatible
|
|
1163 (auto-fill-mode 1))
|
|
1164 ((equal '(nil) desktop-buffer-minor-modes) ; backwards compatible
|
|
1165 (auto-fill-mode 0))
|
|
1166 (t
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1167 (dolist (minor-mode desktop-buffer-minor-modes)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1168 ;; Give minor mode module a chance to add a handler.
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1169 (desktop-load-file minor-mode)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1170 (let ((handler (cdr (assq minor-mode desktop-minor-mode-handlers))))
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1171 (if handler
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1172 (funcall handler desktop-buffer-locals)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1173 (when (functionp minor-mode)
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1174 (funcall minor-mode 1)))))))
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1175 ;; Even though point and mark are non-nil when written by
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1176 ;; `desktop-save', they may be modified by handlers wanting to set
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1177 ;; point or mark themselves.
|
55059
|
1178 (when desktop-buffer-point
|
|
1179 (goto-char
|
|
1180 (condition-case err
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1181 ;; Evaluate point. Thus point can be something like
|
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1182 ;; '(search-forward ...
|
55059
|
1183 (eval desktop-buffer-point)
|
|
1184 (error (message "%s" (error-message-string err)) 1))))
|
50507
|
1185 (when desktop-buffer-mark
|
|
1186 (if (consp desktop-buffer-mark)
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1187 (progn
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1188 (set-mark (car desktop-buffer-mark))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1189 (setq mark-active (car (cdr desktop-buffer-mark))))
|
50507
|
1190 (set-mark desktop-buffer-mark)))
|
|
1191 ;; Never override file system if the file really is read-only marked.
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1192 (when desktop-buffer-read-only (setq buffer-read-only desktop-buffer-read-only))
|
50507
|
1193 (while desktop-buffer-locals
|
|
1194 (let ((this (car desktop-buffer-locals)))
|
|
1195 (if (consp this)
|
78046
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1196 ;; an entry of this form `(symbol . value)'
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1197 (progn
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1198 (make-local-variable (car this))
|
c395c022a035
(desktop-read): Run `desktop-not-loaded-hook' in the directory where the desktop
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1199 (set (car this) (cdr this)))
|
50507
|
1200 ;; an entry of the form `symbol'
|
|
1201 (make-local-variable this)
|
|
1202 (makunbound this)))
|
|
1203 (setq desktop-buffer-locals (cdr desktop-buffer-locals)))))))
|
5465
|
1204
|
50507
|
1205 ;; ----------------------------------------------------------------------------
|
5465
|
1206 ;; Backward compatibility -- update parameters to 205 standards.
|
14755
|
1207 (defun desktop-buffer (desktop-buffer-file-name desktop-buffer-name
|
|
1208 desktop-buffer-major-mode
|
14756
|
1209 mim pt mk ro tl fc cfs cr desktop-buffer-misc)
|
14755
|
1210 (desktop-create-buffer 205 desktop-buffer-file-name desktop-buffer-name
|
14756
|
1211 desktop-buffer-major-mode (cdr mim) pt mk ro
|
|
1212 desktop-buffer-misc
|
5465
|
1213 (list (cons 'truncate-lines tl)
|
|
1214 (cons 'fill-column fc)
|
|
1215 (cons 'case-fold-search cfs)
|
|
1216 (cons 'case-replace cr)
|
|
1217 (cons 'overwrite-mode (car mim)))))
|
50532
4737239e4dad
(desktop-buffer-file): Restore major-mode if it is different from the normal
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1218
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1219 (defun desktop-append-buffer-args (&rest args)
|
64490
e22e42dbaf76
(desktop-enable, desktop-buffer-modes-to-save, (desktop-buffer-misc-functions,
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
1220 "Append ARGS at end of `desktop-buffer-args-list'.
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1221 ARGS must be an argument list for `desktop-create-buffer'."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1222 (setq desktop-buffer-args-list (nconc desktop-buffer-args-list (list args)))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1223 (unless desktop-lazy-timer
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1224 (setq desktop-lazy-timer
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1225 (run-with-idle-timer desktop-lazy-idle-delay t 'desktop-idle-create-buffers))))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1226
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1227 (defun desktop-lazy-create-buffer ()
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1228 "Pop args from `desktop-buffer-args-list', create buffer and bury it."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1229 (when desktop-buffer-args-list
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1230 (let* ((remaining (length desktop-buffer-args-list))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1231 (args (pop desktop-buffer-args-list))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1232 (buffer-name (nth 2 args))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1233 (msg (format "Desktop lazily opening %s (%s remaining)..."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1234 buffer-name remaining)))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1235 (when desktop-lazy-verbose
|
65582
|
1236 (message "%s" msg))
|
59412
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1237 (let ((desktop-first-buffer nil)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1238 (desktop-buffer-ok-count 0)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1239 (desktop-buffer-fail-count 0))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1240 (apply 'desktop-create-buffer args)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1241 (run-hooks 'desktop-delay-hook)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1242 (setq desktop-delay-hook nil)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1243 (bury-buffer (get-buffer buffer-name))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1244 (when desktop-lazy-verbose
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1245 (message "%s%s" msg (if (> desktop-buffer-ok-count 0) "done" "failed")))))))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1246
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1247 (defun desktop-idle-create-buffers ()
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1248 "Create buffers until the user does something, then stop.
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1249 If there are no buffers left to create, kill the timer."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1250 (let ((repeat 1))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1251 (while (and repeat desktop-buffer-args-list)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1252 (save-window-excursion
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1253 (desktop-lazy-create-buffer))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1254 (setq repeat (sit-for 0.2))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1255 (unless desktop-buffer-args-list
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1256 (cancel-timer desktop-lazy-timer)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1257 (setq desktop-lazy-timer nil)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1258 (message "Lazy desktop load complete")
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1259 (sit-for 3)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1260 (message "")))))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1261
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1262 (defun desktop-lazy-complete ()
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1263 "Run the desktop load to completion."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1264 (interactive)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1265 (let ((desktop-lazy-verbose t))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1266 (while desktop-buffer-args-list
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1267 (save-window-excursion
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1268 (desktop-lazy-create-buffer)))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1269 (message "Lazy desktop load complete")))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1270
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1271 (defun desktop-lazy-abort ()
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1272 "Abort lazy loading of the desktop."
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1273 (interactive)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1274 (when desktop-lazy-timer
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1275 (cancel-timer desktop-lazy-timer)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1276 (setq desktop-lazy-timer nil))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1277 (when desktop-buffer-args-list
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1278 (setq desktop-buffer-args-list nil)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1279 (when (interactive-p)
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1280 (message "Lazy desktop load aborted"))))
|
0ddd142616f1
(desktop-restore-eager, desktop-lazy-verbose, desktop-lazy-idle-delay):
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1281
|
4830
|
1282 ;; ----------------------------------------------------------------------------
|
52674
|
1283 ;; When `desktop-save-mode' is non-nil and "--no-desktop" is not specified on the
|
50507
|
1284 ;; command line, we do the rest of what it takes to use desktop, but do it
|
|
1285 ;; after finishing loading the init file.
|
|
1286 ;; We cannot use `command-switch-alist' to process "--no-desktop" because these
|
|
1287 ;; functions are processed after `after-init-hook'.
|
|
1288 (add-hook
|
|
1289 'after-init-hook
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1290 (lambda ()
|
50507
|
1291 (let ((key "--no-desktop"))
|
61638
|
1292 (when (member key command-line-args)
|
|
1293 (setq command-line-args (delete key command-line-args))
|
|
1294 (setq desktop-save-mode nil)))
|
91810
|
1295 (when desktop-save-mode
|
|
1296 (desktop-read)
|
|
1297 (setq inhibit-startup-screen t))))
|
20526
|
1298
|
3405
|
1299 (provide 'desktop)
|
3404
|
1300
|
77115
7596f1771948
(desktop-save, desktop-create-buffer): Replace mapcar with dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1301 ;; arch-tag: 221907c3-1771-4fd3-9c2e-c6f700c6ede9
|
32366
|
1302 ;;; desktop.el ends here
|