(desktop-modes-not-to-save): New var.
[emacs.git] / lisp / desktop.el
blob8c55edb3bd739decf7f7bf2287c68822cb42d103
1 ;;; desktop.el --- save partial status of Emacs when killed
3 ;; Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
5 ;; Author: Morten Welinder <terra@diku.dk>
6 ;; Keywords: convenience
7 ;; Favourite-brand-of-beer: None, I hate beer.
9 ;; This file is part of GNU Emacs.
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.
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.
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.
26 ;;; Commentary:
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
38 ;; To use this, first put these two lines in the bottom of your .emacs
39 ;; file (the later the better):
41 ;; (desktop-load-default)
42 ;; (desktop-read)
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
49 ;; (setq desktop-locals-to-save (cons 'foobar desktop-locals-to-save))
51 ;; To avoid saving excessive amounts of data you may also wish to add
52 ;; something like the following
54 ;; (add-hook 'kill-emacs-hook
55 ;; '(lambda ()
56 ;; (desktop-truncate search-ring 3)
57 ;; (desktop-truncate regexp-search-ring 3)))
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'.
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.
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.
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.
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.
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:
98 ;; Save window configuration.
99 ;; Recognize more minor modes.
100 ;; Save mark rings.
101 ;; Start-up with buffer-menu???
103 ;;; Code:
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 ;; ----------------------------------------------------------------------------
114 (defgroup desktop nil
115 "Save status of Emacs when you exit."
116 :group 'frames)
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")
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)
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)
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!
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.")
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
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)
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)
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)
185 (defcustom desktop-modes-not-to-save nil
186 "List of major modes whose buffers should not be saved."
187 :type '(repeat symbol)
188 :group 'desktop)
190 (defcustom desktop-buffer-major-mode nil
191 "When desktop creates a buffer, this holds the desired Major mode."
192 :type 'symbol
193 :group 'desktop)
195 (defcustom desktop-buffer-file-name nil
196 "When desktop creates a buffer, this holds the file name to visit."
197 :type '(choice file (const nil))
198 :group 'desktop)
200 (defcustom desktop-buffer-name nil
201 "When desktop creates a buffer, this holds the desired buffer name."
202 :type '(choice string (const nil))
203 :group 'desktop)
205 (defvar desktop-buffer-misc nil
206 "When desktop creates a buffer, this holds a list of misc info.
207 It is used by the `desktop-buffer-handlers' functions.")
209 (defcustom desktop-buffer-handlers
210 '(desktop-buffer-dired
211 desktop-buffer-rmail
212 desktop-buffer-mh
213 desktop-buffer-info
214 desktop-buffer-file)
215 "*List of functions to call in order to create a buffer.
216 The functions are called without explicit parameters but can use the
217 variables `desktop-buffer-major-mode', `desktop-buffer-file-name',
218 `desktop-buffer-name'.
219 If one function returns non-nil, no further functions are called.
220 If the function returns t then the buffer is considered created."
221 :type '(repeat function)
222 :group 'desktop)
224 (defvar desktop-create-buffer-form "(desktop-create-buffer 205"
225 "Opening of form for creation of new buffers.")
227 (defcustom desktop-save-hook nil
228 "Hook run before desktop saves the state of Emacs.
229 This is useful for truncating history lists, for example."
230 :type 'hook
231 :group 'desktop)
233 (defcustom desktop-minor-mode-table
234 '((auto-fill-function auto-fill-mode)
235 (vc-mode nil))
236 "Table mapping minor mode variables to minor mode functions.
237 Each entry has the form (NAME RESTORE-FUNCTION).
238 NAME is the name of the buffer-local variable indicating that the minor
239 mode is active. RESTORE-FUNCTION is the function to activate the minor mode.
240 called. RESTORE-FUNCTION nil means don't try to restore the minor mode.
241 Only minor modes for which the name of the buffer-local variable
242 and the name of the minor mode function are different have to added to
243 this table."
244 :type 'sexp
245 :group 'desktop)
247 ;; ----------------------------------------------------------------------------
248 (defvar desktop-dirname nil
249 "The directory in which the current desktop file resides.")
251 (defconst desktop-header
252 ";; --------------------------------------------------------------------------
253 ;; Desktop File for Emacs
254 ;; --------------------------------------------------------------------------
255 " "*Header to place in Desktop file.")
257 (defvar desktop-delay-hook nil
258 "Hooks run after all buffers are loaded; intended for internal use.")
260 ;; ----------------------------------------------------------------------------
261 (defun desktop-truncate (l n)
262 "Truncate LIST to at most N elements destructively."
263 (let ((here (nthcdr (1- n) l)))
264 (if (consp here)
265 (setcdr here nil))))
266 ;; ----------------------------------------------------------------------------
267 (defcustom desktop-clear-preserve-buffers
268 '("*scratch*" "*Messages*")
269 "*Buffer names that `desktop-clear' should not delete."
270 :type '(repeat string)
271 :group 'desktop)
273 (defun desktop-clear ()
274 "Empty the Desktop.
275 This kills all buffers except for internal ones
276 and those listed in `desktop-clear-preserve-buffers'."
277 (interactive)
278 (setq kill-ring nil
279 kill-ring-yank-pointer nil
280 search-ring nil
281 search-ring-yank-pointer nil
282 regexp-search-ring nil
283 regexp-search-ring-yank-pointer nil)
284 (let ((buffers (buffer-list)))
285 (while buffers
286 (or (member (buffer-name (car buffers)) desktop-clear-preserve-buffers)
287 (null (buffer-name (car buffers)))
288 ;; Don't kill buffers made for internal purposes.
289 (and (not (equal (buffer-name (car buffers)) ""))
290 (eq (aref (buffer-name (car buffers)) 0) ?\ ))
291 (kill-buffer (car buffers)))
292 (setq buffers (cdr buffers))))
293 (delete-other-windows))
294 ;; ----------------------------------------------------------------------------
295 (add-hook 'kill-emacs-hook 'desktop-kill)
297 (defun desktop-kill ()
298 (if desktop-dirname
299 (condition-case err
300 (desktop-save desktop-dirname)
301 (file-error
302 (if (yes-or-no-p "Error while saving the desktop. Quit anyway? ")
304 (signal (car err) (cdr err)))))))
305 ;; ----------------------------------------------------------------------------
306 (defun desktop-list* (&rest args)
307 (if (null (cdr args))
308 (car args)
309 (setq args (nreverse args))
310 (let ((value (cons (nth 1 args) (car args))))
311 (setq args (cdr (cdr args)))
312 (while args
313 (setq value (cons (car args) value))
314 (setq args (cdr args)))
315 value)))
317 (defun desktop-internal-v2s (val)
318 "Convert VALUE to a pair (QUOTE . TXT); (eval (read TXT)) gives VALUE.
319 TXT is a string that when read and evaluated yields value.
320 QUOTE may be `may' (value may be quoted),
321 `must' (values must be quoted), or nil (value may not be quoted)."
322 (cond
323 ((or (numberp val) (null val) (eq t val))
324 (cons 'may (prin1-to-string val)))
325 ((stringp val)
326 (let ((copy (copy-sequence val)))
327 (set-text-properties 0 (length copy) nil copy)
328 ;; Get rid of text properties because we cannot read them
329 (cons 'may (prin1-to-string copy))))
330 ((symbolp val)
331 (cons 'must (prin1-to-string val)))
332 ((vectorp val)
333 (let* ((special nil)
334 (pass1 (mapcar
335 (lambda (el)
336 (let ((res (desktop-internal-v2s el)))
337 (if (null (car res))
338 (setq special t))
339 res))
340 val)))
341 (if special
342 (cons nil (concat "(vector "
343 (mapconcat (lambda (el)
344 (if (eq (car el) 'must)
345 (concat "'" (cdr el))
346 (cdr el)))
347 pass1
348 " ")
349 ")"))
350 (cons 'may (concat "[" (mapconcat 'cdr pass1 " ") "]")))))
351 ((consp val)
352 (let ((p val)
353 newlist
354 use-list*
355 anynil)
356 (while (consp p)
357 (let ((q.txt (desktop-internal-v2s (car p))))
358 (or anynil (setq anynil (null (car q.txt))))
359 (setq newlist (cons q.txt newlist)))
360 (setq p (cdr p)))
361 (if p
362 (let ((last (desktop-internal-v2s p))
363 (el (car newlist)))
364 (or anynil (setq anynil (null (car last))))
365 (or anynil
366 (setq newlist (cons '(must . ".") newlist)))
367 (setq use-list* t)
368 (setq newlist (cons last newlist))))
369 (setq newlist (nreverse newlist))
370 (if anynil
371 (cons nil
372 (concat (if use-list* "(desktop-list* " "(list ")
373 (mapconcat (lambda (el)
374 (if (eq (car el) 'must)
375 (concat "'" (cdr el))
376 (cdr el)))
377 newlist
378 " ")
379 ")"))
380 (cons 'must
381 (concat "(" (mapconcat 'cdr newlist " ") ")")))))
382 ((subrp val)
383 (cons nil (concat "(symbol-function '"
384 (substring (prin1-to-string val) 7 -1)
385 ")")))
386 ((markerp val)
387 (let ((pos (prin1-to-string (marker-position val)))
388 (buf (prin1-to-string (buffer-name (marker-buffer val)))))
389 (cons nil (concat "(let ((mk (make-marker)))"
390 " (add-hook 'desktop-delay-hook"
391 " (list 'lambda '() (list 'set-marker mk "
392 pos " (get-buffer " buf ")))) mk)"))))
393 (t ; save as text
394 (cons 'may "\"Unprintable entity\""))))
396 (defun desktop-value-to-string (val)
397 "Convert VALUE to a string that when read evaluates to the same value.
398 Not all types of values are supported."
399 (let* ((print-escape-newlines t)
400 (float-output-format nil)
401 (quote.txt (desktop-internal-v2s val))
402 (quote (car quote.txt))
403 (txt (cdr quote.txt)))
404 (if (eq quote 'must)
405 (concat "'" txt)
406 txt)))
407 ;; ----------------------------------------------------------------------------
408 (defun desktop-outvar (varspec)
409 "Output a setq statement for variable VAR to the desktop file.
410 The argument VARSPEC may be the variable name VAR (a symbol),
411 or a cons cell of the form (VAR . MAX-SIZE),
412 which means to truncate VAR's value to at most MAX-SIZE elements
413 \(if the value is a list) before saving the value."
414 (let (var size)
415 (if (consp varspec)
416 (setq var (car varspec) size (cdr varspec))
417 (setq var varspec))
418 (if (boundp var)
419 (progn
420 (if (and (integerp size)
421 (> size 0)
422 (listp (eval var)))
423 (desktop-truncate (eval var) size))
424 (insert "(setq "
425 (symbol-name var)
427 (desktop-value-to-string (symbol-value var))
428 ")\n")))))
429 ;; ----------------------------------------------------------------------------
430 (defun desktop-save-buffer-p (filename bufname mode &rest dummy)
431 "Return t if the desktop should record a particular buffer for next startup.
432 FILENAME is the visited file name, BUFNAME is the buffer name, and
433 MODE is the major mode."
434 (let ((case-fold-search nil))
435 (and (not (string-match desktop-buffers-not-to-save bufname))
436 (not (memq mode desktop-modes-not-to-save))
437 (or (and filename
438 (not (string-match desktop-files-not-to-save filename)))
439 (and (eq mode 'dired-mode)
440 (save-excursion
441 (set-buffer (get-buffer bufname))
442 (not (string-match desktop-files-not-to-save
443 default-directory))))
444 (and (null filename)
445 (memq mode '(Info-mode rmail-mode)))))))
446 ;; ----------------------------------------------------------------------------
447 (defun desktop-save (dirname)
448 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop."
449 (interactive "DDirectory to save desktop file in: ")
450 (run-hooks 'desktop-save-hook)
451 (save-excursion
452 (let ((filename (expand-file-name
453 (concat dirname desktop-basefilename)))
454 (info (nreverse
455 (mapcar
456 (function
457 (lambda (b)
458 (set-buffer b)
459 (list
460 (buffer-file-name)
461 (buffer-name)
462 major-mode
463 ;; minor modes
464 (let (ret)
465 (mapcar
466 #'(lambda (mim)
467 (and (boundp mim)
468 (symbol-value mim)
469 (setq ret
470 (cons (let ((special (assq mim desktop-minor-mode-table)))
471 (if special
472 (cadr special)
473 mim))
474 ret))))
475 (mapcar #'car minor-mode-alist))
476 ret)
477 (point)
478 (list (mark t) mark-active)
479 buffer-read-only
480 (cond ((eq major-mode 'Info-mode)
481 (list Info-current-file
482 Info-current-node))
483 ((eq major-mode 'dired-mode)
484 (cons
485 (expand-file-name dired-directory)
486 (cdr
487 (nreverse
488 (mapcar
489 (function car)
490 dired-subdir-alist))))))
491 (let ((locals desktop-locals-to-save)
492 (loclist (buffer-local-variables))
493 (ll))
494 (while locals
495 (let ((here (assq (car locals) loclist)))
496 (if here
497 (setq ll (cons here ll))
498 (if (member (car locals) loclist)
499 (setq ll (cons (car locals) ll)))))
500 (setq locals (cdr locals)))
503 (buffer-list))))
504 (buf (get-buffer-create "*desktop*")))
505 (set-buffer buf)
506 (erase-buffer)
508 (insert desktop-header
509 ";; Created " (current-time-string) "\n"
510 ";; Emacs version " emacs-version "\n\n"
511 ";; Global section:\n")
512 (mapcar (function desktop-outvar) desktop-globals-to-save)
513 (if (memq 'kill-ring desktop-globals-to-save)
514 (insert "(setq kill-ring-yank-pointer (nthcdr "
515 (int-to-string
516 (- (length kill-ring) (length kill-ring-yank-pointer)))
517 " kill-ring))\n"))
519 (insert "\n;; Buffer section:\n")
520 (mapcar
521 (function (lambda (l)
522 (if (apply 'desktop-save-buffer-p l)
523 (progn
524 (insert desktop-create-buffer-form)
525 (mapcar
526 (function (lambda (e)
527 (insert "\n "
528 (desktop-value-to-string e))))
530 (insert ")\n\n")))))
531 info)
532 (setq default-directory dirname)
533 (if (file-exists-p filename) (delete-file filename))
534 (write-region (point-min) (point-max) filename nil 'nomessage)))
535 (setq desktop-dirname dirname))
536 ;; ----------------------------------------------------------------------------
537 (defun desktop-remove ()
538 "Delete the Desktop file and inactivate the desktop system."
539 (interactive)
540 (if desktop-dirname
541 (let ((filename (concat desktop-dirname desktop-basefilename)))
542 (setq desktop-dirname nil)
543 (if (file-exists-p filename)
544 (delete-file filename)))))
545 ;; ----------------------------------------------------------------------------
546 ;;;###autoload
547 (defun desktop-read ()
548 "Read the Desktop file and the files it specifies.
549 This is a no-op when Emacs is running in batch mode."
550 (interactive)
551 (if noninteractive
553 (let ((dirs '("./" "~/")))
554 (while (and dirs
555 (not (file-exists-p (expand-file-name
556 desktop-basefilename
557 (car dirs)))))
558 (setq dirs (cdr dirs)))
559 (setq desktop-dirname (and dirs (expand-file-name (car dirs))))
560 (if desktop-dirname
561 (progn
562 (load (expand-file-name desktop-basefilename desktop-dirname)
563 t t t)
564 (run-hooks 'desktop-delay-hook)
565 (setq desktop-delay-hook nil)
566 (message "Desktop loaded."))
567 (desktop-clear)))))
568 ;; ----------------------------------------------------------------------------
569 ;;;###autoload
570 (defun desktop-load-default ()
571 "Load the `default' start-up library manually.
572 Also inhibit further loading of it. Call this from your `.emacs' file
573 to provide correct modes for autoloaded files."
574 (if (not inhibit-default-init) ; safety check
575 (progn
576 (load "default" t t)
577 (setq inhibit-default-init t))))
578 ;; ----------------------------------------------------------------------------
579 ;; Note: the following functions use the dynamic variable binding in Lisp.
581 (defun desktop-buffer-info () "Load an info file."
582 (if (eq 'Info-mode desktop-buffer-major-mode)
583 (progn
584 (require 'info)
585 (Info-find-node (nth 0 desktop-buffer-misc) (nth 1 desktop-buffer-misc))
586 (current-buffer))))
587 ;; ----------------------------------------------------------------------------
588 (defun desktop-buffer-rmail () "Load an RMAIL file."
589 (if (eq 'rmail-mode desktop-buffer-major-mode)
590 (condition-case error
591 (progn (rmail-input desktop-buffer-file-name)
592 (if (eq major-mode 'rmail-mode)
593 (current-buffer)
594 rmail-buffer))
595 (file-locked
596 (kill-buffer (current-buffer))
597 'ignored))))
598 ;; ----------------------------------------------------------------------------
599 (defun desktop-buffer-mh () "Load a folder in the mh system."
600 (if (eq 'mh-folder-mode desktop-buffer-major-mode)
601 (progn
602 (require 'mh-e)
603 (mh-find-path)
604 (mh-visit-folder desktop-buffer-name)
605 (current-buffer))))
606 ;; ----------------------------------------------------------------------------
607 (defun desktop-buffer-dired () "Load a directory using dired."
608 (if (eq 'dired-mode desktop-buffer-major-mode)
609 (if (file-directory-p (file-name-directory (car desktop-buffer-misc)))
610 (progn
611 (dired (car desktop-buffer-misc))
612 (mapcar 'dired-maybe-insert-subdir (cdr desktop-buffer-misc))
613 (current-buffer))
614 (message "Directory %s no longer exists." (car desktop-buffer-misc))
615 (sit-for 1)
616 'ignored)))
617 ;; ----------------------------------------------------------------------------
618 (defun desktop-buffer-file () "Load a file."
619 (if desktop-buffer-file-name
620 (if (or (file-exists-p desktop-buffer-file-name)
621 (and desktop-missing-file-warning
622 (y-or-n-p (format
623 "File \"%s\" no longer exists. Re-create? "
624 desktop-buffer-file-name))))
625 (let ((buf (find-file-noselect desktop-buffer-file-name)))
626 (condition-case nil
627 (switch-to-buffer buf)
628 (error (pop-to-buffer buf))))
629 'ignored)))
630 ;; ----------------------------------------------------------------------------
631 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file
632 ;; only.
633 (defun desktop-create-buffer (ver desktop-buffer-file-name desktop-buffer-name
634 desktop-buffer-major-mode
635 mim pt mk ro desktop-buffer-misc
636 &optional locals)
637 (let ((hlist desktop-buffer-handlers)
638 (result)
639 (handler))
640 (while (and (not result) hlist)
641 (setq handler (car hlist))
642 (setq result (funcall handler))
643 (setq hlist (cdr hlist)))
644 (when (bufferp result)
645 (set-buffer result)
646 (if (not (equal (buffer-name) desktop-buffer-name))
647 (rename-buffer desktop-buffer-name))
648 ;; minor modes
649 (cond ((equal '(t) mim) (auto-fill-mode 1)) ; backwards compatible
650 ((equal '(nil) mim) (auto-fill-mode 0))
651 (t (mapcar #'(lambda (minor-mode)
652 (when minor-mode (funcall minor-mode 1)))
653 mim)))
654 (goto-char pt)
655 (if (consp mk)
656 (progn
657 (set-mark (car mk))
658 (setq mark-active (car (cdr mk))))
659 (set-mark mk))
660 ;; Never override file system if the file really is read-only marked.
661 (if ro (setq buffer-read-only ro))
662 (while locals
663 (let ((this (car locals)))
664 (if (consp this)
665 ;; an entry of this form `(symbol . value)'
666 (progn
667 (make-local-variable (car this))
668 (set (car this) (cdr this)))
669 ;; an entry of the form `symbol'
670 (make-local-variable this)
671 (makunbound this)))
672 (setq locals (cdr locals))))))
674 ;; Backward compatibility -- update parameters to 205 standards.
675 (defun desktop-buffer (desktop-buffer-file-name desktop-buffer-name
676 desktop-buffer-major-mode
677 mim pt mk ro tl fc cfs cr desktop-buffer-misc)
678 (desktop-create-buffer 205 desktop-buffer-file-name desktop-buffer-name
679 desktop-buffer-major-mode (cdr mim) pt mk ro
680 desktop-buffer-misc
681 (list (cons 'truncate-lines tl)
682 (cons 'fill-column fc)
683 (cons 'case-fold-search cfs)
684 (cons 'case-replace cr)
685 (cons 'overwrite-mode (car mim)))))
686 ;; ----------------------------------------------------------------------------
688 ;; If the user set desktop-enable to t with Custom,
689 ;; do the rest of what it takes to use desktop,
690 ;; but do it after finishing loading the init file.
691 (add-hook 'after-init-hook
692 '(lambda ()
693 (when desktop-enable
694 (desktop-load-default)
695 (desktop-read))))
697 (provide 'desktop)
699 ;;; desktop.el ends here