comparison lisp/desktop.el @ 89943:4c90ffeb71c5

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-15 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-218 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-220 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-221 Restore deleted tagline in etc/TUTORIAL.ru * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-222 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-228 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-229 Remove TeX output files from the archive * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-230 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-247 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-248 src/lisp.h (CYCLE_CHECK): Macro moved from xfaces.c * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-249 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-256 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-258 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-263 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-264 Update from CVS: lispref/display.texi: emacs -> Emacs. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-265 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-274 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-275 Update from CVS: man/makefile.w32-in: Revert last change * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-276 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-295 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-296 Allow restarting an existing debugger session that's exited * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-297 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-299 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-300 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-327 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-328 Update from CVS: src/.gdbinit (xsymbol): Fix last change. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-329 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-344 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-345 Tweak source regexps so that building in place won't cause problems * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-346 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-351 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-352 Update from CVS: lisp/flymake.el: New file. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-353 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-361 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-362 Support " [...]" style defaults in minibuffer-electric-default-mode * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-363 (read-number): Use canonical format for default in prompt. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-364 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-367 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-368 Improve display-supports-face-attributes-p on non-ttys * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-369 Rewrite face-differs-from-default-p * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-370 Move `display-supports-face-attributes-p' entirely into C code * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-371 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-372 Simplify face-differs-from-default-p; don't consider :stipple. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-373 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-374 (tty_supports_face_attributes_p): Ensure attributes differ from default * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-375 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-376 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-377 (Fdisplay_supports_face_attributes_p): Work around bootstrapping problem * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-378 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-380 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-381 Face merging cleanups * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-382 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-384 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-385 src/xfaces.c (push_named_merge_point): Return 0 if a cycle is detected * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-386 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-395 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-396 Tweak arch tagging to make build/install-in-place less annoying * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-397 Work around vc-arch problems when building eshell * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-398 Tweak permissions * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-399 Tweak directory permissions * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-400 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-401 More build-in-place tweaking of arch tagging * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-402 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-403 Yet more build-in-place tweaking of arch tagging * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-404 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-409 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-410 Make sure image types are initialized for lookup too * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-411 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-416 Update from CVS
author Miles Bader <miles@gnu.org>
date Mon, 28 Jun 2004 07:56:49 +0000
parents 68c22ea6027c 27173676bedf
children 566253900690
comparison
equal deleted inserted replaced
89942:9cb747ae49af 89943:4c90ffeb71c5
80 ;; Save window configuration. 80 ;; Save window configuration.
81 ;; Recognize more minor modes. 81 ;; Recognize more minor modes.
82 ;; Save mark rings. 82 ;; Save mark rings.
83 83
84 ;;; Code: 84 ;;; Code:
85
86 ;; Make the compilation more silent
87 (eval-when-compile
88 ;; We use functions from these modules
89 ;; We can't (require 'mh-e) since that wants to load something.
90 (mapcar 'require '(info dired reporter)))
91 85
92 (defvar desktop-file-version "206" 86 (defvar desktop-file-version "206"
93 "Version number of desktop file format. 87 "Version number of desktop file format.
94 Written into the desktop file and used at desktop read to provide 88 Written into the desktop file and used at desktop read to provide
95 backward compatibility.") 89 backward compatibility.")
149 The base name of the file is specified in `desktop-base-file-name'." 143 The base name of the file is specified in `desktop-base-file-name'."
150 :type '(repeat directory) 144 :type '(repeat directory)
151 :group 'desktop) 145 :group 'desktop)
152 146
153 (defcustom desktop-missing-file-warning nil 147 (defcustom desktop-missing-file-warning nil
154 "*If non-nil then `desktop-read' warns when a file no longer exists. 148 "*If non-nil then `desktop-read' asks if a non-existent file should be recreated.
155 Otherwise it simply ignores that file." 149 Also pause for a moment to display message about errors signaled in
150 `desktop-buffer-mode-handlers'.
151
152 If nil, just print error messages in the message buffer."
156 :type 'boolean 153 :type 'boolean
157 :group 'desktop) 154 :group 'desktop)
158 155
159 (defcustom desktop-no-desktop-file-hook nil 156 (defcustom desktop-no-desktop-file-hook nil
160 "Normal hook run when `desktop-read' can't find a desktop file. 157 "Normal hook run when `desktop-read' can't find a desktop file.
248 "^/[^/:]*:" 245 "^/[^/:]*:"
249 "Regexp identifying files whose buffers are to be excluded from saving." 246 "Regexp identifying files whose buffers are to be excluded from saving."
250 :type 'regexp 247 :type 'regexp
251 :group 'desktop) 248 :group 'desktop)
252 249
253 (defcustom desktop-buffer-modes-to-save
254 '(Info-mode rmail-mode)
255 "If a buffer is of one of these major modes, save the buffer state.
256 It is up to the functions in `desktop-buffer-handlers' to decide
257 whether the buffer should be recreated or not, and how."
258 :type '(repeat symbol)
259 :group 'desktop)
260
261 (defcustom desktop-modes-not-to-save nil 250 (defcustom desktop-modes-not-to-save nil
262 "List of major modes whose buffers should not be saved." 251 "List of major modes whose buffers should not be saved."
263 :type '(repeat symbol) 252 :type '(repeat symbol)
264 :group 'desktop) 253 :group 'desktop)
265 254
270 tilde -- Relative to ~. 259 tilde -- Relative to ~.
271 local -- Relative to directory of desktop file." 260 local -- Relative to directory of desktop file."
272 :type '(choice (const absolute) (const tilde) (const local)) 261 :type '(choice (const absolute) (const tilde) (const local))
273 :group 'desktop) 262 :group 'desktop)
274 263
275 (defcustom desktop-buffer-misc-functions 264 ;;;###autoload
276 '(desktop-buffer-info-misc-data 265 (defvar desktop-save-buffer nil
277 desktop-buffer-dired-misc-data) 266 "When non-nil, save buffer status in desktop file.
278 "*Functions used to determine auxiliary information for a buffer. 267 This variable becomes buffer local when set.
279 These functions are called by `desktop-save' in order, with no 268
280 arguments. If a function returns non-nil, its value is saved along 269 If the value is a function, it called by `desktop-save' with argument
281 with the state of the buffer for which it was called; no further 270 DESKTOP-DIRNAME to obtain auxiliary information to saved in the desktop
282 functions will be called. 271 file along with the state of the buffer for which it was called.
283 272
284 When file names are returned, they should be formatted using the call 273 When file names are returned, they should be formatted using the call
285 \"(desktop-file-name FILE-NAME dirname)\". 274 \"(desktop-file-name FILE-NAME DESKTOP-DIRNAME)\".
286 275
287 Later, when `desktop-read' restores buffers, each of the functions in 276 Later, when `desktop-read' calls a function in `desktop-buffer-mode-handlers'
288 `desktop-buffer-handlers' will have access to a buffer local variable, 277 to restore the buffer, the auxiliary information is passed as the argument
289 named `desktop-buffer-misc', whose value is what the function in 278 DESKTOP-BUFFER-MISC.")
290 `desktop-buffer-misc-functions' returned." 279 (make-variable-buffer-local 'desktop-save-buffer)
291 :type '(repeat function) 280 (make-obsolete-variable 'desktop-buffer-modes-to-save
292 :group 'desktop) 281 'desktop-save-buffer)
293 282 (make-obsolete-variable 'desktop-buffer-misc-functions
294 (defcustom desktop-buffer-handlers 283 'desktop-save-buffer)
295 '(desktop-buffer-dired 284
296 desktop-buffer-rmail 285 (defcustom desktop-buffer-mode-handlers '(
297 desktop-buffer-mh 286 (dired-mode . dired-restore-desktop-buffer)
298 desktop-buffer-info 287 (rmail-mode . rmail-restore-desktop-buffer)
299 desktop-buffer-file) 288 (mh-folder-mode . mh-restore-desktop-buffer)
300 "*Functions called by `desktop-read' in order to create a buffer. 289 (Info-mode . Info-restore-desktop-buffer))
301 The functions are called without explicit parameters but can use the 290 "Alist of major mode specific functions to restore a desktop buffer.
302 following variables: 291 Functions are called by `desktop-read'. List elements must have the form
292 \(MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
293
294 Buffers with a major mode not specified here, are restored by the default
295 handler `desktop-restore-file-buffer'.
296
297 Handlers are called with argument list
298
299 (DESKTOP-BUFFER-FILE-NAME DESKTOP-BUFFER-NAME DESKTOP-BUFFER-MISC)
300
301 Furthermore, they may use the following variables:
303 302
304 desktop-file-version 303 desktop-file-version
305 desktop-buffer-file-name
306 desktop-buffer-name
307 desktop-buffer-major-mode 304 desktop-buffer-major-mode
308 desktop-buffer-minor-modes 305 desktop-buffer-minor-modes
309 desktop-buffer-point 306 desktop-buffer-point
310 desktop-buffer-mark 307 desktop-buffer-mark
311 desktop-buffer-read-only 308 desktop-buffer-read-only
312 desktop-buffer-misc
313 desktop-buffer-locals 309 desktop-buffer-locals
314 310
315 If one function returns non-nil, no further functions are called. 311 If a handler returns a buffer, then the saved mode settings
316 If the function returns a buffer, then the saved mode settings
317 and variable values for that buffer are copied into it." 312 and variable values for that buffer are copied into it."
318 :type '(repeat function) 313 :type 'alist
319 :group 'desktop) 314 :group 'desktop)
320 315
321 (put 'desktop-buffer-handlers 'risky-local-variable t) 316 (put 'desktop-buffer-mode-handlers 'risky-local-variable t)
317 (make-obsolete-variable 'desktop-buffer-handlers
318 'desktop-buffer-mode-handlers)
322 319
323 (defcustom desktop-minor-mode-table 320 (defcustom desktop-minor-mode-table
324 '((auto-fill-function auto-fill-mode) 321 '((auto-fill-function auto-fill-mode)
325 (vc-mode nil)) 322 (vc-mode nil))
326 "Table mapping minor mode variables to minor mode functions. 323 "Table mapping minor mode variables to minor mode functions.
327 Each entry has the form (NAME RESTORE-FUNCTION). 324 Each entry has the form (NAME RESTORE-FUNCTION).
328 NAME is the name of the buffer-local variable indicating that the minor 325 NAME is the name of the buffer-local variable indicating that the minor
329 mode is active. RESTORE-FUNCTION is the function to activate the minor mode. 326 mode is active. RESTORE-FUNCTION is the function to activate the minor mode.
330 called. RESTORE-FUNCTION nil means don't try to restore the minor mode. 327 called. RESTORE-FUNCTION nil means don't try to restore the minor mode.
331 Only minor modes for which the name of the buffer-local variable 328 Only minor modes for which the name of the buffer-local variable
332 and the name of the minor mode function are different have to added to 329 and the name of the minor mode function are different have to be added to
333 this table." 330 this table."
334 :type 'sexp 331 :type 'sexp
335 :group 'desktop) 332 :group 'desktop)
336 333
337 ;; ---------------------------------------------------------------------------- 334 ;; ----------------------------------------------------------------------------
538 (desktop-value-to-string (symbol-value var)) 535 (desktop-value-to-string (symbol-value var))
539 ")\n"))))) 536 ")\n")))))
540 537
541 ;; ---------------------------------------------------------------------------- 538 ;; ----------------------------------------------------------------------------
542 (defun desktop-save-buffer-p (filename bufname mode &rest dummy) 539 (defun desktop-save-buffer-p (filename bufname mode &rest dummy)
543 "Return t if the desktop should record a particular buffer for next startup. 540 "Return t if buffer should have its state saved in the desktop file.
544 FILENAME is the visited file name, BUFNAME is the buffer name, and 541 FILENAME is the visited file name, BUFNAME is the buffer name, and
545 MODE is the major mode." 542 MODE is the major mode."
546 (let ((case-fold-search nil)) 543 (let ((case-fold-search nil))
547 (and (not (string-match desktop-buffers-not-to-save bufname)) 544 (and (not (string-match desktop-buffers-not-to-save bufname))
548 (not (memq mode desktop-modes-not-to-save)) 545 (not (memq mode desktop-modes-not-to-save))
549 (or (and filename 546 (or (and filename
550 (not (string-match desktop-files-not-to-save filename))) 547 (not (string-match desktop-files-not-to-save filename)))
551 (and (eq mode 'dired-mode) 548 (and (eq mode 'dired-mode)
552 (save-excursion 549 (with-current-buffer bufname
553 (set-buffer (get-buffer bufname)) 550 (not (string-match desktop-files-not-to-save
554 (not (string-match desktop-files-not-to-save 551 default-directory))))
555 default-directory)))) 552 (and (null filename)
556 (and (null filename) 553 (with-current-buffer bufname desktop-save-buffer))))))
557 (memq mode desktop-buffer-modes-to-save))))))
558 554
559 ;; ---------------------------------------------------------------------------- 555 ;; ----------------------------------------------------------------------------
560 (defun desktop-file-name (filename dirname) 556 (defun desktop-file-name (filename dirname)
561 "Convert FILENAME to format specified in `desktop-file-name-format'. 557 "Convert FILENAME to format specified in `desktop-file-name-format'.
562 DIRNAME must be the directory in which the desktop file will be saved." 558 DIRNAME must be the directory in which the desktop file will be saved."
591 (desktop-file-name (buffer-file-name) dirname) 587 (desktop-file-name (buffer-file-name) dirname)
592 (buffer-name) 588 (buffer-name)
593 major-mode 589 major-mode
594 ;; minor modes 590 ;; minor modes
595 (let (ret) 591 (let (ret)
596 (mapcar 592 (mapc
597 #'(lambda (mim) 593 #'(lambda (minor-mode)
598 (and 594 (and
599 (boundp mim) 595 (boundp minor-mode)
600 (symbol-value mim) 596 (symbol-value minor-mode)
601 (setq ret 597 (let ((special (assq minor-mode desktop-minor-mode-table)))
602 (cons 598 (when (or special (functionp minor-mode))
603 (let ((special (assq mim desktop-minor-mode-table))) 599 (setq ret
604 (if special (cadr special) mim)) 600 (cons
605 ret)))) 601 (if special (cadr special) minor-mode)
602 ret))))))
606 (mapcar #'car minor-mode-alist)) 603 (mapcar #'car minor-mode-alist))
607 ret) 604 ret)
608 (point) 605 (point)
609 (list (mark t) mark-active) 606 (list (mark t) mark-active)
610 buffer-read-only 607 buffer-read-only
611 (run-hook-with-args-until-success 'desktop-buffer-misc-functions) 608 ;; Auxiliary information
609 (when (functionp desktop-save-buffer)
610 (funcall desktop-save-buffer dirname))
612 (let ((locals desktop-locals-to-save) 611 (let ((locals desktop-locals-to-save)
613 (loclist (buffer-local-variables)) 612 (loclist (buffer-local-variables))
614 (ll)) 613 (ll))
615 (while locals 614 (while locals
616 (let ((here (assq (car locals) loclist))) 615 (let ((here (assq (car locals) loclist)))
701 (and desktop-path (car desktop-path)) 700 (and desktop-path (car desktop-path))
702 ;; Default: Home directory. 701 ;; Default: Home directory.
703 "~")))) 702 "~"))))
704 (if (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)) 703 (if (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname))
705 ;; Desktop file found, process it. 704 ;; Desktop file found, process it.
706 (let ((desktop-first-buffer nil)) 705 (let ((desktop-first-buffer nil)
706 (desktop-buffer-ok-count 0)
707 (desktop-buffer-fail-count 0))
707 ;; Evaluate desktop buffer. 708 ;; Evaluate desktop buffer.
708 (load (expand-file-name desktop-base-file-name desktop-dirname) t t t) 709 (load (expand-file-name desktop-base-file-name desktop-dirname) t t t)
709 ;; `desktop-create-buffer' puts buffers at end of the buffer list. 710 ;; `desktop-create-buffer' puts buffers at end of the buffer list.
710 ;; We want buffers existing prior to evaluating the desktop (and not reused) 711 ;; We want buffers existing prior to evaluating the desktop (and not reused)
711 ;; to be placed at the end of the buffer list, so we move them here. 712 ;; to be placed at the end of the buffer list, so we move them here.
713 (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list)))))) 714 (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list))))))
714 (switch-to-buffer (car (buffer-list))) 715 (switch-to-buffer (car (buffer-list)))
715 (run-hooks 'desktop-delay-hook) 716 (run-hooks 'desktop-delay-hook)
716 (setq desktop-delay-hook nil) 717 (setq desktop-delay-hook nil)
717 (run-hooks 'desktop-after-read-hook) 718 (run-hooks 'desktop-after-read-hook)
718 (message "Desktop loaded.") 719 (message "Desktop: %d buffer%s restored%s."
720 desktop-buffer-ok-count
721 (if (= 1 desktop-buffer-ok-count) "" "s")
722 (if (< 0 desktop-buffer-fail-count)
723 (format ", %d failed to restore" desktop-buffer-fail-count)
724 ""))
719 t) 725 t)
720 ;; No desktop file found. 726 ;; No desktop file found.
721 (desktop-clear) 727 (desktop-clear)
722 (let ((default-directory desktop-dirname)) 728 (let ((default-directory desktop-dirname))
723 (run-hooks 'desktop-no-desktop-file-hook)) 729 (run-hooks 'desktop-no-desktop-file-hook))
770 (error "No desktop file found")) 776 (error "No desktop file found"))
771 (desktop-clear) 777 (desktop-clear)
772 (desktop-read desktop-dirname)) 778 (desktop-read desktop-dirname))
773 779
774 ;; ---------------------------------------------------------------------------- 780 ;; ----------------------------------------------------------------------------
775 ;; Note: the following functions use the dynamic variable binding in Lisp. 781 (defun desktop-restore-file-buffer (desktop-buffer-file-name
776 ;; 782 desktop-buffer-name
777 783 desktop-buffer-misc)
778 (eval-when-compile ; Just to silence the byte compiler 784 "Restore a file buffer."
779 (defvar desktop-file-version) 785 (eval-when-compile ; Just to silence the byte compiler
780 (defvar desktop-buffer-file-name) 786 (defvar desktop-buffer-major-mode)
781 (defvar desktop-buffer-name) 787 (defvar desktop-buffer-locals))
782 (defvar desktop-buffer-major-mode)
783 (defvar desktop-buffer-minor-modes)
784 (defvar desktop-buffer-point)
785 (defvar desktop-buffer-mark)
786 (defvar desktop-buffer-read-only)
787 (defvar desktop-buffer-misc)
788 (defvar desktop-buffer-locals)
789 )
790
791 (defun desktop-buffer-info-misc-data ()
792 (if (eq major-mode 'Info-mode)
793 (list Info-current-file
794 Info-current-node)))
795
796 ;; ----------------------------------------------------------------------------
797 (defun desktop-buffer-dired-misc-data ()
798 (when (eq major-mode 'dired-mode)
799 (eval-when-compile (defvar dirname))
800 (cons
801 ;; Value of `dired-directory'.
802 (if (consp dired-directory)
803 ;; Directory name followed by list of files.
804 (cons (desktop-file-name (car dired-directory) dirname) (cdr dired-directory))
805 ;; Directory name, optionally with with shell wildcard.
806 (desktop-file-name dired-directory dirname))
807 ;; Subdirectories in `dired-subdir-alist'.
808 (cdr
809 (nreverse
810 (mapcar
811 (function (lambda (f) (desktop-file-name (car f) dirname)))
812 dired-subdir-alist))))))
813
814 ;; ----------------------------------------------------------------------------
815 (defun desktop-buffer-info () "Load an info file."
816 (if (eq 'Info-mode desktop-buffer-major-mode)
817 (progn
818 (let ((first (nth 0 desktop-buffer-misc))
819 (second (nth 1 desktop-buffer-misc)))
820 (when (and first second)
821 (require 'info)
822 (with-no-warnings
823 (Info-find-node first second))
824 (current-buffer))))))
825
826 ;; ----------------------------------------------------------------------------
827 (eval-when-compile (defvar rmail-buffer)) ; Just to silence the byte compiler.
828 (defun desktop-buffer-rmail () "Load an RMAIL file."
829 (if (eq 'rmail-mode desktop-buffer-major-mode)
830 (condition-case error
831 (progn (rmail-input desktop-buffer-file-name)
832 (if (eq major-mode 'rmail-mode)
833 (current-buffer)
834 rmail-buffer))
835 (file-locked
836 (kill-buffer (current-buffer))
837 'ignored))))
838
839 ;; ----------------------------------------------------------------------------
840 (defun desktop-buffer-mh () "Load a folder in the mh system."
841 (if (eq 'mh-folder-mode desktop-buffer-major-mode)
842 (with-no-warnings
843 (mh-find-path)
844 (mh-visit-folder desktop-buffer-name)
845 (current-buffer))))
846
847 ;; ----------------------------------------------------------------------------
848 (defun desktop-buffer-dired () "Load a directory using dired."
849 (if (eq 'dired-mode desktop-buffer-major-mode)
850 ;; First element of `desktop-buffer-misc' is the value of `dired-directory'.
851 ;; This value is a directory name, optionally with with shell wildcard or
852 ;; a directory name followed by list of files.
853 (let* ((dired-dir (car desktop-buffer-misc))
854 (dir (if (consp dired-dir) (car dired-dir) dired-dir)))
855 (if (file-directory-p (file-name-directory dir))
856 (progn
857 (dired dired-dir)
858 ;; The following elements of `desktop-buffer-misc' are the keys
859 ;; from `dired-subdir-alist'.
860 (mapcar 'dired-maybe-insert-subdir (cdr desktop-buffer-misc))
861 (current-buffer))
862 (message "Directory %s no longer exists." dir)
863 (sit-for 1)
864 'ignored))))
865
866 ;; ----------------------------------------------------------------------------
867 (defun desktop-buffer-file ()
868 "Load a file."
869 (if desktop-buffer-file-name 788 (if desktop-buffer-file-name
870 (if (or (file-exists-p desktop-buffer-file-name) 789 (if (or (file-exists-p desktop-buffer-file-name)
871 (and desktop-missing-file-warning 790 (let ((msg (format "Desktop: File \"%s\" no longer exists."
872 (y-or-n-p (format 791 desktop-buffer-file-name)))
873 "File \"%s\" no longer exists. Re-create? " 792 (if desktop-missing-file-warning
874 desktop-buffer-file-name)))) 793 (y-or-n-p (concat msg " Re-create? "))
794 (message msg)
795 nil)))
875 (let* ((auto-insert nil) ; Disable auto insertion 796 (let* ((auto-insert nil) ; Disable auto insertion
876 (coding-system-for-read 797 (coding-system-for-read
877 (or coding-system-for-read 798 (or coding-system-for-read
878 (cdr (assq 'buffer-file-coding-system 799 (cdr (assq 'buffer-file-coding-system
879 desktop-buffer-locals)))) 800 desktop-buffer-locals))))
883 (error (pop-to-buffer buf))) 804 (error (pop-to-buffer buf)))
884 (and (not (eq major-mode desktop-buffer-major-mode)) 805 (and (not (eq major-mode desktop-buffer-major-mode))
885 (functionp desktop-buffer-major-mode) 806 (functionp desktop-buffer-major-mode)
886 (funcall desktop-buffer-major-mode)) 807 (funcall desktop-buffer-major-mode))
887 buf) 808 buf)
888 'ignored))) 809 nil)))
889 810
890 ;; ---------------------------------------------------------------------------- 811 ;; ----------------------------------------------------------------------------
891 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file 812 ;; Create a buffer, load its file, set its mode, ...;
892 ;; only. 813 ;; called from Desktop file only.
893 814
894 (eval-when-compile ; Just to silence the byte compiler 815 (eval-when-compile ; Just to silence the byte compiler
895 (defvar desktop-first-buffer) ;; Dynamically bound in `desktop-read' 816 (defvar desktop-first-buffer) ;; Dynamically bound in `desktop-read'
896 ) 817 )
897 818
905 desktop-buffer-mark 826 desktop-buffer-mark
906 desktop-buffer-read-only 827 desktop-buffer-read-only
907 desktop-buffer-misc 828 desktop-buffer-misc
908 &optional 829 &optional
909 desktop-buffer-locals) 830 desktop-buffer-locals)
831 ;; Just to silence the byte compiler. Bound locally in `desktop-read'.
832 (eval-when-compile
833 (defvar desktop-buffer-ok-count)
834 (defvar desktop-buffer-fail-count))
910 ;; To make desktop files with relative file names possible, we cannot 835 ;; To make desktop files with relative file names possible, we cannot
911 ;; allow `default-directory' to change. Therefore we save current buffer. 836 ;; allow `default-directory' to change. Therefore we save current buffer.
912 (save-current-buffer 837 (save-current-buffer
913 (let ( 838 (let (
914 (buffer-list (buffer-list)) 839 (buffer-list (buffer-list))
915 (hlist desktop-buffer-handlers) 840 (result
916 (result) 841 (condition-case err
917 (handler) 842 (funcall (or (cdr (assq desktop-buffer-major-mode desktop-buffer-mode-handlers))
843 'desktop-restore-file-buffer)
844 desktop-buffer-file-name
845 desktop-buffer-name
846 desktop-buffer-misc)
847 (error
848 (message "Desktop: Can't load buffer %s: %s"
849 desktop-buffer-name (error-message-string err))
850 (when desktop-missing-file-warning (sit-for 1))
851 nil)))
918 ) 852 )
919 ;; Call desktop-buffer-handlers to create buffer. 853 (if (bufferp result)
920 (while (and (not result) hlist) 854 (setq desktop-buffer-ok-count (1+ desktop-buffer-ok-count))
921 (setq handler (car hlist)) 855 (setq desktop-buffer-fail-count (1+ desktop-buffer-fail-count))
922 (setq result (funcall handler)) 856 (setq result nil))
923 (setq hlist (cdr hlist)))
924 (unless (bufferp result) (setq result nil)) 857 (unless (bufferp result) (setq result nil))
925 ;; Restore buffer list order with new buffer at end. Don't change 858 ;; Restore buffer list order with new buffer at end. Don't change
926 ;; the order for old desktop files (old desktop module behaviour). 859 ;; the order for old desktop files (old desktop module behaviour).
927 (unless (< desktop-file-version 206) 860 (unless (< desktop-file-version 206)
928 (mapcar 'bury-buffer buffer-list) 861 (mapcar 'bury-buffer buffer-list)
945 #'(lambda (minor-mode) 878 #'(lambda (minor-mode)
946 (when (functionp minor-mode) (funcall minor-mode 1))) 879 (when (functionp minor-mode) (funcall minor-mode 1)))
947 desktop-buffer-minor-modes))) 880 desktop-buffer-minor-modes)))
948 ;; Even though point and mark are non-nil when written by `desktop-save' 881 ;; Even though point and mark are non-nil when written by `desktop-save'
949 ;; they may be modified by handlers wanting to set point or mark themselves. 882 ;; they may be modified by handlers wanting to set point or mark themselves.
950 (when desktop-buffer-point (goto-char desktop-buffer-point)) 883 (when desktop-buffer-point
884 (goto-char
885 (condition-case err
886 ;; Evaluate point. Thus point can be something like '(search-forward ...
887 (eval desktop-buffer-point)
888 (error (message "%s" (error-message-string err)) 1))))
951 (when desktop-buffer-mark 889 (when desktop-buffer-mark
952 (if (consp desktop-buffer-mark) 890 (if (consp desktop-buffer-mark)
953 (progn 891 (progn
954 (set-mark (car desktop-buffer-mark)) 892 (set-mark (car desktop-buffer-mark))
955 (setq mark-active (car (cdr desktop-buffer-mark)))) 893 (setq mark-active (car (cdr desktop-buffer-mark))))