0
|
1 ;;; desktop.el --- save partial status of Emacs when killed
|
|
2
|
|
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Morten Welinder <terra@diku.dk>
|
|
6 ;; Version: 2.09? RMS has an obnoxious tendency to remove version
|
|
7 ;; numbers from packages, and he did in this case.
|
|
8 ;; Keywords: customization
|
|
9 ;; Favourite-brand-of-beer: None, I hate beer.
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
26 ;; 02111-1307, USA.
|
0
|
27
|
2
|
28 ;;; Synched up with: FSF 19.34.
|
0
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; Save the Desktop, i.e.,
|
|
33 ;; - some global variables
|
|
34 ;; - the list of buffers with associated files. For each buffer also
|
|
35 ;; - the major mode
|
|
36 ;; - the default directory
|
|
37 ;; - the point
|
|
38 ;; - the mark & mark-active
|
|
39 ;; - buffer-read-only
|
|
40 ;; - some local variables
|
|
41
|
|
42 ;; To use this, first put these three lines in the bottom of your .emacs
|
|
43 ;; file (the later the better):
|
|
44 ;;
|
|
45 ;; (load "desktop")
|
|
46 ;; (desktop-load-default)
|
|
47 ;; (desktop-read)
|
|
48 ;;
|
|
49 ;; Between the second and the third line you may wish to add something that
|
|
50 ;; updates the variables `desktop-globals-to-save' and/or
|
|
51 ;; `desktop-locals-to-save'. If for instance you want to save the local
|
|
52 ;; variable `foobar' for every buffer in which it is local, you could add
|
|
53 ;; the line
|
|
54 ;;
|
|
55 ;; (setq desktop-locals-to-save (cons 'foobar desktop-locals-to-save))
|
|
56 ;;
|
|
57 ;; To avoid saving excessive amounts of data you may also wish to add
|
|
58 ;; something like the following
|
|
59 ;;
|
|
60 ;; (add-hook 'kill-emacs-hook
|
|
61 ;; '(lambda ()
|
|
62 ;; (desktop-truncate search-ring 3)
|
|
63 ;; (desktop-truncate regexp-search-ring 3)))
|
|
64 ;;
|
|
65 ;; which will make sure that no more than three search items are saved. You
|
|
66 ;; must place this line *after* the (load "desktop") line. See also the
|
|
67 ;; variable desktop-save-hook.
|
|
68
|
|
69 ;; Start Emacs in the root directory of your "project". The desktop saver
|
|
70 ;; is inactive by default. You activate it by M-x desktop-save RET. When
|
|
71 ;; you exit the next time the above data will be saved. This ensures that
|
|
72 ;; all the files you were editing will be reloaded the next time you start
|
|
73 ;; Emacs from the same directory and that points will be set where you
|
|
74 ;; left them. If you save a desktop file in your home directory it will
|
|
75 ;; act as a default desktop when you start Emacs from a directory that
|
|
76 ;; doesn't have its own. I never do this, but you may want to.
|
|
77
|
|
78 ;; By the way: don't use desktop.el to customize Emacs -- the file .emacs
|
|
79 ;; in your home directory is used for that. Saving global default values
|
|
80 ;; for buffers is an example of misuse.
|
|
81
|
|
82 ;; PLEASE NOTE: The kill ring can be saved as specified by the variable
|
|
83 ;; `desktop-globals-to-save' (by default it isn't). This may result in saving
|
|
84 ;; things you did not mean to keep. Use M-x desktop-clear RET.
|
|
85
|
|
86 ;; Thanks to hetrick@phys.uva.nl (Jim Hetrick) for useful ideas.
|
|
87 ;; avk@rtsg.mot.com (Andrew V. Klein) for a dired tip.
|
|
88 ;; chris@tecc.co.uk (Chris Boucher) for a mark tip.
|
|
89 ;; f89-kam@nada.kth.se (Klas Mellbourn) for a mh-e tip.
|
|
90 ;; kifer@sbkifer.cs.sunysb.edu (M. Kifer) for a bug hunt.
|
|
91 ;; treese@lcs.mit.edu (Win Treese) for ange-ftp tips.
|
2
|
92 ;; pot@cnuce.cnr.it (Francesco Potorti`) for misc. tips.
|
0
|
93 ;; ---------------------------------------------------------------------------
|
|
94 ;; TODO:
|
|
95 ;;
|
|
96 ;; Save window configuration.
|
|
97 ;; Recognize more minor modes.
|
|
98 ;; Save mark rings.
|
|
99 ;; Start-up with buffer-menu???
|
|
100
|
|
101 ;;; Code:
|
|
102
|
|
103 ;; Make the compilation more silent
|
|
104 (eval-when-compile
|
|
105 ;; We use functions from these modules
|
|
106 ;; We can't (require 'mh-e) since that wants to load something.
|
209
|
107 (require 'info))
|
0
|
108 ;; ----------------------------------------------------------------------------
|
|
109 ;; USER OPTIONS -- settings you might want to play with.
|
|
110 ;; ----------------------------------------------------------------------------
|
134
|
111
|
|
112 (defgroup desktop nil
|
|
113 "Save partial status of Emacs when killed"
|
|
114 :group 'frames)
|
|
115
|
0
|
116 (defconst desktop-basefilename
|
|
117 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
|
|
118 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name
|
|
119 ".emacs.desktop")
|
|
120 "File for Emacs desktop, not including the directory name.")
|
|
121
|
134
|
122 (defcustom desktop-missing-file-warning t
|
0
|
123 "*If non-nil then desktop warns when a file no longer exists.
|
134
|
124 Otherwise it simply ignores that file."
|
|
125 :type 'boolean
|
|
126 :group 'desktop)
|
0
|
127
|
134
|
128 (defcustom desktop-globals-to-save
|
0
|
129 (list 'desktop-missing-file-warning
|
|
130 ;; Feature: saving kill-ring implies saving kill-ring-yank-pointer
|
|
131 ;; 'kill-ring
|
|
132 'tags-file-name
|
|
133 'tags-table-list
|
|
134 'search-ring
|
|
135 'regexp-search-ring
|
|
136 'register-alist
|
|
137 ;; 'desktop-globals-to-save ; Itself!
|
|
138 )
|
|
139 "List of global variables to save when killing Emacs.
|
|
140 An element may be variable name (a symbol)
|
|
141 or a cons cell of the form (VAR . MAX-SIZE),
|
|
142 which means to truncate VAR's value to at most MAX-SIZE elements
|
134
|
143 \(if the value is a list) before saving the value."
|
|
144 :type '(repeat (choice (symbol :tag "Variable")
|
|
145 (cons (symbol :tag "Variable")
|
|
146 (integer :tag "Size"))))
|
|
147 :group 'desktop)
|
0
|
148
|
134
|
149 (defcustom desktop-locals-to-save
|
0
|
150 (list 'desktop-locals-to-save ; Itself! Think it over.
|
|
151 'truncate-lines
|
|
152 'case-fold-search
|
|
153 'case-replace
|
|
154 'fill-column
|
|
155 'overwrite-mode
|
|
156 'change-log-default-name
|
|
157 'line-number-mode
|
|
158 )
|
|
159 "List of local variables to save for each buffer.
|
134
|
160 The variables are saved only when they really are local."
|
|
161 :type '(repeat (choice (symbol :tag "Variable")
|
|
162 (cons (symbol :tag "Variable")
|
|
163 (integer :tag "Size"))))
|
|
164 :group 'desktop)
|
0
|
165 (make-variable-buffer-local 'desktop-locals-to-save)
|
|
166
|
|
167 ;; We skip .log files because they are normally temporary.
|
2
|
168 ;; (ftp) files because they require passwords and whatnot.
|
0
|
169 ;; TAGS files to save time (tags-file-name is saved instead).
|
134
|
170 (defcustom desktop-buffers-not-to-save
|
0
|
171 "\\(^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\|^tags\\|^TAGS\\)$"
|
134
|
172 "Regexp identifying buffers that are to be excluded from saving."
|
|
173 :type 'regexp
|
|
174 :group 'desktop)
|
0
|
175
|
|
176 ;; Skip ange-ftp files
|
134
|
177 (defcustom desktop-files-not-to-save
|
0
|
178 "^/[^/:]*:"
|
134
|
179 "Regexp identifying files whose buffers are to be excluded from saving."
|
|
180 :type 'regexp
|
|
181 :group 'desktop)
|
0
|
182
|
2
|
183 (defvar desktop-buffer-major-mode nil
|
|
184 "When desktop creates a buffer, this holds the desired Major mode.")
|
|
185
|
|
186 (defvar desktop-buffer-file-name nil
|
|
187 "When desktop creates a buffer, this holds the file name to visit.")
|
|
188
|
|
189 (defvar desktop-buffer-name nil
|
|
190 "When desktop creates a buffer, this holds the desired buffer name.")
|
|
191
|
|
192 (defvar desktop-buffer-misc nil
|
|
193 "When desktop creates a buffer, this holds a list of misc info.
|
|
194 It is used by the `desktop-buffer-handlers' functions.")
|
|
195
|
134
|
196 (defcustom desktop-buffer-handlers
|
0
|
197 '(desktop-buffer-dired
|
|
198 desktop-buffer-rmail
|
|
199 desktop-buffer-mh
|
|
200 desktop-buffer-info
|
|
201 desktop-buffer-file)
|
|
202 "*List of functions to call in order to create a buffer.
|
2
|
203 The functions are called without explicit parameters but can use the
|
|
204 variables `desktop-buffer-major-mode', `desktop-buffer-file-name',
|
|
205 `desktop-buffer-name'.
|
|
206 If one function returns non-nil, no further functions are called.
|
134
|
207 If the function returns t then the buffer is considered created."
|
|
208 :type '(repeat function)
|
|
209 :group 'desktop)
|
0
|
210
|
|
211 (defvar desktop-create-buffer-form "(desktop-create-buffer 205"
|
|
212 "Opening of form for creation of new buffers.")
|
|
213
|
134
|
214 (defcustom desktop-save-hook nil
|
0
|
215 "Hook run before saving the desktop to allow you to cut history lists and
|
134
|
216 the like shorter."
|
|
217 :type 'hook
|
|
218 :group 'desktop)
|
0
|
219 ;; ----------------------------------------------------------------------------
|
|
220 (defvar desktop-dirname nil
|
|
221 "The directory in which the current desktop file resides.")
|
|
222
|
|
223 (defconst desktop-header
|
|
224 ";; --------------------------------------------------------------------------
|
|
225 ;; Desktop File for Emacs
|
|
226 ;; --------------------------------------------------------------------------
|
|
227 " "*Header to place in Desktop file.")
|
|
228
|
|
229 (defvar desktop-delay-hook nil
|
|
230 "Hooks run after all buffers are loaded; intended for internal use.")
|
|
231 ;; ----------------------------------------------------------------------------
|
|
232 (defun desktop-truncate (l n)
|
|
233 "Truncate LIST to at most N elements destructively."
|
|
234 (let ((here (nthcdr (1- n) l)))
|
|
235 (if (consp here)
|
|
236 (setcdr here nil))))
|
|
237 ;; ----------------------------------------------------------------------------
|
|
238 (defun desktop-clear () "Empty the Desktop."
|
|
239 (interactive)
|
|
240 (setq kill-ring nil
|
|
241 kill-ring-yank-pointer nil
|
|
242 search-ring nil
|
|
243 search-ring-yank-pointer nil
|
|
244 regexp-search-ring nil
|
|
245 regexp-search-ring-yank-pointer nil)
|
|
246 (mapcar (function (lambda (x)
|
|
247 ;; XEmacs change
|
|
248 (if (not (equal (buffer-name x) "*Warnings*"))
|
|
249 (kill-buffer x)))) (buffer-list))
|
|
250 (delete-other-windows))
|
|
251 ;; ----------------------------------------------------------------------------
|
|
252 (add-hook 'kill-emacs-hook 'desktop-kill)
|
|
253
|
|
254 (defun desktop-kill ()
|
|
255 (if desktop-dirname
|
|
256 (condition-case err
|
|
257 (desktop-save desktop-dirname)
|
|
258 (file-error
|
|
259 (if (yes-or-no-p "Error while saving the desktop. Quit anyway? ")
|
|
260 nil
|
|
261 (signal (car err) (cdr err)))))))
|
|
262 ;; ----------------------------------------------------------------------------
|
2
|
263 (defun desktop-list* (&rest args)
|
|
264 (if (null (cdr args))
|
|
265 (car args)
|
|
266 (setq args (nreverse args))
|
|
267 (let ((value (cons (nth 1 args) (car args))))
|
|
268 (setq args (cdr (cdr args)))
|
|
269 (while args
|
|
270 (setq value (cons (car args) value))
|
|
271 (setq args (cdr args)))
|
|
272 value)))
|
|
273
|
0
|
274 (defun desktop-internal-v2s (val)
|
|
275 "Convert VALUE to a pair (QUOTE . TXT); (eval (read TXT)) gives VALUE.
|
|
276 TXT is a string that when read and evaluated yields value.
|
|
277 QUOTE may be `may' (value may be quoted),
|
|
278 `must' (values must be quoted), or nil (value may not be quoted)."
|
|
279 (cond
|
|
280 ((or (numberp val) (null val) (eq t val))
|
|
281 (cons 'may (prin1-to-string val)))
|
|
282 ((stringp val)
|
|
283 (let ((copy (copy-sequence val)))
|
|
284 (set-text-properties 0 (length copy) nil copy)
|
|
285 ;; Get rid of text properties because we cannot read them
|
|
286 (cons 'may (prin1-to-string copy))))
|
|
287 ((symbolp val)
|
|
288 (cons 'must (prin1-to-string val)))
|
|
289 ((vectorp val)
|
|
290 (let* ((special nil)
|
|
291 (pass1 (mapcar
|
|
292 (lambda (el)
|
|
293 (let ((res (desktop-internal-v2s el)))
|
|
294 (if (null (car res))
|
|
295 (setq special t))
|
|
296 res))
|
|
297 val)))
|
|
298 (if special
|
|
299 (cons nil (concat "(vector "
|
|
300 (mapconcat (lambda (el)
|
|
301 (if (eq (car el) 'must)
|
|
302 (concat "'" (cdr el))
|
|
303 (cdr el)))
|
|
304 pass1
|
|
305 " ")
|
|
306 ")"))
|
|
307 (cons 'may (concat "[" (mapconcat 'cdr pass1 " ") "]")))))
|
|
308 ((consp val)
|
|
309 (let ((p val)
|
|
310 newlist
|
2
|
311 use-list*
|
0
|
312 anynil)
|
|
313 (while (consp p)
|
|
314 (let ((q.txt (desktop-internal-v2s (car p))))
|
|
315 (or anynil (setq anynil (null (car q.txt))))
|
|
316 (setq newlist (cons q.txt newlist)))
|
|
317 (setq p (cdr p)))
|
|
318 (if p
|
|
319 (let ((last (desktop-internal-v2s p))
|
|
320 (el (car newlist)))
|
2
|
321 (or anynil (setq anynil (null (car last))))
|
|
322 (or anynil
|
|
323 (setq newlist (cons '(must . ".") newlist)))
|
|
324 (setq use-list* t)
|
|
325 (setq newlist (cons last newlist))))
|
0
|
326 (setq newlist (nreverse newlist))
|
|
327 (if anynil
|
|
328 (cons nil
|
2
|
329 (concat (if use-list* "(desktop-list* " "(list ")
|
0
|
330 (mapconcat (lambda (el)
|
|
331 (if (eq (car el) 'must)
|
|
332 (concat "'" (cdr el))
|
|
333 (cdr el)))
|
|
334 newlist
|
|
335 " ")
|
|
336 ")"))
|
|
337 (cons 'must
|
|
338 (concat "(" (mapconcat 'cdr newlist " ") ")")))))
|
|
339 ((subrp val)
|
|
340 (cons nil (concat "(symbol-function '"
|
|
341 (substring (prin1-to-string val) 7 -1)
|
|
342 ")")))
|
|
343 ((markerp val)
|
|
344 (let ((pos (prin1-to-string (marker-position val)))
|
|
345 (buf (prin1-to-string (buffer-name (marker-buffer val)))))
|
|
346 (cons nil (concat "(let ((mk (make-marker)))"
|
|
347 " (add-hook 'desktop-delay-hook"
|
|
348 " (list 'lambda '() (list 'set-marker mk "
|
|
349 pos " (get-buffer " buf ")))) mk)"))))
|
|
350 (t ; save as text
|
|
351 (cons 'may "\"Unprintable entity\""))))
|
|
352
|
|
353 (defun desktop-value-to-string (val)
|
|
354 "Convert VALUE to a string that when read evaluates to the same value.
|
|
355 Not all types of values are supported."
|
|
356 (let* ((print-escape-newlines t)
|
|
357 (float-output-format nil)
|
|
358 (quote.txt (desktop-internal-v2s val))
|
|
359 (quote (car quote.txt))
|
|
360 (txt (cdr quote.txt)))
|
|
361 (if (eq quote 'must)
|
|
362 (concat "'" txt)
|
|
363 txt)))
|
|
364 ;; ----------------------------------------------------------------------------
|
|
365 (defun desktop-outvar (varspec)
|
|
366 "Output a setq statement for variable VAR to the desktop file.
|
|
367 The argument VARSPEC may be the variable name VAR (a symbol),
|
|
368 or a cons cell of the form (VAR . MAX-SIZE),
|
|
369 which means to truncate VAR's value to at most MAX-SIZE elements
|
|
370 \(if the value is a list) before saving the value."
|
|
371 (let (var size)
|
|
372 (if (consp varspec)
|
|
373 (setq var (car varspec) size (cdr varspec))
|
|
374 (setq var varspec))
|
|
375 (if (boundp var)
|
|
376 (progn
|
|
377 (if (and (integerp size)
|
|
378 (> size 0)
|
|
379 (listp (eval var)))
|
|
380 (desktop-truncate (eval var) size))
|
|
381 (insert "(setq "
|
|
382 (symbol-name var)
|
|
383 " "
|
|
384 (desktop-value-to-string (symbol-value var))
|
|
385 ")\n")))))
|
|
386 ;; ----------------------------------------------------------------------------
|
|
387 (defun desktop-save-buffer-p (filename bufname mode &rest dummy)
|
|
388 "Return t if the desktop should record a particular buffer for next startup.
|
|
389 FILENAME is the visited file name, BUFNAME is the buffer name, and
|
|
390 MODE is the major mode."
|
|
391 (let ((case-fold-search nil))
|
|
392 (or (and filename
|
|
393 (not (string-match desktop-buffers-not-to-save bufname))
|
|
394 (not (string-match desktop-files-not-to-save filename)))
|
|
395 (and (eq mode 'dired-mode)
|
|
396 (save-excursion
|
|
397 (set-buffer (get-buffer bufname))
|
|
398 (not (string-match desktop-files-not-to-save
|
|
399 default-directory))))
|
|
400 (and (null filename)
|
|
401 (memq mode '(Info-mode rmail-mode))))))
|
|
402 ;; ----------------------------------------------------------------------------
|
|
403 (defun desktop-save (dirname)
|
|
404 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop."
|
|
405 (interactive "DDirectory to save desktop file in: ")
|
|
406 (run-hooks 'desktop-save-hook)
|
|
407 (save-excursion
|
|
408 (let ((filename (expand-file-name
|
|
409 (concat dirname desktop-basefilename)))
|
|
410 (info (nreverse
|
|
411 (mapcar
|
|
412 (function (lambda (b)
|
|
413 (set-buffer b)
|
|
414 (list
|
|
415 (buffer-file-name)
|
|
416 (buffer-name)
|
|
417 major-mode
|
|
418 (list ; list explaining minor modes
|
|
419 (not (null auto-fill-function)))
|
|
420 (point)
|
|
421 (list (mark t) ;; mark-active
|
|
422 (not (null (mark)))) ; XEmacs
|
|
423 buffer-read-only
|
|
424 (cond ((eq major-mode 'Info-mode)
|
|
425 (list Info-current-file
|
|
426 Info-current-node))
|
|
427 ((eq major-mode 'dired-mode)
|
|
428 (cons
|
|
429 (expand-file-name dired-directory)
|
|
430 (cdr
|
|
431 (nreverse
|
|
432 (mapcar
|
|
433 (function car)
|
|
434 dired-subdir-alist))))))
|
|
435 (let ((locals desktop-locals-to-save)
|
|
436 (loclist (buffer-local-variables))
|
|
437 (ll))
|
|
438 (while locals
|
|
439 (let ((here (assq (car locals) loclist)))
|
|
440 (if here
|
|
441 (setq ll (cons here ll))
|
|
442 (if (member (car locals) loclist)
|
|
443 (setq ll (cons (car locals) ll)))))
|
|
444 (setq locals (cdr locals)))
|
|
445 ll)
|
|
446 )))
|
|
447 (buffer-list))))
|
|
448 (buf (get-buffer-create "*desktop*")))
|
|
449 (set-buffer buf)
|
|
450 (erase-buffer)
|
|
451
|
|
452 (insert desktop-header
|
|
453 ";; Created " (current-time-string) "\n"
|
|
454 ";; Emacs version " emacs-version "\n\n"
|
|
455 ";; Global section:\n")
|
|
456 (mapcar (function desktop-outvar) desktop-globals-to-save)
|
|
457 (if (memq 'kill-ring desktop-globals-to-save)
|
|
458 (insert "(setq kill-ring-yank-pointer (nthcdr "
|
|
459 (int-to-string
|
|
460 (- (length kill-ring) (length kill-ring-yank-pointer)))
|
|
461 " kill-ring))\n"))
|
|
462
|
|
463 (insert "\n;; Buffer section:\n")
|
|
464 (mapcar
|
|
465 (function (lambda (l)
|
|
466 (if (apply 'desktop-save-buffer-p l)
|
|
467 (progn
|
|
468 (insert desktop-create-buffer-form)
|
|
469 (mapcar
|
|
470 (function (lambda (e)
|
|
471 (insert "\n "
|
|
472 (desktop-value-to-string e))))
|
|
473 l)
|
|
474 (insert ")\n\n")))))
|
|
475 info)
|
|
476 (setq default-directory dirname)
|
|
477 (if (file-exists-p filename) (delete-file filename))
|
|
478 (write-region (point-min) (point-max) filename nil 'nomessage)))
|
|
479 (setq desktop-dirname dirname))
|
|
480 ;; ----------------------------------------------------------------------------
|
|
481 (defun desktop-remove ()
|
|
482 "Delete the Desktop file and inactivate the desktop system."
|
|
483 (interactive)
|
|
484 (if desktop-dirname
|
|
485 (let ((filename (concat desktop-dirname desktop-basefilename)))
|
|
486 (setq desktop-dirname nil)
|
|
487 (if (file-exists-p filename)
|
|
488 (delete-file filename)))))
|
|
489 ;; ----------------------------------------------------------------------------
|
|
490 (defun desktop-read ()
|
2
|
491 "Read the Desktop file and the files it specifies.
|
|
492 This is a no-op when Emacs is running in batch mode."
|
0
|
493 (interactive)
|
2
|
494 (if noninteractive
|
|
495 nil
|
|
496 (let ((dirs '("./" "~/")))
|
|
497 (while (and dirs
|
|
498 (not (file-exists-p (expand-file-name
|
|
499 desktop-basefilename
|
|
500 (car dirs)))))
|
|
501 (setq dirs (cdr dirs)))
|
|
502 (setq desktop-dirname (and dirs (expand-file-name (car dirs))))
|
|
503 (if desktop-dirname
|
|
504 (progn
|
|
505 (load (expand-file-name desktop-basefilename desktop-dirname)
|
|
506 t t t)
|
|
507 (run-hooks 'desktop-delay-hook)
|
|
508 (setq desktop-delay-hook nil)
|
|
509 (message "Desktop loaded."))
|
|
510 (desktop-clear)))))
|
0
|
511 ;; ----------------------------------------------------------------------------
|
|
512 (defun desktop-load-default ()
|
|
513 "Load the `default' start-up library manually.
|
|
514 Also inhibit further loading of it. Call this from your `.emacs' file
|
|
515 to provide correct modes for autoloaded files."
|
|
516 (if (not inhibit-default-init) ; safety check
|
|
517 (progn
|
|
518 (load "default" t t)
|
|
519 (setq inhibit-default-init t))))
|
|
520 ;; ----------------------------------------------------------------------------
|
|
521 ;; Note: the following functions use the dynamic variable binding in Lisp.
|
|
522 ;;
|
|
523 (defun desktop-buffer-info () "Load an info file."
|
2
|
524 (if (eq 'Info-mode desktop-buffer-major-mode)
|
0
|
525 (progn
|
|
526 (require 'info)
|
2
|
527 (Info-find-node (nth 0 desktop-buffer-misc)
|
|
528 (nth 1 desktop-buffer-misc))
|
0
|
529 t)))
|
|
530 ;; ----------------------------------------------------------------------------
|
|
531 (defun desktop-buffer-rmail () "Load an RMAIL file."
|
2
|
532 (if (eq 'rmail-mode desktop-buffer-major-mode)
|
0
|
533 (condition-case error
|
2
|
534 (progn (rmail-input desktop-buffer-file-name) t)
|
0
|
535 (file-locked
|
|
536 (kill-buffer (current-buffer))
|
|
537 'ignored))))
|
|
538 ;; ----------------------------------------------------------------------------
|
|
539 (defun desktop-buffer-mh () "Load a folder in the mh system."
|
2
|
540 (if (eq 'mh-folder-mode desktop-buffer-major-mode)
|
0
|
541 (progn
|
|
542 (require 'mh-e)
|
|
543 (mh-find-path)
|
2
|
544 (mh-visit-folder desktop-buffer-name)
|
0
|
545 t)))
|
|
546 ;; ----------------------------------------------------------------------------
|
|
547 (defun desktop-buffer-dired () "Load a directory using dired."
|
2
|
548 (if (eq 'dired-mode desktop-buffer-major-mode)
|
|
549 (if (file-directory-p (file-name-directory (car desktop-buffer-misc)))
|
0
|
550 (progn
|
2
|
551 (dired (car desktop-buffer-misc))
|
|
552 (mapcar 'dired-insert-subdir (cdr desktop-buffer-misc))
|
0
|
553 t)
|
2
|
554 (message "Directory %s no longer exists." (car desktop-buffer-misc))
|
0
|
555 (sit-for 1)
|
|
556 'ignored)))
|
|
557 ;; ----------------------------------------------------------------------------
|
|
558 (defun desktop-buffer-file () "Load a file."
|
2
|
559 (if desktop-buffer-file-name
|
|
560 (if (or (file-exists-p desktop-buffer-file-name)
|
0
|
561 (and desktop-missing-file-warning
|
|
562 (y-or-n-p (format
|
|
563 "File \"%s\" no longer exists. Re-create? "
|
2
|
564 desktop-buffer-file-name))))
|
|
565 (progn (find-file desktop-buffer-file-name) t)
|
0
|
566 'ignored)))
|
|
567 ;; ----------------------------------------------------------------------------
|
|
568 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file
|
|
569 ;; only.
|
2
|
570 (defun desktop-create-buffer (ver desktop-buffer-file-name desktop-buffer-name
|
|
571 desktop-buffer-major-mode
|
|
572 mim pt mk ro desktop-buffer-misc
|
|
573 &optional locals)
|
0
|
574 (let ((hlist desktop-buffer-handlers)
|
|
575 (result)
|
|
576 (handler))
|
|
577 (while (and (not result) hlist)
|
|
578 (setq handler (car hlist))
|
|
579 (setq result (funcall handler))
|
|
580 (setq hlist (cdr hlist)))
|
|
581 (if (eq result t)
|
|
582 (progn
|
2
|
583 (if (not (equal (buffer-name) desktop-buffer-name))
|
|
584 (rename-buffer desktop-buffer-name))
|
0
|
585 (auto-fill-mode (if (nth 0 mim) 1 0))
|
|
586 (goto-char pt)
|
|
587 (if (consp mk)
|
|
588 (progn
|
|
589 (set-mark (car mk))
|
|
590 ;; (setq mark-active (car (cdr mk))))
|
|
591 (if (car (cdr mk)) (zmacs-activate-region))) ; XEmacs
|
|
592 (set-mark mk))
|
|
593 ;; Never override file system if the file really is read-only marked.
|
|
594 (if ro (setq buffer-read-only ro))
|
|
595 (while locals
|
|
596 (let ((this (car locals)))
|
|
597 (if (consp this)
|
|
598 ;; an entry of this form `(symbol . value)'
|
|
599 (progn
|
|
600 (make-local-variable (car this))
|
|
601 (set (car this) (cdr this)))
|
|
602 ;; an entry of the form `symbol'
|
|
603 (make-local-variable this)
|
|
604 (makunbound this)))
|
|
605 (setq locals (cdr locals)))
|
|
606 ))))
|
|
607
|
|
608 ;; Backward compatibility -- update parameters to 205 standards.
|
2
|
609 (defun desktop-buffer (desktop-buffer-file-name desktop-buffer-name
|
|
610 desktop-buffer-major-mode
|
|
611 mim pt mk ro tl fc cfs cr
|
|
612 desktop-buffer-misc)
|
|
613 (desktop-create-buffer 205 desktop-buffer-file-name desktop-buffer-name
|
|
614 desktop-buffer-major-mode (cdr mim) pt mk ro
|
|
615 desktop-buffer-misc
|
0
|
616 (list (cons 'truncate-lines tl)
|
|
617 (cons 'fill-column fc)
|
|
618 (cons 'case-fold-search cfs)
|
|
619 (cons 'case-replace cr)
|
|
620 (cons 'overwrite-mode (car mim)))))
|
|
621 ;; ----------------------------------------------------------------------------
|
|
622 (provide 'desktop)
|
|
623
|
|
624 ;; desktop.el ends here.
|