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.
|
|
107 (mapcar 'require '(info dired reporter)))
|
|
108 ;; ----------------------------------------------------------------------------
|
|
109 ;; USER OPTIONS -- settings you might want to play with.
|
|
110 ;; ----------------------------------------------------------------------------
|
|
111 (defconst desktop-basefilename
|
|
112 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
|
|
113 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name
|
|
114 ".emacs.desktop")
|
|
115 "File for Emacs desktop, not including the directory name.")
|
|
116
|
|
117 (defvar desktop-missing-file-warning t
|
|
118 "*If non-nil then desktop warns when a file no longer exists.
|
|
119 Otherwise it simply ignores that file.")
|
|
120
|
|
121 (defvar desktop-globals-to-save
|
|
122 (list 'desktop-missing-file-warning
|
|
123 ;; Feature: saving kill-ring implies saving kill-ring-yank-pointer
|
|
124 ;; 'kill-ring
|
|
125 'tags-file-name
|
|
126 'tags-table-list
|
|
127 'search-ring
|
|
128 'regexp-search-ring
|
|
129 'register-alist
|
|
130 ;; 'desktop-globals-to-save ; Itself!
|
|
131 )
|
|
132 "List of global variables to save when killing Emacs.
|
|
133 An element may be variable name (a symbol)
|
|
134 or a cons cell of the form (VAR . MAX-SIZE),
|
|
135 which means to truncate VAR's value to at most MAX-SIZE elements
|
|
136 \(if the value is a list) before saving the value.")
|
|
137
|
|
138 (defvar desktop-locals-to-save
|
|
139 (list 'desktop-locals-to-save ; Itself! Think it over.
|
|
140 'truncate-lines
|
|
141 'case-fold-search
|
|
142 'case-replace
|
|
143 'fill-column
|
|
144 'overwrite-mode
|
|
145 'change-log-default-name
|
|
146 'line-number-mode
|
|
147 )
|
|
148 "List of local variables to save for each buffer.
|
|
149 The variables are saved only when they really are local.")
|
|
150 (make-variable-buffer-local 'desktop-locals-to-save)
|
|
151
|
|
152 ;; We skip .log files because they are normally temporary.
|
2
|
153 ;; (ftp) files because they require passwords and whatnot.
|
0
|
154 ;; TAGS files to save time (tags-file-name is saved instead).
|
|
155 (defvar desktop-buffers-not-to-save
|
|
156 "\\(^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\|^tags\\|^TAGS\\)$"
|
|
157 "Regexp identifying buffers that are to be excluded from saving.")
|
|
158
|
|
159 ;; Skip ange-ftp files
|
|
160 (defvar desktop-files-not-to-save
|
|
161 "^/[^/:]*:"
|
|
162 "Regexp identifying files whose buffers are to be excluded from saving.")
|
|
163
|
2
|
164 (defvar desktop-buffer-major-mode nil
|
|
165 "When desktop creates a buffer, this holds the desired Major mode.")
|
|
166
|
|
167 (defvar desktop-buffer-file-name nil
|
|
168 "When desktop creates a buffer, this holds the file name to visit.")
|
|
169
|
|
170 (defvar desktop-buffer-name nil
|
|
171 "When desktop creates a buffer, this holds the desired buffer name.")
|
|
172
|
|
173 (defvar desktop-buffer-misc nil
|
|
174 "When desktop creates a buffer, this holds a list of misc info.
|
|
175 It is used by the `desktop-buffer-handlers' functions.")
|
|
176
|
0
|
177 (defvar desktop-buffer-handlers
|
|
178 '(desktop-buffer-dired
|
|
179 desktop-buffer-rmail
|
|
180 desktop-buffer-mh
|
|
181 desktop-buffer-info
|
|
182 desktop-buffer-file)
|
|
183 "*List of functions to call in order to create a buffer.
|
2
|
184 The functions are called without explicit parameters but can use the
|
|
185 variables `desktop-buffer-major-mode', `desktop-buffer-file-name',
|
|
186 `desktop-buffer-name'.
|
|
187 If one function returns non-nil, no further functions are called.
|
|
188 If the function returns t then the buffer is considered created.")
|
0
|
189
|
|
190 (defvar desktop-create-buffer-form "(desktop-create-buffer 205"
|
|
191 "Opening of form for creation of new buffers.")
|
|
192
|
|
193 (defvar desktop-save-hook nil
|
|
194 "Hook run before saving the desktop to allow you to cut history lists and
|
|
195 the like shorter.")
|
|
196 ;; ----------------------------------------------------------------------------
|
|
197 (defvar desktop-dirname nil
|
|
198 "The directory in which the current desktop file resides.")
|
|
199
|
|
200 (defconst desktop-header
|
|
201 ";; --------------------------------------------------------------------------
|
|
202 ;; Desktop File for Emacs
|
|
203 ;; --------------------------------------------------------------------------
|
|
204 " "*Header to place in Desktop file.")
|
|
205
|
|
206 (defvar desktop-delay-hook nil
|
|
207 "Hooks run after all buffers are loaded; intended for internal use.")
|
|
208 ;; ----------------------------------------------------------------------------
|
|
209 (defun desktop-truncate (l n)
|
|
210 "Truncate LIST to at most N elements destructively."
|
|
211 (let ((here (nthcdr (1- n) l)))
|
|
212 (if (consp here)
|
|
213 (setcdr here nil))))
|
|
214 ;; ----------------------------------------------------------------------------
|
|
215 (defun desktop-clear () "Empty the Desktop."
|
|
216 (interactive)
|
|
217 (setq kill-ring nil
|
|
218 kill-ring-yank-pointer nil
|
|
219 search-ring nil
|
|
220 search-ring-yank-pointer nil
|
|
221 regexp-search-ring nil
|
|
222 regexp-search-ring-yank-pointer nil)
|
|
223 (mapcar (function (lambda (x)
|
|
224 ;; XEmacs change
|
|
225 (if (not (equal (buffer-name x) "*Warnings*"))
|
|
226 (kill-buffer x)))) (buffer-list))
|
|
227 (delete-other-windows))
|
|
228 ;; ----------------------------------------------------------------------------
|
|
229 (add-hook 'kill-emacs-hook 'desktop-kill)
|
|
230
|
|
231 (defun desktop-kill ()
|
|
232 (if desktop-dirname
|
|
233 (condition-case err
|
|
234 (desktop-save desktop-dirname)
|
|
235 (file-error
|
|
236 (if (yes-or-no-p "Error while saving the desktop. Quit anyway? ")
|
|
237 nil
|
|
238 (signal (car err) (cdr err)))))))
|
|
239 ;; ----------------------------------------------------------------------------
|
2
|
240 (defun desktop-list* (&rest args)
|
|
241 (if (null (cdr args))
|
|
242 (car args)
|
|
243 (setq args (nreverse args))
|
|
244 (let ((value (cons (nth 1 args) (car args))))
|
|
245 (setq args (cdr (cdr args)))
|
|
246 (while args
|
|
247 (setq value (cons (car args) value))
|
|
248 (setq args (cdr args)))
|
|
249 value)))
|
|
250
|
0
|
251 (defun desktop-internal-v2s (val)
|
|
252 "Convert VALUE to a pair (QUOTE . TXT); (eval (read TXT)) gives VALUE.
|
|
253 TXT is a string that when read and evaluated yields value.
|
|
254 QUOTE may be `may' (value may be quoted),
|
|
255 `must' (values must be quoted), or nil (value may not be quoted)."
|
|
256 (cond
|
|
257 ((or (numberp val) (null val) (eq t val))
|
|
258 (cons 'may (prin1-to-string val)))
|
|
259 ((stringp val)
|
|
260 (let ((copy (copy-sequence val)))
|
|
261 (set-text-properties 0 (length copy) nil copy)
|
|
262 ;; Get rid of text properties because we cannot read them
|
|
263 (cons 'may (prin1-to-string copy))))
|
|
264 ((symbolp val)
|
|
265 (cons 'must (prin1-to-string val)))
|
|
266 ((vectorp val)
|
|
267 (let* ((special nil)
|
|
268 (pass1 (mapcar
|
|
269 (lambda (el)
|
|
270 (let ((res (desktop-internal-v2s el)))
|
|
271 (if (null (car res))
|
|
272 (setq special t))
|
|
273 res))
|
|
274 val)))
|
|
275 (if special
|
|
276 (cons nil (concat "(vector "
|
|
277 (mapconcat (lambda (el)
|
|
278 (if (eq (car el) 'must)
|
|
279 (concat "'" (cdr el))
|
|
280 (cdr el)))
|
|
281 pass1
|
|
282 " ")
|
|
283 ")"))
|
|
284 (cons 'may (concat "[" (mapconcat 'cdr pass1 " ") "]")))))
|
|
285 ((consp val)
|
|
286 (let ((p val)
|
|
287 newlist
|
2
|
288 use-list*
|
0
|
289 anynil)
|
|
290 (while (consp p)
|
|
291 (let ((q.txt (desktop-internal-v2s (car p))))
|
|
292 (or anynil (setq anynil (null (car q.txt))))
|
|
293 (setq newlist (cons q.txt newlist)))
|
|
294 (setq p (cdr p)))
|
|
295 (if p
|
|
296 (let ((last (desktop-internal-v2s p))
|
|
297 (el (car newlist)))
|
2
|
298 (or anynil (setq anynil (null (car last))))
|
|
299 (or anynil
|
|
300 (setq newlist (cons '(must . ".") newlist)))
|
|
301 (setq use-list* t)
|
|
302 (setq newlist (cons last newlist))))
|
0
|
303 (setq newlist (nreverse newlist))
|
|
304 (if anynil
|
|
305 (cons nil
|
2
|
306 (concat (if use-list* "(desktop-list* " "(list ")
|
0
|
307 (mapconcat (lambda (el)
|
|
308 (if (eq (car el) 'must)
|
|
309 (concat "'" (cdr el))
|
|
310 (cdr el)))
|
|
311 newlist
|
|
312 " ")
|
|
313 ")"))
|
|
314 (cons 'must
|
|
315 (concat "(" (mapconcat 'cdr newlist " ") ")")))))
|
|
316 ((subrp val)
|
|
317 (cons nil (concat "(symbol-function '"
|
|
318 (substring (prin1-to-string val) 7 -1)
|
|
319 ")")))
|
|
320 ((markerp val)
|
|
321 (let ((pos (prin1-to-string (marker-position val)))
|
|
322 (buf (prin1-to-string (buffer-name (marker-buffer val)))))
|
|
323 (cons nil (concat "(let ((mk (make-marker)))"
|
|
324 " (add-hook 'desktop-delay-hook"
|
|
325 " (list 'lambda '() (list 'set-marker mk "
|
|
326 pos " (get-buffer " buf ")))) mk)"))))
|
|
327 (t ; save as text
|
|
328 (cons 'may "\"Unprintable entity\""))))
|
|
329
|
|
330 (defun desktop-value-to-string (val)
|
|
331 "Convert VALUE to a string that when read evaluates to the same value.
|
|
332 Not all types of values are supported."
|
|
333 (let* ((print-escape-newlines t)
|
|
334 (float-output-format nil)
|
|
335 (quote.txt (desktop-internal-v2s val))
|
|
336 (quote (car quote.txt))
|
|
337 (txt (cdr quote.txt)))
|
|
338 (if (eq quote 'must)
|
|
339 (concat "'" txt)
|
|
340 txt)))
|
|
341 ;; ----------------------------------------------------------------------------
|
|
342 (defun desktop-outvar (varspec)
|
|
343 "Output a setq statement for variable VAR to the desktop file.
|
|
344 The argument VARSPEC may be the variable name VAR (a symbol),
|
|
345 or a cons cell of the form (VAR . MAX-SIZE),
|
|
346 which means to truncate VAR's value to at most MAX-SIZE elements
|
|
347 \(if the value is a list) before saving the value."
|
|
348 (let (var size)
|
|
349 (if (consp varspec)
|
|
350 (setq var (car varspec) size (cdr varspec))
|
|
351 (setq var varspec))
|
|
352 (if (boundp var)
|
|
353 (progn
|
|
354 (if (and (integerp size)
|
|
355 (> size 0)
|
|
356 (listp (eval var)))
|
|
357 (desktop-truncate (eval var) size))
|
|
358 (insert "(setq "
|
|
359 (symbol-name var)
|
|
360 " "
|
|
361 (desktop-value-to-string (symbol-value var))
|
|
362 ")\n")))))
|
|
363 ;; ----------------------------------------------------------------------------
|
|
364 (defun desktop-save-buffer-p (filename bufname mode &rest dummy)
|
|
365 "Return t if the desktop should record a particular buffer for next startup.
|
|
366 FILENAME is the visited file name, BUFNAME is the buffer name, and
|
|
367 MODE is the major mode."
|
|
368 (let ((case-fold-search nil))
|
|
369 (or (and filename
|
|
370 (not (string-match desktop-buffers-not-to-save bufname))
|
|
371 (not (string-match desktop-files-not-to-save filename)))
|
|
372 (and (eq mode 'dired-mode)
|
|
373 (save-excursion
|
|
374 (set-buffer (get-buffer bufname))
|
|
375 (not (string-match desktop-files-not-to-save
|
|
376 default-directory))))
|
|
377 (and (null filename)
|
|
378 (memq mode '(Info-mode rmail-mode))))))
|
|
379 ;; ----------------------------------------------------------------------------
|
|
380 (defun desktop-save (dirname)
|
|
381 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop."
|
|
382 (interactive "DDirectory to save desktop file in: ")
|
|
383 (run-hooks 'desktop-save-hook)
|
|
384 (save-excursion
|
|
385 (let ((filename (expand-file-name
|
|
386 (concat dirname desktop-basefilename)))
|
|
387 (info (nreverse
|
|
388 (mapcar
|
|
389 (function (lambda (b)
|
|
390 (set-buffer b)
|
|
391 (list
|
|
392 (buffer-file-name)
|
|
393 (buffer-name)
|
|
394 major-mode
|
|
395 (list ; list explaining minor modes
|
|
396 (not (null auto-fill-function)))
|
|
397 (point)
|
|
398 (list (mark t) ;; mark-active
|
|
399 (not (null (mark)))) ; XEmacs
|
|
400 buffer-read-only
|
|
401 (cond ((eq major-mode 'Info-mode)
|
|
402 (list Info-current-file
|
|
403 Info-current-node))
|
|
404 ((eq major-mode 'dired-mode)
|
|
405 (cons
|
|
406 (expand-file-name dired-directory)
|
|
407 (cdr
|
|
408 (nreverse
|
|
409 (mapcar
|
|
410 (function car)
|
|
411 dired-subdir-alist))))))
|
|
412 (let ((locals desktop-locals-to-save)
|
|
413 (loclist (buffer-local-variables))
|
|
414 (ll))
|
|
415 (while locals
|
|
416 (let ((here (assq (car locals) loclist)))
|
|
417 (if here
|
|
418 (setq ll (cons here ll))
|
|
419 (if (member (car locals) loclist)
|
|
420 (setq ll (cons (car locals) ll)))))
|
|
421 (setq locals (cdr locals)))
|
|
422 ll)
|
|
423 )))
|
|
424 (buffer-list))))
|
|
425 (buf (get-buffer-create "*desktop*")))
|
|
426 (set-buffer buf)
|
|
427 (erase-buffer)
|
|
428
|
|
429 (insert desktop-header
|
|
430 ";; Created " (current-time-string) "\n"
|
|
431 ";; Emacs version " emacs-version "\n\n"
|
|
432 ";; Global section:\n")
|
|
433 (mapcar (function desktop-outvar) desktop-globals-to-save)
|
|
434 (if (memq 'kill-ring desktop-globals-to-save)
|
|
435 (insert "(setq kill-ring-yank-pointer (nthcdr "
|
|
436 (int-to-string
|
|
437 (- (length kill-ring) (length kill-ring-yank-pointer)))
|
|
438 " kill-ring))\n"))
|
|
439
|
|
440 (insert "\n;; Buffer section:\n")
|
|
441 (mapcar
|
|
442 (function (lambda (l)
|
|
443 (if (apply 'desktop-save-buffer-p l)
|
|
444 (progn
|
|
445 (insert desktop-create-buffer-form)
|
|
446 (mapcar
|
|
447 (function (lambda (e)
|
|
448 (insert "\n "
|
|
449 (desktop-value-to-string e))))
|
|
450 l)
|
|
451 (insert ")\n\n")))))
|
|
452 info)
|
|
453 (setq default-directory dirname)
|
|
454 (if (file-exists-p filename) (delete-file filename))
|
|
455 (write-region (point-min) (point-max) filename nil 'nomessage)))
|
|
456 (setq desktop-dirname dirname))
|
|
457 ;; ----------------------------------------------------------------------------
|
|
458 (defun desktop-remove ()
|
|
459 "Delete the Desktop file and inactivate the desktop system."
|
|
460 (interactive)
|
|
461 (if desktop-dirname
|
|
462 (let ((filename (concat desktop-dirname desktop-basefilename)))
|
|
463 (setq desktop-dirname nil)
|
|
464 (if (file-exists-p filename)
|
|
465 (delete-file filename)))))
|
|
466 ;; ----------------------------------------------------------------------------
|
|
467 (defun desktop-read ()
|
2
|
468 "Read the Desktop file and the files it specifies.
|
|
469 This is a no-op when Emacs is running in batch mode."
|
0
|
470 (interactive)
|
2
|
471 (if noninteractive
|
|
472 nil
|
|
473 (let ((dirs '("./" "~/")))
|
|
474 (while (and dirs
|
|
475 (not (file-exists-p (expand-file-name
|
|
476 desktop-basefilename
|
|
477 (car dirs)))))
|
|
478 (setq dirs (cdr dirs)))
|
|
479 (setq desktop-dirname (and dirs (expand-file-name (car dirs))))
|
|
480 (if desktop-dirname
|
|
481 (progn
|
|
482 (load (expand-file-name desktop-basefilename desktop-dirname)
|
|
483 t t t)
|
|
484 (run-hooks 'desktop-delay-hook)
|
|
485 (setq desktop-delay-hook nil)
|
|
486 (message "Desktop loaded."))
|
|
487 (desktop-clear)))))
|
0
|
488 ;; ----------------------------------------------------------------------------
|
|
489 (defun desktop-load-default ()
|
|
490 "Load the `default' start-up library manually.
|
|
491 Also inhibit further loading of it. Call this from your `.emacs' file
|
|
492 to provide correct modes for autoloaded files."
|
|
493 (if (not inhibit-default-init) ; safety check
|
|
494 (progn
|
|
495 (load "default" t t)
|
|
496 (setq inhibit-default-init t))))
|
|
497 ;; ----------------------------------------------------------------------------
|
|
498 ;; Note: the following functions use the dynamic variable binding in Lisp.
|
|
499 ;;
|
|
500 (defun desktop-buffer-info () "Load an info file."
|
2
|
501 (if (eq 'Info-mode desktop-buffer-major-mode)
|
0
|
502 (progn
|
|
503 (require 'info)
|
2
|
504 (Info-find-node (nth 0 desktop-buffer-misc)
|
|
505 (nth 1 desktop-buffer-misc))
|
0
|
506 t)))
|
|
507 ;; ----------------------------------------------------------------------------
|
|
508 (defun desktop-buffer-rmail () "Load an RMAIL file."
|
2
|
509 (if (eq 'rmail-mode desktop-buffer-major-mode)
|
0
|
510 (condition-case error
|
2
|
511 (progn (rmail-input desktop-buffer-file-name) t)
|
0
|
512 (file-locked
|
|
513 (kill-buffer (current-buffer))
|
|
514 'ignored))))
|
|
515 ;; ----------------------------------------------------------------------------
|
|
516 (defun desktop-buffer-mh () "Load a folder in the mh system."
|
2
|
517 (if (eq 'mh-folder-mode desktop-buffer-major-mode)
|
0
|
518 (progn
|
|
519 (require 'mh-e)
|
|
520 (mh-find-path)
|
2
|
521 (mh-visit-folder desktop-buffer-name)
|
0
|
522 t)))
|
|
523 ;; ----------------------------------------------------------------------------
|
|
524 (defun desktop-buffer-dired () "Load a directory using dired."
|
2
|
525 (if (eq 'dired-mode desktop-buffer-major-mode)
|
|
526 (if (file-directory-p (file-name-directory (car desktop-buffer-misc)))
|
0
|
527 (progn
|
2
|
528 (dired (car desktop-buffer-misc))
|
|
529 (mapcar 'dired-insert-subdir (cdr desktop-buffer-misc))
|
0
|
530 t)
|
2
|
531 (message "Directory %s no longer exists." (car desktop-buffer-misc))
|
0
|
532 (sit-for 1)
|
|
533 'ignored)))
|
|
534 ;; ----------------------------------------------------------------------------
|
|
535 (defun desktop-buffer-file () "Load a file."
|
2
|
536 (if desktop-buffer-file-name
|
|
537 (if (or (file-exists-p desktop-buffer-file-name)
|
0
|
538 (and desktop-missing-file-warning
|
|
539 (y-or-n-p (format
|
|
540 "File \"%s\" no longer exists. Re-create? "
|
2
|
541 desktop-buffer-file-name))))
|
|
542 (progn (find-file desktop-buffer-file-name) t)
|
0
|
543 'ignored)))
|
|
544 ;; ----------------------------------------------------------------------------
|
|
545 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file
|
|
546 ;; only.
|
2
|
547 (defun desktop-create-buffer (ver desktop-buffer-file-name desktop-buffer-name
|
|
548 desktop-buffer-major-mode
|
|
549 mim pt mk ro desktop-buffer-misc
|
|
550 &optional locals)
|
0
|
551 (let ((hlist desktop-buffer-handlers)
|
|
552 (result)
|
|
553 (handler))
|
|
554 (while (and (not result) hlist)
|
|
555 (setq handler (car hlist))
|
|
556 (setq result (funcall handler))
|
|
557 (setq hlist (cdr hlist)))
|
|
558 (if (eq result t)
|
|
559 (progn
|
2
|
560 (if (not (equal (buffer-name) desktop-buffer-name))
|
|
561 (rename-buffer desktop-buffer-name))
|
0
|
562 (auto-fill-mode (if (nth 0 mim) 1 0))
|
|
563 (goto-char pt)
|
|
564 (if (consp mk)
|
|
565 (progn
|
|
566 (set-mark (car mk))
|
|
567 ;; (setq mark-active (car (cdr mk))))
|
|
568 (if (car (cdr mk)) (zmacs-activate-region))) ; XEmacs
|
|
569 (set-mark mk))
|
|
570 ;; Never override file system if the file really is read-only marked.
|
|
571 (if ro (setq buffer-read-only ro))
|
|
572 (while locals
|
|
573 (let ((this (car locals)))
|
|
574 (if (consp this)
|
|
575 ;; an entry of this form `(symbol . value)'
|
|
576 (progn
|
|
577 (make-local-variable (car this))
|
|
578 (set (car this) (cdr this)))
|
|
579 ;; an entry of the form `symbol'
|
|
580 (make-local-variable this)
|
|
581 (makunbound this)))
|
|
582 (setq locals (cdr locals)))
|
|
583 ))))
|
|
584
|
|
585 ;; Backward compatibility -- update parameters to 205 standards.
|
2
|
586 (defun desktop-buffer (desktop-buffer-file-name desktop-buffer-name
|
|
587 desktop-buffer-major-mode
|
|
588 mim pt mk ro tl fc cfs cr
|
|
589 desktop-buffer-misc)
|
|
590 (desktop-create-buffer 205 desktop-buffer-file-name desktop-buffer-name
|
|
591 desktop-buffer-major-mode (cdr mim) pt mk ro
|
|
592 desktop-buffer-misc
|
0
|
593 (list (cons 'truncate-lines tl)
|
|
594 (cons 'fill-column fc)
|
|
595 (cons 'case-fold-search cfs)
|
|
596 (cons 'case-replace cr)
|
|
597 (cons 'overwrite-mode (car mim)))))
|
|
598 ;; ----------------------------------------------------------------------------
|
|
599 (provide 'desktop)
|
|
600
|
|
601 ;; desktop.el ends here.
|