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