aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-10-07 16:50:26 +0000
committerRichard M. Stallman1993-10-07 16:50:26 +0000
commit0b9bd5040cff82bde56f1bcc59f60437ffc9a969 (patch)
tree217143f3cf471a512b5382cddd4c5a8b0879418a
parent665eef22904a63d8e4e418ad0b15aed1b33a938f (diff)
downloademacs-0b9bd5040cff82bde56f1bcc59f60437ffc9a969.tar.gz
emacs-0b9bd5040cff82bde56f1bcc59f60437ffc9a969.zip
Internal clean-up. Save information about current
tags files, don't save the tags buffers (to save reload time). Don't save desktop-globals-to-save (desktop files must be erased for this to take effect, sorry.) Save "mark-activity" and allow multi-dir direds.
-rw-r--r--lisp/desktop.el279
1 files changed, 142 insertions, 137 deletions
diff --git a/lisp/desktop.el b/lisp/desktop.el
index 4191788091d..405f6a243fe 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -3,7 +3,7 @@
3;; Copyright (C) 1993 Free Software Foundation, Inc. 3;; Copyright (C) 1993 Free Software Foundation, Inc.
4 4
5;; Author: Morten Welinder <terra@diku.dk> 5;; Author: Morten Welinder <terra@diku.dk>
6;; Version: 2.01 6;; Version: 2.02
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
9 9
@@ -23,139 +23,129 @@
23 23
24;;; Commentary: 24;;; Commentary:
25 25
26; Save the Desktop, i.e., 26;; Save the Desktop, i.e.,
27; - some global variables 27;; - some global variables
28; - the list of buffers with associated files. For each buffer also 28;; - the list of buffers with associated files. For each buffer also
29; - the major mode 29;; - the major mode
30; - the default directory 30;; - the default directory
31; - the point 31;; - the point
32; - the mark 32;; - the mark & mark-active
33; - buffer-read-only 33;; - buffer-read-only
34; - truncate-lines 34;; - truncate-lines
35; - case-fold-search 35;; - case-fold-search
36; - case-replace 36;; - case-replace
37; - fill-column 37;; - fill-column
38 38
39; To use this, first put these three lines in the bottom of your .emacs 39;; To use this, first put these three lines in the bottom of your .emacs
40; file (the later the better): 40;; file (the later the better):
41; 41;;
42; (load "desktop") 42;; (load "desktop")
43; (desktop-load-default) 43;; (desktop-load-default)
44; (desktop-read) 44;; (desktop-read)
45; 45;;
46 46
47; Start Emacs in the root directory of your "project". The desktop saver 47;; Start Emacs in the root directory of your "project". The desktop saver
48; is inactive by default. You activate it by M-X desktop-save RET. When 48;; is inactive by default. You activate it by M-x desktop-save RET. When
49; you exit the next time the above data will be saved. This ensures that 49;; you exit the next time the above data will be saved. This ensures that
50; all the files you were editing will be reloaded the next time you start 50;; all the files you were editing will be reloaded the next time you start
51; Emacs from the same directory and that points will be set where you 51;; Emacs from the same directory and that points will be set where you
52; left them. 52;; left them.
53; 53;;
54; PLEASE NOTE: When the kill ring is saved as specified by the variable 54;; PLEASE NOTE: The kill ring can be saved as specified by the variable
55; `desktop-globals-to-save' (by default it isn't). This may result in saving 55;; `desktop-globals-to-save' (by default it isn't). This may result in saving
56; things you did not mean to keep. Use M-X desktop-clear RET. 56;; things you did not mean to keep. Use M-x desktop-clear RET.
57; 57;;
58; Thanks to hetrick@phys.uva.nl (Jim Hetrick) for useful ideas. 58;; Thanks to hetrick@phys.uva.nl (Jim Hetrick) for useful ideas.
59; --------------------------------------------------------------------------- 59;; avk@rtsg.mot.com (Andrew V. Klein) for a dired tip.
60; HISTORY: 60;; chris@tecc.co.uk (Chris Boucher) for a mark tip.
61; 61;; ---------------------------------------------------------------------------
62; Dec , 1992: Version 1.0 written; never released. 62;; TODO:
63; Jan , 1993: Minor modes now saved: auto-fill-mode, overwrite-mode. 63;;
64; Apr 26, 1993: Version 1.1 released. 64;; Save window configuration.
65; Apr 29, 1993: Now supports RMAIL, Info, and dired modes. 65;; Recognize more minor modes.
66; Will now search home directory for desktop file. 66;; Save mark rings.
67; desktop-save asks for directory to save in. 67;; Start-up with buffer-menu???
68; May 31, 1993: Version 1.3
69; Now works with Emacs 19.
70; Jun 1, 1993: Minor bug fix.
71;
72; TODO:
73;
74; Save window configuration.
75; Recognize more minor modes.
76; Save mark rings.
77; Start-up with buffer-menu???
78 68
79;;; Code: 69;;; Code:
80 70
81; USER OPTIONS -- settings you might want to play with. 71;; USER OPTIONS -- settings you might want to play with.
82; ----------------------------------------------------------------------------- 72;; ----------------------------------------------------------------------------
83(defconst desktop-basefilename 73(defconst desktop-basefilename
84 (if (equal system-type 'ms-dos) 74 (if (equal system-type 'ms-dos)
85 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name 75 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name
86 ".emacs.desktop") 76 ".emacs.desktop")
87 "File for Emacs desktop. A directory name will be prepended to this name.") 77 "File for Emacs desktop. A directory name will be prepended to this name.")
88 78
89(defvar desktop-missing-file-warning t 79(defvar desktop-missing-file-warning t
90 "*If non-nil then issue warning if a file no longer exists. 80 "*If non-nil then issue warning if a file no longer exists.
91Otherwise simply ignore the file.") 81Otherwise simply ignore the file.")
92 82
93(defvar desktop-globals-to-save 83(defvar desktop-globals-to-save
94 (list 'desktop-missing-file-warning 84 (list 'desktop-missing-file-warning
95 ; 'kill-ring ; Feature: Also saves kill-ring-yank-pointer 85 ;; Feature: saving kill-ring implies saving kill-ring-yank-pointer
96 'desktop-globals-to-save) ; Itself! 86 ;; 'kill-ring
87 'tags-file-name
88 'tags-table-list
89 ;; 'desktop-globals-to-save ; Itself!
90 )
97 "List of global variables to save when killing Emacs.") 91 "List of global variables to save when killing Emacs.")
98 92
93;; We skip .log files because they are normally temporary.
94;; (ftp) files because they require passwords and whatsnot.
95;; TAGS files to save time (tags-file-name is saved instead).
99(defvar desktop-buffers-not-to-save 96(defvar desktop-buffers-not-to-save
100 "\\(\\.log\\|(ftp)\\)$" 97 "\\(\\.log\\|(ftp)\\|^tags\\|^TAGS\\)$"
101 "Regexp identifying buffers that are to be excluded from saving.") 98 "Regexp identifying buffers that are to be excluded from saving.")
102 99
103(defvar desktop-buffer-handlers 100(defvar desktop-buffer-handlers
104 '(desktop-buffer-dired 101 '(desktop-buffer-dired
105 desktop-buffer-rmail 102 desktop-buffer-rmail
106 desktop-buffer-info 103 desktop-buffer-info
107 desktop-buffer-file) 104 desktop-buffer-file)
108 "*List of functions to call in order to create a buffer. 105 "*List of functions to call in order to create a buffer. The functions are
109The functions are called without parameters 106called without explicit parameters but may access the the major mode as `mam',
110but may access the the major mode as `mam', 107the file name as `fn', the buffer name as `bn', the default directory as
111the file name as `fn', the buffer name as `bn', the default directory as 108`dd'. If some function returns non-nil no further functions are called.
112`dd'. If some function returns non-nil no further functions are called.
113If the function returns t then the buffer is considered created.") 109If the function returns t then the buffer is considered created.")
114; --------------------------------------------------------------------------- 110;; ----------------------------------------------------------------------------
115(defvar desktop-dirname nil 111(defvar desktop-dirname nil
116 "The directory in which the current desktop file resides.") 112 "The directory in which the current desktop file resides.")
117 113
118(defconst desktop-header 114(defconst desktop-header
119"; --------------------------------------------------------------------------- 115";; --------------------------------------------------------------------------
120; Desktop File for Emacs 116;; Desktop File for Emacs
121; --------------------------------------------------------------------------- 117;; --------------------------------------------------------------------------
122" "*Header to place in Desktop file.") 118" "*Header to place in Desktop file.")
123; --------------------------------------------------------------------------- 119;; ----------------------------------------------------------------------------
124(defconst postv18 120(defconst postv18
125 (string-lessp "19" emacs-version) 121 (string-lessp "19" emacs-version)
126 "t is Emacs version 19 or later.") 122 "t if Emacs version 19 or later.")
127 123
128(defun desktop-clear () "Empty the Desktop." 124(defun desktop-clear () "Empty the Desktop."
129 (interactive) 125 (interactive)
130 (setq kill-ring nil) 126 (setq kill-ring nil)
131 (setq kill-ring-yank-pointer nil) 127 (setq kill-ring-yank-pointer nil)
132 (mapcar (function kill-buffer) (buffer-list))) 128 (mapcar (function kill-buffer) (buffer-list)))
133; --------------------------------------------------------------------------- 129;; ----------------------------------------------------------------------------
130;; This is a bit dirty for version 18 because that version of Emacs was not
131;; toilet-trained considering hooks.
134(if (not (boundp 'desktop-kill)) 132(if (not (boundp 'desktop-kill))
135 (if postv18 133 (if postv18
136 (add-hook 'kill-emacs-hook 'desktop-kill) 134 (add-hook 'kill-emacs-hook 'desktop-kill)
137 (setq old-kill-emacs kill-emacs-hook) 135 (setq old-kill-emacs kill-emacs-hook)
138 (setq kill-emacs-hook 136 (setq kill-emacs-hook
139 (function (lambda () (progn (desktop-kill) 137 (function (lambda ()
140 (run-hooks old-kill-emacs))))))) 138 (progn (desktop-kill)
141; --------------------------------------------------------------------------- 139 (if (or (null old-kill-emacs)
140 (symbolp old-kill-emacs))
141 (run-hooks old-kill-emacs)
142 (funcall old-kill-emacs))))))))
143;; ----------------------------------------------------------------------------
142(defun desktop-kill () 144(defun desktop-kill ()
143 (if desktop-dirname 145 (if desktop-dirname
144 (progn 146 (progn
145 (desktop-save desktop-dirname)))) 147 (desktop-save desktop-dirname))))
146 148;; ----------------------------------------------------------------------------
147;(defun kill-emacs (&optional query)
148; "End this Emacs session.
149;Prefix ARG or optional first ARG non-nil means exit with no questions asked,
150;even if there are unsaved buffers. If Emacs is running non-interactively
151;and ARG is an integer, then Emacs exits with ARG as its exit code.
152;
153;If the variable `desktop-dirname' is non-nil,
154;the function desktop-save will be called first."
155; (interactive "P")
156; (if desktop-dirname (desktop-save desktop-dirname))
157; (original-kill-emacs query))
158; ---------------------------------------------------------------------------
159(defun desktop-outvar (VAR) 149(defun desktop-outvar (VAR)
160 "Output a setq statement for VAR to the desktop file." 150 "Output a setq statement for VAR to the desktop file."
161 (if (boundp VAR) 151 (if (boundp VAR)
@@ -165,53 +155,58 @@ If the function returns t then the buffer is considered created.")
165 (insert " '") 155 (insert " '")
166 (prin1 (symbol-value VAR) (current-buffer)) 156 (prin1 (symbol-value VAR) (current-buffer))
167 (insert ")\n")))) 157 (insert ")\n"))))
168; --------------------------------------------------------------------------- 158;; ----------------------------------------------------------------------------
169(defun desktop-save-buffer-p (filename bufname mode) 159(defun desktop-save-buffer-p (filename bufname mode)
170 "Return t if should record a particular buffer for next startup. 160 "Return t if should record a particular buffer for next startup.
171FILENAME is the visited file name, BUFNAME is the buffer name, and 161FILENAME is the visited file name, BUFNAME is the buffer name, and
172MODE is the major mode." 162MODE is the major mode."
173 163
174 (or (and filename 164 (or (and filename
175 (not (string-match desktop-buffers-not-to-save bufname))) 165 (not (string-match desktop-buffers-not-to-save bufname)))
176 (and (null filename) 166 (and (null filename)
177 (memq mode '(Info-mode dired-mode rmail-mode))))) 167 (memq mode '(Info-mode dired-mode rmail-mode)))))
178; --------------------------------------------------------------------------- 168;; ----------------------------------------------------------------------------
179(defun desktop-save (dirname) 169(defun desktop-save (dirname)
180 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." 170 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop."
181 (interactive "DDirectory to save desktop file in: ") 171 (interactive "DDirectory to save desktop file in: ")
182 (save-excursion 172 (save-excursion
183 (let ((filename (expand-file-name 173 (let ((filename (expand-file-name
184 (concat dirname desktop-basefilename))) 174 (concat dirname desktop-basefilename)))
185 (info (nreverse 175 (info (nreverse
186 (mapcar 176 (mapcar
187 (function (lambda (b) 177 (function (lambda (b)
188 (set-buffer b) 178 (set-buffer b)
189 (list 179 (list
190 (buffer-file-name) 180 (buffer-file-name)
191 (buffer-name) 181 (buffer-name)
192 (list 'quote major-mode) 182 (list 'quote major-mode)
193 (list 'quote 183 (list 'quote
194 (list overwrite-mode 184 (list overwrite-mode
195 (not (null 185 (not (null
196 (if postv18 186 (if postv18
197 auto-fill-function 187 auto-fill-function
198 auto-fill-hook))))) 188 auto-fill-hook)))))
199 (point) 189 (point)
200 (if postv18 190 (if postv18
201 (mark t) 191 (list 'quote (mark t) mark-active)
202 (mark)) 192 (mark))
203 buffer-read-only 193 buffer-read-only
204 truncate-lines 194 truncate-lines
205 fill-column 195 fill-column
206 case-fold-search 196 case-fold-search
207 case-replace 197 case-replace
208 (list 198 (list
209 'quote 199 'quote
210 (cond ((equal major-mode 'Info-mode) 200 (cond ((equal major-mode 'Info-mode)
211 (list Info-current-file 201 (list Info-current-file
212 Info-current-node)) 202 Info-current-node))
213 ((equal major-mode 'dired-mode) 203 ((equal major-mode 'dired-mode)
214 (list default-directory)) 204 (if postv18
205 (nreverse
206 (mapcar
207 (function car)
208 dired-subdir-alist))
209 (list default-directory)))
215 )) 210 ))
216 ))) 211 )))
217 (buffer-list)))) 212 (buffer-list))))
@@ -219,27 +214,27 @@ MODE is the major mode."
219 (set-buffer buf) 214 (set-buffer buf)
220 (erase-buffer) 215 (erase-buffer)
221 216
222 (insert desktop-header 217 (insert desktop-header
223 "; Created " (current-time-string) "\n" 218 ";; Created " (current-time-string) "\n"
224 "; Emacs version " emacs-version "\n\n" 219 ";; Emacs version " emacs-version "\n\n"
225 "; Global section:\n") 220 ";; Global section:\n")
226 (mapcar (function desktop-outvar) desktop-globals-to-save) 221 (mapcar (function desktop-outvar) desktop-globals-to-save)
227 (if (memq 'kill-ring desktop-globals-to-save) 222 (if (memq 'kill-ring desktop-globals-to-save)
228 (insert "(setq kill-ring-yank-pointer (nthcdr " 223 (insert "(setq kill-ring-yank-pointer (nthcdr "
229 (int-to-string 224 (int-to-string
230 (- (length kill-ring) (length kill-ring-yank-pointer))) 225 (- (length kill-ring) (length kill-ring-yank-pointer)))
231 " kill-ring))\n")) 226 " kill-ring))\n"))
232 227
233 (insert "\n; Buffer section:\n") 228 (insert "\n;; Buffer section:\n")
234 (mapcar 229 (mapcar
235 (function (lambda (l) 230 (function (lambda (l)
236 (if (desktop-save-buffer-p 231 (if (desktop-save-buffer-p
237 (car l) 232 (car l)
238 (nth 1 l) 233 (nth 1 l)
239 (nth 1 (nth 2 l))) 234 (nth 1 (nth 2 l)))
240 (progn 235 (progn
241 (insert "(desktop-buffer") 236 (insert "(desktop-buffer")
242 (mapcar 237 (mapcar
243 (function (lambda (e) 238 (function (lambda (e)
244 (insert "\n ") 239 (insert "\n ")
245 (prin1 e (current-buffer)))) 240 (prin1 e (current-buffer))))
@@ -250,7 +245,7 @@ MODE is the major mode."
250 (if (file-exists-p filename) (delete-file filename)) 245 (if (file-exists-p filename) (delete-file filename))
251 (write-region (point-min) (point-max) filename nil 'nomessage))) 246 (write-region (point-min) (point-max) filename nil 'nomessage)))
252 (setq desktop-dirname dirname)) 247 (setq desktop-dirname dirname))
253; --------------------------------------------------------------------------- 248;; ----------------------------------------------------------------------------
254(defun desktop-remove () 249(defun desktop-remove ()
255 "Delete the Desktop file and inactivate the desktop system." 250 "Delete the Desktop file and inactivate the desktop system."
256 (interactive) 251 (interactive)
@@ -258,7 +253,7 @@ MODE is the major mode."
258 (let ((filename (concat desktop-dirname desktop-basefilename))) 253 (let ((filename (concat desktop-dirname desktop-basefilename)))
259 (if (file-exists-p filename) (delete-file filename)) 254 (if (file-exists-p filename) (delete-file filename))
260 (setq desktop-dirname nil)))) 255 (setq desktop-dirname nil))))
261; --------------------------------------------------------------------------- 256;; ----------------------------------------------------------------------------
262(defun desktop-read () 257(defun desktop-read ()
263 "Read the Desktop file and the files it specifies." 258 "Read the Desktop file and the files it specifies."
264 (interactive) 259 (interactive)
@@ -273,43 +268,48 @@ MODE is the major mode."
273 (load (concat desktop-dirname desktop-basefilename) t t t) 268 (load (concat desktop-dirname desktop-basefilename) t t t)
274 (message "Desktop loaded.")) 269 (message "Desktop loaded."))
275 (desktop-clear)))) 270 (desktop-clear))))
276; --------------------------------------------------------------------------- 271;; ----------------------------------------------------------------------------
277(defun desktop-load-default () 272(defun desktop-load-default ()
278 "Load the `default' start-up library manually. 273 "Load the `default' start-up library manually. Also inhibit further loading
279Also inhibit further loading of it. 274of it. Call this from your `.emacs' file to provide correct modes for
280Call this from your `.emacs' file 275autoloaded files."
281provide correct modes for autoloaded files." 276 (if (not inhibit-default-init) ; safety check
282 (if (not inhibit-default-init)
283 (progn 277 (progn
284 (load "default" t t) 278 (load "default" t t)
285 (setq inhibit-default-init t)))) 279 (setq inhibit-default-init t))))
286; --------------------------------------------------------------------------- 280;; ----------------------------------------------------------------------------
281;; Note: the following functions use the dynamic variable binding in Lisp.
282;; The byte compiler may therefore complain of undeclared variables.
283;;
287(defun desktop-buffer-info () "Load an info file." 284(defun desktop-buffer-info () "Load an info file."
288 (if (equal 'Info-mode mam) 285 (if (equal 'Info-mode mam)
289 (progn 286 (progn
290 (require 'info) 287 (require 'info)
291 (Info-find-node (nth 0 misc) (nth 1 misc)) 288 (Info-find-node (nth 0 misc) (nth 1 misc))
292 t))) 289 t)))
293; --------------------------------------------------------------------------- 290;; ----------------------------------------------------------------------------
294(defun desktop-buffer-rmail () "Load a RMAIL file." 291(defun desktop-buffer-rmail () "Load a RMAIL file."
295 (if (equal 'rmail-mode mam) 292 (if (equal 'rmail-mode mam)
296 (progn (rmail-input fn) t))) 293 (progn (rmail-input fn) t)))
297; --------------------------------------------------------------------------- 294;; ----------------------------------------------------------------------------
298(defun desktop-buffer-dired () "Load a directory using dired." 295(defun desktop-buffer-dired () "Load a directory using dired."
299 (if (equal 'dired-mode mam) 296 (if (equal 'dired-mode mam)
300 (progn (dired (nth 0 misc)) t))) 297 (progn
301; --------------------------------------------------------------------------- 298 (dired (car misc))
299 (mapcar (function dired-maybe-insert-subdir) (cdr misc))
300 t)))
301;; ----------------------------------------------------------------------------
302(defun desktop-buffer-file () "Load a file." 302(defun desktop-buffer-file () "Load a file."
303 (if fn 303 (if fn
304 (if (or (file-exists-p fn) 304 (if (or (file-exists-p fn)
305 (and desktop-missing-file-warning 305 (and desktop-missing-file-warning
306 (y-or-n-p (format 306 (y-or-n-p (format
307 "File \"%s\" no longer exists. Re-create? " 307 "File \"%s\" no longer exists. Re-create? "
308 fn)))) 308 fn))))
309 (progn (find-file fn) t) 309 (progn (find-file fn) t)
310 'ignored))) 310 'ignored)))
311; --------------------------------------------------------------------------- 311;; ----------------------------------------------------------------------------
312;;Create a buffer, load its file, set is mode, ...; called from Desktop file 312;; Create a buffer, load its file, set is mode, ...; called from Desktop file
313;; only. 313;; only.
314(defun desktop-buffer (fn bn mam mim pt mk ro tl fc cfs cr misc) 314(defun desktop-buffer (fn bn mam mim pt mk ro tl fc cfs cr misc)
315 (let ((hlist desktop-buffer-handlers) 315 (let ((hlist desktop-buffer-handlers)
@@ -330,15 +330,20 @@ provide correct modes for autoloaded files."
330 (auto-fill-mode 1) 330 (auto-fill-mode 1)
331 (overwrite-mode 0)) 331 (overwrite-mode 0))
332 (goto-char pt) 332 (goto-char pt)
333 (set-mark mk) 333 (if (consp mk)
334 (setq buffer-read-only ro) 334 (progn
335 (set-mark (car mk))
336 (setq mark-active (car (cdr mk))))
337 (set-mark mk))
338 ;; Never override file system if the file really is read-only marked.
339 (if ro (setq buffer-read-only ro))
335 (setq truncate-lines tl) 340 (setq truncate-lines tl)
336 (setq fill-column fc) 341 (setq fill-column fc)
337 (setq case-fold-search cfs) 342 (setq case-fold-search cfs)
338 (setq case-replace cr) 343 (setq case-replace cr)
339 )))) 344 ))))
340; --------------------------------------------------------------------------- 345;; ----------------------------------------------------------------------------
341
342(provide 'desktop) 346(provide 'desktop)
343 347
344;; desktop.el ends here. 348;; desktop.el ends here.
349