Mercurial > emacs
annotate lisp/desktop.el @ 5104:bcf4b8ed1c60
(inferior-lisp-proc): Clean up error message.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 22 Nov 1993 00:42:30 +0000 |
parents | a61307ac474e |
children | e65e125e5334 |
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> | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
6 ;; Version: 2.02 |
3404 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
26 ;; Save the Desktop, i.e., |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
27 ;; - some global variables |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
28 ;; - 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
|
29 ;; - the major mode |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
30 ;; - the default directory |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
31 ;; - the point |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
32 ;; - the mark & mark-active |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
33 ;; - buffer-read-only |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
34 ;; - truncate-lines |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
35 ;; - case-fold-search |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
36 ;; - case-replace |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
37 ;; - fill-column |
3404 | 38 |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
39 ;; 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
|
40 ;; file (the later the better): |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
41 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
42 ;; (load "desktop") |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
43 ;; (desktop-load-default) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
44 ;; (desktop-read) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
45 ;; |
3404 | 46 |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
47 ;; 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
|
48 ;; 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
|
49 ;; 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
|
50 ;; 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
|
51 ;; 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
|
52 ;; left them. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
53 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
54 ;; 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
|
55 ;; `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
|
56 ;; 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
|
57 ;; |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
58 ;; 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
|
59 ;; 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
|
60 ;; 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
|
61 ;; --------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
62 ;; TODO: |
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 ;; Save window configuration. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
65 ;; Recognize more minor modes. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
66 ;; Save mark rings. |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
67 ;; Start-up with buffer-menu??? |
3404 | 68 |
69 ;;; Code: | |
70 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
71 ;; 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
|
72 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
73 (defconst desktop-basefilename |
3404 | 74 (if (equal system-type 'ms-dos) |
75 "emacs.dsk" ; Ms-Dos does not support multiple dots in file name | |
76 ".emacs.desktop") | |
77 "File for Emacs desktop. A directory name will be prepended to this name.") | |
78 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
79 (defvar desktop-missing-file-warning t |
3404 | 80 "*If non-nil then issue warning if a file no longer exists. |
81 Otherwise simply ignore the file.") | |
82 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
83 (defvar desktop-globals-to-save |
3404 | 84 (list 'desktop-missing-file-warning |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
85 ;; 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
|
86 ;; 'kill-ring |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
87 'tags-file-name |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
88 'tags-table-list |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
89 ;; 'desktop-globals-to-save ; Itself! |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
90 ) |
3404 | 91 "List of global variables to save when killing Emacs.") |
92 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
93 ;; 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
|
94 ;; (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
|
95 ;; TAGS files to save time (tags-file-name is saved instead). |
3404 | 96 (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
|
97 "\\(\\.log\\|(ftp)\\|^tags\\|^TAGS\\)$" |
3404 | 98 "Regexp identifying buffers that are to be excluded from saving.") |
99 | |
100 (defvar desktop-buffer-handlers | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
101 '(desktop-buffer-dired |
3404 | 102 desktop-buffer-rmail |
103 desktop-buffer-info | |
104 desktop-buffer-file) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
105 "*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
|
106 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
|
107 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
|
108 `dd'. If some function returns non-nil no further functions are called. |
3404 | 109 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
|
110 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
111 (defvar desktop-dirname nil |
3404 | 112 "The directory in which the current desktop file resides.") |
113 | |
114 (defconst desktop-header | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
115 ";; -------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
116 ;; Desktop File for Emacs |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
117 ;; -------------------------------------------------------------------------- |
3404 | 118 " "*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
|
119 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
120 (defconst postv18 |
3404 | 121 (string-lessp "19" emacs-version) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
122 "t if Emacs version 19 or later.") |
3404 | 123 |
124 (defun desktop-clear () "Empty the Desktop." | |
125 (interactive) | |
126 (setq kill-ring nil) | |
127 (setq kill-ring-yank-pointer nil) | |
128 (mapcar (function kill-buffer) (buffer-list))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
129 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
130 ;; 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
|
131 ;; toilet-trained considering hooks. |
3404 | 132 (if (not (boundp 'desktop-kill)) |
133 (if postv18 | |
134 (add-hook 'kill-emacs-hook 'desktop-kill) | |
135 (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
|
136 (setq kill-emacs-hook |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
137 (function (lambda () |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
138 (progn (desktop-kill) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
139 (if (or (null old-kill-emacs) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
140 (symbolp old-kill-emacs)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
141 (run-hooks old-kill-emacs) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
142 (funcall old-kill-emacs)))))))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
143 ;; ---------------------------------------------------------------------------- |
3404 | 144 (defun desktop-kill () |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
145 (if desktop-dirname |
3404 | 146 (progn |
147 (desktop-save desktop-dirname)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
148 ;; ---------------------------------------------------------------------------- |
3404 | 149 (defun desktop-outvar (VAR) |
150 "Output a setq statement for VAR to the desktop file." | |
151 (if (boundp VAR) | |
152 (progn | |
153 (insert "(setq ") | |
154 (prin1 VAR (current-buffer)) | |
155 (insert " '") | |
156 (prin1 (symbol-value VAR) (current-buffer)) | |
157 (insert ")\n")))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
158 ;; ---------------------------------------------------------------------------- |
3404 | 159 (defun desktop-save-buffer-p (filename bufname mode) |
160 "Return t if 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
|
161 FILENAME is the visited file name, BUFNAME is the buffer name, and |
3404 | 162 MODE is the major mode." |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
163 |
3404 | 164 (or (and filename |
165 (not (string-match desktop-buffers-not-to-save bufname))) | |
166 (and (null filename) | |
167 (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
|
168 ;; ---------------------------------------------------------------------------- |
3404 | 169 (defun desktop-save (dirname) |
170 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." | |
171 (interactive "DDirectory to save desktop file in: ") | |
172 (save-excursion | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
173 (let ((filename (expand-file-name |
3404 | 174 (concat dirname desktop-basefilename))) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
175 (info (nreverse |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
176 (mapcar |
3404 | 177 (function (lambda (b) |
178 (set-buffer b) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
179 (list |
3404 | 180 (buffer-file-name) |
181 (buffer-name) | |
182 (list 'quote major-mode) | |
183 (list 'quote | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
184 (list overwrite-mode |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
185 (not (null |
3404 | 186 (if postv18 |
187 auto-fill-function | |
188 auto-fill-hook))))) | |
189 (point) | |
190 (if postv18 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
191 (list 'quote (mark t) mark-active) |
3404 | 192 (mark)) |
193 buffer-read-only | |
194 truncate-lines | |
195 fill-column | |
196 case-fold-search | |
197 case-replace | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
198 (list |
3404 | 199 'quote |
200 (cond ((equal major-mode 'Info-mode) | |
201 (list Info-current-file | |
202 Info-current-node)) | |
203 ((equal major-mode 'dired-mode) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
204 (if postv18 |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
205 (nreverse |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
206 (mapcar |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
207 (function car) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
208 dired-subdir-alist)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
209 (list default-directory))) |
3404 | 210 )) |
211 ))) | |
212 (buffer-list)))) | |
213 (buf (get-buffer-create "*desktop*"))) | |
214 (set-buffer buf) | |
215 (erase-buffer) | |
216 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
217 (insert desktop-header |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
218 ";; Created " (current-time-string) "\n" |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
219 ";; Emacs version " emacs-version "\n\n" |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
220 ";; Global section:\n") |
3404 | 221 (mapcar (function desktop-outvar) desktop-globals-to-save) |
222 (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
|
223 (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
|
224 (int-to-string |
3404 | 225 (- (length kill-ring) (length kill-ring-yank-pointer))) |
226 " kill-ring))\n")) | |
227 | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
228 (insert "\n;; Buffer section:\n") |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
229 (mapcar |
3404 | 230 (function (lambda (l) |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
231 (if (desktop-save-buffer-p |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
232 (car l) |
3404 | 233 (nth 1 l) |
234 (nth 1 (nth 2 l))) | |
235 (progn | |
236 (insert "(desktop-buffer") | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
237 (mapcar |
3404 | 238 (function (lambda (e) |
239 (insert "\n ") | |
240 (prin1 e (current-buffer)))) | |
241 l) | |
242 (insert ")\n\n"))))) | |
243 info) | |
244 (setq default-directory dirname) | |
245 (if (file-exists-p filename) (delete-file filename)) | |
246 (write-region (point-min) (point-max) filename nil 'nomessage))) | |
247 (setq desktop-dirname dirname)) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
248 ;; ---------------------------------------------------------------------------- |
3404 | 249 (defun desktop-remove () |
250 "Delete the Desktop file and inactivate the desktop system." | |
251 (interactive) | |
252 (if desktop-dirname | |
253 (let ((filename (concat desktop-dirname desktop-basefilename))) | |
254 (if (file-exists-p filename) (delete-file filename)) | |
255 (setq desktop-dirname nil)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
256 ;; ---------------------------------------------------------------------------- |
3404 | 257 (defun desktop-read () |
258 "Read the Desktop file and the files it specifies." | |
259 (interactive) | |
260 (let ((filename)) | |
261 (if (file-exists-p (concat "./" desktop-basefilename)) | |
262 (setq desktop-dirname (expand-file-name "./")) | |
263 (if (file-exists-p (concat "~/" desktop-basefilename)) | |
264 (setq desktop-dirname (expand-file-name "~/")) | |
265 (setq desktop-dirname nil))) | |
266 (if desktop-dirname | |
267 (progn | |
268 (load (concat desktop-dirname desktop-basefilename) t t t) | |
269 (message "Desktop loaded.")) | |
270 (desktop-clear)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
271 ;; ---------------------------------------------------------------------------- |
3404 | 272 (defun desktop-load-default () |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
273 "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
|
274 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
|
275 autoloaded files." |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
276 (if (not inhibit-default-init) ; safety check |
3404 | 277 (progn |
278 (load "default" t t) | |
279 (setq inhibit-default-init t)))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
280 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
281 ;; 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
|
282 ;; 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
|
283 ;; |
3404 | 284 (defun desktop-buffer-info () "Load an info file." |
285 (if (equal 'Info-mode mam) | |
286 (progn | |
287 (require 'info) | |
288 (Info-find-node (nth 0 misc) (nth 1 misc)) | |
289 t))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
290 ;; ---------------------------------------------------------------------------- |
3404 | 291 (defun desktop-buffer-rmail () "Load a RMAIL file." |
292 (if (equal 'rmail-mode mam) | |
293 (progn (rmail-input fn) t))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
294 ;; ---------------------------------------------------------------------------- |
3404 | 295 (defun desktop-buffer-dired () "Load a directory using dired." |
296 (if (equal 'dired-mode mam) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
297 (progn |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
298 (dired (car misc)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
299 (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
|
300 t))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
301 ;; ---------------------------------------------------------------------------- |
3404 | 302 (defun desktop-buffer-file () "Load a file." |
303 (if fn | |
304 (if (or (file-exists-p fn) | |
305 (and desktop-missing-file-warning | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
306 (y-or-n-p (format |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
307 "File \"%s\" no longer exists. Re-create? " |
3404 | 308 fn)))) |
309 (progn (find-file fn) t) | |
310 'ignored))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
311 ;; ---------------------------------------------------------------------------- |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
312 ;; Create a buffer, load its file, set is mode, ...; called from Desktop file |
3404 | 313 ;; only. |
314 (defun desktop-buffer (fn bn mam mim pt mk ro tl fc cfs cr misc) | |
315 (let ((hlist desktop-buffer-handlers) | |
316 (result) | |
317 (handler)) | |
318 (while (and (not result) hlist) | |
319 (setq handler (car hlist)) | |
320 (setq result (funcall handler)) | |
321 (setq hlist (cdr hlist))) | |
322 (if (equal result t) | |
323 (progn | |
324 (if (not (equal (buffer-name) bn)) | |
325 (rename-buffer bn)) | |
326 (if (nth 0 mim) | |
327 (overwrite-mode 1) | |
328 (overwrite-mode 0)) | |
329 (if (nth 1 mim) | |
330 (auto-fill-mode 1) | |
331 (overwrite-mode 0)) | |
332 (goto-char pt) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
333 (if (consp mk) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
334 (progn |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
335 (set-mark (car mk)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
336 (setq mark-active (car (cdr mk)))) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
337 (set-mark mk)) |
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
338 ;; 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
|
339 (if ro (setq buffer-read-only ro)) |
3404 | 340 (setq truncate-lines tl) |
341 (setq fill-column fc) | |
342 (setq case-fold-search cfs) | |
343 (setq case-replace cr) | |
344 )))) | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
345 ;; ---------------------------------------------------------------------------- |
3405 | 346 (provide 'desktop) |
3404 | 347 |
348 ;; desktop.el ends here. | |
4830
a61307ac474e
Internal clean-up. Save information about current
Richard M. Stallman <rms@gnu.org>
parents:
3405
diff
changeset
|
349 |