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