annotate lisp/packages/desktop.el @ 0:376386a54a3c r19-14

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