Mercurial > emacs
annotate lisp/desktop.el @ 5427:cde2cde50796
(tex-common-initialization): Make parse-sexp-ignore-comments t.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 03 Jan 1994 20:06:28 +0000 |
parents | e65e125e5334 |
children | 9fcfca1caec7 |
rev | line source |
---|---|
3404 | 1 ;;; desktop.el --- save partial status of Emacs when killed |
2 | |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Morten Welinder <terra@diku.dk> | |
5314 | 6 ;; Version: 2.03 |
7 ;; Keywords: customization | |
8 ;; Favourite-brand-of-beer: None, I hate beer. | |
3404 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
28 ;; Save the Desktop, i.e., |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
29 ;; - some global variables |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
30 ;; - the list of buffers with associated files. For each buffer also |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
31 ;; - the major mode |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
32 ;; - the default directory |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
33 ;; - the point |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
34 ;; - the mark & mark-active |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
35 ;; - buffer-read-only |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
36 ;; - truncate-lines |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
37 ;; - case-fold-search |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
38 ;; - case-replace |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
39 ;; - fill-column |
3404 | 40 |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
41 ;; To use this, first put these three lines in the bottom of your .emacs |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
42 ;; file (the later the better): |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
43 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
44 ;; (load "desktop") |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
45 ;; (desktop-load-default) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
46 ;; (desktop-read) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
47 ;; |
3404 | 48 |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
49 ;; Start Emacs in the root directory of your "project". The desktop saver |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
50 ;; is inactive by default. You activate it by M-x desktop-save RET. When |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
51 ;; you exit the next time the above data will be saved. This ensures that |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
52 ;; all the files you were editing will be reloaded the next time you start |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
53 ;; Emacs from the same directory and that points will be set where you |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
54 ;; left them. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
55 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
56 ;; PLEASE NOTE: The kill ring can be saved as specified by the variable |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
57 ;; `desktop-globals-to-save' (by default it isn't). This may result in saving |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
58 ;; things you did not mean to keep. Use M-x desktop-clear RET. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
59 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
60 ;; Thanks to hetrick@phys.uva.nl (Jim Hetrick) for useful ideas. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
61 ;; avk@rtsg.mot.com (Andrew V. Klein) for a dired tip. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
62 ;; chris@tecc.co.uk (Chris Boucher) for a mark tip. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
63 ;; --------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
64 ;; TODO: |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
65 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
66 ;; Save window configuration. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
67 ;; Recognize more minor modes. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
68 ;; Save mark rings. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
69 ;; Start-up with buffer-menu??? |
3404 | 70 |
71 ;;; Code: | |
72 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
73 ;; USER OPTIONS -- settings you might want to play with. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
74 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
75 (defconst desktop-basefilename |
3404 | 76 (if (equal system-type 'ms-dos) |
77 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name | |
78 ".emacs.desktop") | |
79 "File for Emacs desktop. A directory name will be prepended to this name.") | |
80 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
81 (defvar desktop-missing-file-warning t |
3404 | 82 "*If non-nil then issue warning if a file no longer exists. |
83 Otherwise simply ignore the file.") | |
84 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
85 (defvar desktop-globals-to-save |
3404 | 86 (list 'desktop-missing-file-warning |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
87 ;; Feature: saving kill-ring implies saving kill-ring-yank-pointer |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
88 ;; 'kill-ring |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
89 'tags-file-name |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
90 'tags-table-list |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
91 ;; 'desktop-globals-to-save ; Itself! |
5314 | 92 ) |
3404 | 93 "List of global variables to save when killing Emacs.") |
94 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
95 ;; We skip .log files because they are normally temporary. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
96 ;; (ftp) files because they require passwords and whatsnot. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
97 ;; TAGS files to save time (tags-file-name is saved instead). |
3404 | 98 (defvar desktop-buffers-not-to-save |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
99 "\\(\\.log\\|(ftp)\\|^tags\\|^TAGS\\)$" |
3404 | 100 "Regexp identifying buffers that are to be excluded from saving.") |
101 | |
102 (defvar desktop-buffer-handlers | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
103 '(desktop-buffer-dired |
3404 | 104 desktop-buffer-rmail |
105 desktop-buffer-info | |
106 desktop-buffer-file) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
107 "*List of functions to call in order to create a buffer. The functions are |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
108 called without explicit parameters but may access the the major mode as `mam', |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
109 the file name as `fn', the buffer name as `bn', the default directory as |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
110 `dd'. If some function returns non-nil no further functions are called. |
3404 | 111 If the function returns t then the buffer is considered created.") |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
112 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
113 (defvar desktop-dirname nil |
3404 | 114 "The directory in which the current desktop file resides.") |
115 | |
116 (defconst desktop-header | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
117 ";; -------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
118 ;; Desktop File for Emacs |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
119 ;; -------------------------------------------------------------------------- |
3404 | 120 " "*Header to place in Desktop file.") |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
121 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
122 (defconst postv18 |
3404 | 123 (string-lessp "19" emacs-version) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
124 "t if Emacs version 19 or later.") |
3404 | 125 |
126 (defun desktop-clear () "Empty the Desktop." | |
127 (interactive) | |
128 (setq kill-ring nil) | |
129 (setq kill-ring-yank-pointer nil) | |
5314 | 130 (mapcar (function kill-buffer) (buffer-list)) |
131 (delete-other-windows)) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
132 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
133 ;; This is a bit dirty for version 18 because that version of Emacs was not |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
134 ;; toilet-trained considering hooks. |
3404 | 135 (if (not (boundp 'desktop-kill)) |
136 (if postv18 | |
137 (add-hook 'kill-emacs-hook 'desktop-kill) | |
138 (setq old-kill-emacs kill-emacs-hook) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
139 (setq kill-emacs-hook |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
140 (function (lambda () |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
141 (progn (desktop-kill) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
142 (if (or (null old-kill-emacs) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
143 (symbolp old-kill-emacs)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
144 (run-hooks old-kill-emacs) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
145 (funcall old-kill-emacs)))))))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
146 ;; ---------------------------------------------------------------------------- |
3404 | 147 (defun desktop-kill () |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
148 (if desktop-dirname |
3404 | 149 (progn |
150 (desktop-save desktop-dirname)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
151 ;; ---------------------------------------------------------------------------- |
5314 | 152 (defun desktop-outvar (var) |
3404 | 153 "Output a setq statement for VAR to the desktop file." |
5314 | 154 (if (boundp var) |
155 (let ((print-escape-newlines t) | |
156 (val (symbol-value var))) | |
3404 | 157 (insert "(setq ") |
5314 | 158 (prin1 var (current-buffer)) |
159 ;; symbols are needed for cons cells and for symbols except | |
160 ;; `t' and `nil'. | |
161 (if (or (consp val) | |
162 (and (symbolp val) val (not (eq t val)))) | |
163 (insert " '") | |
164 (insert " ")) | |
165 (prin1 val (current-buffer)) | |
3404 | 166 (insert ")\n")))) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
167 ;; ---------------------------------------------------------------------------- |
3404 | 168 (defun desktop-save-buffer-p (filename bufname mode) |
5314 | 169 "Return t if the desktop should record a particular buffer for next startup. |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
170 FILENAME is the visited file name, BUFNAME is the buffer name, and |
3404 | 171 MODE is the major mode." |
172 (or (and filename | |
173 (not (string-match desktop-buffers-not-to-save bufname))) | |
174 (and (null filename) | |
175 (memq mode '(Info-mode dired-mode rmail-mode))))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
176 ;; ---------------------------------------------------------------------------- |
3404 | 177 (defun desktop-save (dirname) |
178 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." | |
179 (interactive "DDirectory to save desktop file in: ") | |
180 (save-excursion | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
181 (let ((filename (expand-file-name |
3404 | 182 (concat dirname desktop-basefilename))) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
183 (info (nreverse |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
184 (mapcar |
3404 | 185 (function (lambda (b) |
186 (set-buffer b) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
187 (list |
3404 | 188 (buffer-file-name) |
189 (buffer-name) | |
190 (list 'quote major-mode) | |
191 (list 'quote | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
192 (list overwrite-mode |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
193 (not (null |
3404 | 194 (if postv18 |
195 auto-fill-function | |
196 auto-fill-hook))))) | |
197 (point) | |
198 (if postv18 | |
5314 | 199 (list 'quote (list (mark t) mark-active)) |
3404 | 200 (mark)) |
201 buffer-read-only | |
202 truncate-lines | |
203 fill-column | |
204 case-fold-search | |
205 case-replace | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
206 (list |
3404 | 207 'quote |
208 (cond ((equal major-mode 'Info-mode) | |
209 (list Info-current-file | |
210 Info-current-node)) | |
211 ((equal major-mode 'dired-mode) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
212 (if postv18 |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
213 (nreverse |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
214 (mapcar |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
215 (function car) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
216 dired-subdir-alist)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
217 (list default-directory))) |
3404 | 218 )) |
219 ))) | |
220 (buffer-list)))) | |
221 (buf (get-buffer-create "*desktop*"))) | |
222 (set-buffer buf) | |
223 (erase-buffer) | |
224 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
225 (insert desktop-header |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
226 ";; Created " (current-time-string) "\n" |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
227 ";; Emacs version " emacs-version "\n\n" |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
228 ";; Global section:\n") |
3404 | 229 (mapcar (function desktop-outvar) desktop-globals-to-save) |
230 (if (memq 'kill-ring desktop-globals-to-save) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
231 (insert "(setq kill-ring-yank-pointer (nthcdr " |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
232 (int-to-string |
3404 | 233 (- (length kill-ring) (length kill-ring-yank-pointer))) |
234 " kill-ring))\n")) | |
235 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
236 (insert "\n;; Buffer section:\n") |
5314 | 237 (let ((print-escape-newlines t)) |
238 (mapcar | |
239 (function (lambda (l) | |
240 (if (desktop-save-buffer-p | |
241 (car l) | |
242 (nth 1 l) | |
243 (nth 1 (nth 2 l))) | |
244 (progn | |
245 (insert "(desktop-buffer") | |
246 (mapcar | |
247 (function (lambda (e) | |
248 (insert "\n ") | |
249 (prin1 e (current-buffer)))) | |
250 l) | |
251 (insert ")\n\n"))))) | |
252 info)) | |
3404 | 253 (setq default-directory dirname) |
254 (if (file-exists-p filename) (delete-file filename)) | |
255 (write-region (point-min) (point-max) filename nil 'nomessage))) | |
256 (setq desktop-dirname dirname)) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
257 ;; ---------------------------------------------------------------------------- |
3404 | 258 (defun desktop-remove () |
259 "Delete the Desktop file and inactivate the desktop system." | |
260 (interactive) | |
261 (if desktop-dirname | |
262 (let ((filename (concat desktop-dirname desktop-basefilename))) | |
263 (if (file-exists-p filename) (delete-file filename)) | |
264 (setq desktop-dirname nil)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
265 ;; ---------------------------------------------------------------------------- |
3404 | 266 (defun desktop-read () |
267 "Read the Desktop file and the files it specifies." | |
268 (interactive) | |
269 (let ((filename)) | |
270 (if (file-exists-p (concat "./" desktop-basefilename)) | |
271 (setq desktop-dirname (expand-file-name "./")) | |
272 (if (file-exists-p (concat "~/" desktop-basefilename)) | |
273 (setq desktop-dirname (expand-file-name "~/")) | |
274 (setq desktop-dirname nil))) | |
275 (if desktop-dirname | |
276 (progn | |
277 (load (concat desktop-dirname desktop-basefilename) t t t) | |
278 (message "Desktop loaded.")) | |
279 (desktop-clear)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
280 ;; ---------------------------------------------------------------------------- |
3404 | 281 (defun desktop-load-default () |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
282 "Load the `default' start-up library manually. Also inhibit further loading |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
283 of it. Call this from your `.emacs' file to provide correct modes for |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
284 autoloaded files." |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
285 (if (not inhibit-default-init) ; safety check |
3404 | 286 (progn |
287 (load "default" t t) | |
288 (setq inhibit-default-init t)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
289 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
290 ;; Note: the following functions use the dynamic variable binding in Lisp. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
291 ;; The byte compiler may therefore complain of undeclared variables. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
292 ;; |
3404 | 293 (defun desktop-buffer-info () "Load an info file." |
294 (if (equal 'Info-mode mam) | |
295 (progn | |
296 (require 'info) | |
297 (Info-find-node (nth 0 misc) (nth 1 misc)) | |
298 t))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
299 ;; ---------------------------------------------------------------------------- |
5314 | 300 (defun desktop-buffer-rmail () "Load an RMAIL file." |
301 (if (eq 'rmail-mode mam) | |
3404 | 302 (progn (rmail-input fn) t))) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
303 ;; ---------------------------------------------------------------------------- |
3404 | 304 (defun desktop-buffer-dired () "Load a directory using dired." |
5314 | 305 (if (eq 'dired-mode mam) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
306 (progn |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
307 (dired (car misc)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
308 (mapcar (function dired-maybe-insert-subdir) (cdr misc)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
309 t))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
310 ;; ---------------------------------------------------------------------------- |
3404 | 311 (defun desktop-buffer-file () "Load a file." |
312 (if fn | |
313 (if (or (file-exists-p fn) | |
314 (and desktop-missing-file-warning | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
315 (y-or-n-p (format |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
316 "File \"%s\" no longer exists. Re-create? " |
3404 | 317 fn)))) |
318 (progn (find-file fn) t) | |
319 'ignored))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
320 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
321 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file |
3404 | 322 ;; only. |
323 (defun desktop-buffer (fn bn mam mim pt mk ro tl fc cfs cr misc) | |
324 (let ((hlist desktop-buffer-handlers) | |
325 (result) | |
326 (handler)) | |
327 (while (and (not result) hlist) | |
328 (setq handler (car hlist)) | |
329 (setq result (funcall handler)) | |
330 (setq hlist (cdr hlist))) | |
5314 | 331 (if (eq result t) |
3404 | 332 (progn |
333 (if (not (equal (buffer-name) bn)) | |
334 (rename-buffer bn)) | |
335 (if (nth 0 mim) | |
336 (overwrite-mode 1) | |
337 (overwrite-mode 0)) | |
338 (if (nth 1 mim) | |
339 (auto-fill-mode 1) | |
340 (overwrite-mode 0)) | |
341 (goto-char pt) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
342 (if (consp mk) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
343 (progn |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
344 (set-mark (car mk)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
345 (setq mark-active (car (cdr mk)))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
346 (set-mark mk)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
347 ;; Never override file system if the file really is read-only marked. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
348 (if ro (setq buffer-read-only ro)) |
3404 | 349 (setq truncate-lines tl) |
350 (setq fill-column fc) | |
351 (setq case-fold-search cfs) | |
352 (setq case-replace cr) | |
353 )))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
354 ;; ---------------------------------------------------------------------------- |
3405 | 355 (provide 'desktop) |
3404 | 356 |
357 ;; desktop.el ends here. |