100
|
1 ;; -*- Emacs-Lisp -*-
|
|
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3 ;;
|
|
4 ;; File: auto-save.el
|
|
5 ;; Version: $Revision: 1.2 $
|
|
6 ;; RCS:
|
|
7 ;; Description: Safer autosaving with support for efs and /tmp.
|
|
8 ;; This version of auto-save is designed to work with efs,
|
|
9 ;; instead of ange-ftp.
|
|
10 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>,
|
|
11 ;;
|
|
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
0
|
13
|
100
|
14 (defconst auto-save-version (substring "$Revision: 1.2 $" 11 -2)
|
|
15 "Version number of auto-save.")
|
0
|
16
|
100
|
17 ;;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de>
|
|
18
|
|
19 ;;; This program is free software; you can redistribute it and/or modify
|
|
20 ;;; it under the terms of the GNU General Public License as published by
|
|
21 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
22 ;;; any later version.
|
0
|
23
|
100
|
24 ;;; This program is distributed in the hope that it will be useful,
|
|
25 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
27 ;;; GNU General Public License for more details.
|
0
|
28
|
100
|
29 ;;; You should have received a copy of the GNU General Public License
|
|
30 ;;; along with this program; if not, write to the Free Software
|
|
31 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
0
|
32
|
|
33 ;;;; OVERVIEW ==========================================================
|
|
34
|
100
|
35 ;;; Combines autosaving for efs (to a local or remote directory)
|
|
36 ;;; with the ability to do autosaves to a fixed directory on a local
|
|
37 ;;; disk, in case NFS is slow. The auto-save file used for
|
|
38 ;;; /usr/foo/bar/baz.txt
|
|
39 ;;; will be
|
|
40 ;;; AUTOSAVE/#\!usr\!foo\!bar\!baz.txt#
|
|
41 ;;; assuming AUTOSAVE is the non-nil value of the variable
|
|
42 ;;; `auto-save-directory'.
|
0
|
43
|
100
|
44 ;;; Takes care that autosave files for non-file-buffers (e.g. *mail*)
|
|
45 ;;; from two simultaneous Emacses don't collide.
|
0
|
46
|
100
|
47 ;;; Autosaves even if the current directory is not writable.
|
0
|
48
|
100
|
49 ;;; Can limit autosave names to 14 characters using a hash function,
|
|
50 ;;; see `auto-save-hash-p'.
|
0
|
51
|
100
|
52 ;;; See `auto-save-directory' and `make-auto-save-file-name' and
|
|
53 ;;; references therein for complete documentation.
|
0
|
54
|
100
|
55 ;;; Meta-x recover-all-files will effectively do recover-file on all
|
|
56 ;;; files whose autosave file is newer (one of the benefits of having
|
|
57 ;;; all autosave files in the same place).
|
0
|
58
|
|
59 ;;;; INSTALLATION ======================================================
|
|
60
|
100
|
61 ;;; Put this file into your load-path and the following in your ~/.emacs:
|
0
|
62
|
100
|
63 ;;; If you want to autosave in the fixed directory /tmp/USER-autosave/
|
|
64 ;;; (setq auto-save-directory
|
|
65 ;;; (concat "/tmp/" (user-login-name) "-autosave/"))
|
0
|
66
|
100
|
67 ;;; If you don't want to save in /tmp (e.g., because it is swap
|
|
68 ;;; mounted) but rather in ~/autosave/
|
|
69 ;;; (setq auto-save-directory (expand-file-name "~/autosave/"))
|
0
|
70
|
100
|
71 ;;; If you want to save each file in its own directory (the default)
|
|
72 ;;; (setq auto-save-directory nil)
|
|
73 ;;; You still can take advantage of autosaving efs remote files
|
|
74 ;;; in a fixed local directory, `auto-save-directory-fallback' will
|
|
75 ;;; be used.
|
0
|
76
|
100
|
77 ;;; If you want to use 14 character hashed autosave filenames
|
|
78 ;;; (setq auto-save-hash-p t)
|
0
|
79
|
100
|
80 ;;; Finally, put this line after the others in your ~/.emacs:
|
|
81 ;;; (require 'auto-save)
|
0
|
82
|
|
83
|
|
84 ;;;; ACKNOWLEDGEMENT ===================================================
|
|
85
|
100
|
86 ;;; This code is loosely derived from autosave-in-tmp.el by Jamie
|
|
87 ;;; Zawinski <jwz@lucid.com> (the version I had was last modified 22
|
|
88 ;;; dec 90 jwz) and code submitted to ange-ftp-lovers on Sun, 5 Apr
|
|
89 ;;; 92 23:20:47 EDT by drw@BOURBAKI.MIT.EDU (Dale R. Worley).
|
|
90 ;;; auto-save.el tries to cover the functionality of those two
|
|
91 ;;; packages.
|
0
|
92
|
100
|
93 ;;; Valuable comments and help from Dale Worley, Andy Norman, Jamie
|
|
94 ;;; Zawinski and Sandy Rutherford are gratefully acknowledged.
|
|
95
|
|
96 ;;;; PROVISION ========================================================
|
|
97
|
|
98 (provide 'auto-save)
|
0
|
99
|
|
100 ;;;; CUSTOMIZATION =====================================================
|
|
101
|
|
102 (defvar auto-save-directory nil
|
|
103
|
|
104 ;;; Don't make this user-variable-p, it should be set in .emacs and
|
|
105 ;;; left at that. In particular, it should remain constant across
|
|
106 ;;; several Emacs session to make recover-all-files work.
|
|
107
|
|
108 "If non-nil, fixed directory for autosaving: all autosave files go
|
|
109 there. If this directory does not yet exist at load time, it is
|
|
110 created and its mode is set to 0700 so that nobody else can read your
|
|
111 autosave files.
|
|
112
|
|
113 If nil, each autosave files goes into the same directory as its
|
|
114 corresponding visited file.
|
|
115
|
|
116 A non-nil `auto-save-directory' could be on a local disk such as in
|
|
117 /tmp, then auto-saves will always be fast, even if NFS or the
|
|
118 automounter is slow. In the usual case of /tmp being locally mounted,
|
|
119 note that if you run emacs on two different machines, they will not
|
|
120 see each other's auto-save files.
|
|
121
|
|
122 The value \(expand-file-name \"~/autosave/\"\) might be better if /tmp
|
|
123 is mounted from swap (possible in SunOS, type `df /tmp' to find out)
|
|
124 and thus vanishes after a reboot, or if your system is particularly
|
|
125 thorough when cleaning up /tmp, clearing even non-empty subdirectories.
|
|
126
|
100
|
127 It should never be an efs remote filename because that would
|
|
128 defeat `efs-auto-save-remotely'.
|
0
|
129
|
|
130 Unless you set `auto-save-hash-p', you shouldn't set this to a
|
|
131 directory in a filesystem that does not support long filenames, since
|
|
132 a file named
|
|
133
|
|
134 /home/sk/lib/emacs/lisp/auto-save.el
|
|
135
|
|
136 will have a longish filename like
|
|
137
|
|
138 AUTO-SAVE-DIRECTORY/#\\!home\\!sk\\!lib\\!emacs\\!lisp\\!auto-save.el#
|
|
139
|
|
140 as auto save file.
|
|
141
|
100
|
142 See also variables `auto-save-directory-fallback',
|
|
143 `efs-auto-save' and `efs-auto-save-remotely'.")
|
0
|
144
|
|
145 (defvar auto-save-hash-p nil
|
|
146 "If non-nil, hashed autosave names of length 14 are used.
|
|
147 This is to avoid autosave filenames longer than 14 characters.
|
|
148 The directory used is `auto-save-hash-directory' regardless of
|
|
149 `auto-save-directory'.
|
|
150 Hashing defeats `recover-all-files', you have to recover files
|
|
151 individually by doing `recover-file'.")
|
|
152
|
100
|
153 ;;; This defvar is in efs.el now, but doesn't hurt to give it here as
|
|
154 ;;; well so that loading first auto-save.el does not abort.
|
|
155 (or (boundp 'efs-auto-save) (defvar efs-auto-save 0))
|
|
156 (or (boundp 'efs-auto-save-remotely) (defvar efs-auto-save-remotely nil))
|
0
|
157
|
100
|
158 (defvar auto-save-offer-delete nil
|
|
159 "*If non-nil, `recover-all-files' offers to delete autosave files
|
|
160 that are out of date or were dismissed for recovering.
|
|
161 Special value 'always deletes those files silently.")
|
0
|
162
|
|
163 ;;;; end of customization
|
|
164
|
|
165
|
|
166 ;;; Preparations to be done at load time
|
|
167
|
|
168 (defvar auto-save-directory-fallback (expand-file-name "~/autosave/")
|
|
169 ;; not user-variable-p, see above
|
|
170 "Directory used for local autosaving of remote files if
|
100
|
171 both `auto-save-directory' and `efs-auto-save-remotely' are nil.
|
0
|
172 Also used if a working directory to be used for autosaving is not writable.
|
|
173 This *must* always be the name of directory that exists or can be
|
|
174 created by you, never nil.")
|
|
175
|
|
176 (defvar auto-save-hash-directory
|
|
177 (expand-file-name "hash/" (or auto-save-directory
|
|
178 auto-save-directory-fallback))
|
|
179 "If non-nil, directory used for hashed autosave filenames.")
|
|
180
|
|
181 (defun auto-save-check-directory (var)
|
|
182 (let ((dir (symbol-value var)))
|
|
183 (if (null dir)
|
|
184 nil
|
|
185 ;; Expand and store back into the variable
|
|
186 (set var (setq dir (expand-file-name dir)))
|
|
187 ;; Make sure directory exists
|
|
188 (if (file-directory-p dir)
|
|
189 nil
|
|
190 ;; Else we create and chmod 0700 the directory
|
|
191 (setq dir (directory-file-name dir)) ; some systems need this
|
|
192 (if (fboundp 'make-directory) ; V19 or tree dired
|
|
193 (make-directory dir)
|
|
194 (call-process "mkdir" nil nil nil dir))
|
|
195 (set-file-modes dir (* 7 8 8))))))
|
|
196
|
|
197 (mapcar (function auto-save-check-directory)
|
|
198 '(auto-save-directory auto-save-directory-fallback))
|
|
199
|
|
200 (and auto-save-hash-p
|
|
201 (auto-save-check-directory 'auto-save-hash-directory))
|
|
202
|
|
203
|
|
204 ;;; Computing an autosave name for a file and vice versa
|
|
205
|
|
206 (defun make-auto-save-file-name ();; redefines files.el
|
|
207 ;; auto-save-file-name-p need not be redefined.
|
|
208
|
|
209 "Return file name to use for auto-saves of current buffer.
|
|
210 Does not consider `auto-save-visited-file-name'; that is checked
|
|
211 before calling this function.
|
|
212
|
|
213 Offers to autosave all files in the same `auto-save-directory'. All
|
|
214 autosave files can then be recovered at once with function
|
|
215 `recover-all-files'.
|
|
216
|
100
|
217 Takes care to make autosave files for files accessed through efs
|
|
218 be local files if variable `efs-auto-save-remotely' is nil.
|
0
|
219
|
|
220 Takes care of slashes in buffer names to prevent autosave errors.
|
|
221
|
100
|
222 Takes care that autosave files for buffers not visiting any file (such
|
|
223 as `*mail*') from two simultaneous Emacses don't collide by prepending
|
|
224 the Emacs pid.
|
|
225
|
0
|
226 Uses 14 character autosave names if `auto-save-hash-p' is true.
|
|
227
|
|
228 Autosaves even if the current directory is not writable, using
|
|
229 directory `auto-save-directory-fallback'.
|
|
230
|
|
231 You can redefine this for customization (he he :-).
|
|
232 See also function `auto-save-file-name-p'."
|
|
233
|
|
234 ;; We have to be very careful about not signalling an error in this
|
|
235 ;; function since files.el does not provide for this (e.g. find-file
|
|
236 ;; would fail for each new file).
|
|
237
|
|
238 (condition-case error-data
|
100
|
239 (let* ((file-name (or (and (boundp 'buffer-file-truename)
|
|
240 buffer-file-truename
|
|
241 ;; Make sure that the file name is expanded.
|
|
242 (expand-file-name buffer-file-name))
|
|
243 (and buffer-file-name
|
|
244 (expand-file-name buffer-file-name))))
|
0
|
245 ;; So autosavename looks like #%...#, roughly as with the
|
|
246 ;; old make-auto-save-file-name function. The
|
|
247 ;; make-temp-name inserts the pid of this Emacs: this
|
|
248 ;; avoids autosaving from two Emacses into the same file.
|
|
249 ;; It cannot be recovered automatically then because in
|
|
250 ;; the next Emacs session (the one after the crash) the
|
|
251 ;; pid will be different, but file-less buffers like
|
|
252 ;; *mail* must be recovered manually anyway.
|
100
|
253 (name-prefix (if file-name nil (make-temp-name "#%")))
|
0
|
254 (save-name (or file-name
|
|
255 ;; Prevent autosave errors. Buffername
|
|
256 ;; (to become non-dir part of filename) will
|
|
257 ;; be unslashified twice. Don't care.
|
|
258 (auto-save-unslashify-name (buffer-name))))
|
|
259 (remote-p (and (stringp file-name)
|
100
|
260 (fboundp 'efs-ftp-path)
|
|
261 (efs-ftp-path file-name))))
|
0
|
262 ;; Return the appropriate auto save file name:
|
|
263 (expand-file-name;; a buffername needs this, a filename not
|
|
264 (if remote-p
|
100
|
265 (if efs-auto-save-remotely
|
0
|
266 (auto-save-name-in-same-directory save-name)
|
|
267 ;; We have to use the `fixed-directory' now since the
|
|
268 ;; `same-directory' would be remote.
|
|
269 ;; It will use the fallback if needed.
|
|
270 (auto-save-name-in-fixed-directory save-name))
|
|
271 ;; Else it is a local file (or a buffer without a file, hence
|
100
|
272 ;; the name-prefix).
|
0
|
273 ;; Hashed files always go into the special hash dir, never
|
|
274 ;; in the same directory, to make recognizing reliable.
|
|
275 (if (or auto-save-directory auto-save-hash-p)
|
|
276 (auto-save-name-in-fixed-directory save-name name-prefix)
|
|
277 (auto-save-name-in-same-directory save-name name-prefix)))))
|
100
|
278
|
0
|
279 ;; If any error occurs in the above code, return what the old
|
|
280 ;; version of this function would have done. It is not ok to
|
|
281 ;; return nil, e.g., when after-find-file tests
|
|
282 ;; file-newer-than-file-p, nil would bomb.
|
|
283
|
|
284 (error (progn
|
|
285 (message "make-auto-save-file-name %s" error-data)
|
|
286 (sit-for 2)
|
|
287 (if buffer-file-name
|
|
288 (concat (file-name-directory buffer-file-name)
|
|
289 "#"
|
|
290 (file-name-nondirectory buffer-file-name)
|
|
291 "#")
|
|
292 (expand-file-name (concat "#%" (buffer-name) "#")))))))
|
|
293
|
|
294 (defun auto-save-original-name (savename)
|
|
295 "Reverse of `make-auto-save-file-name'.
|
|
296 Returns nil if SAVENAME was not associated with a file (e.g., it came
|
|
297 from an autosaved `*mail*' buffer) or does not appear to be an
|
|
298 autosave file at all.
|
|
299 Hashed files are not understood, see `auto-save-hash-p'."
|
|
300 (let ((basename (file-name-nondirectory savename))
|
|
301 (savedir (file-name-directory savename)))
|
|
302 (cond ((or (not (auto-save-file-name-p basename))
|
|
303 (string-match "^#%" basename))
|
|
304 nil)
|
|
305 ;; now we know it looks like #...# thus substring is safe to use
|
|
306 ((or (equal savedir auto-save-directory) ; 2nd arg may be nil
|
|
307 (equal savedir auto-save-directory-fallback))
|
|
308 ;; it is of the `-fixed-directory' type
|
|
309 (auto-save-slashify-name (substring basename 1 -1)))
|
|
310 (t
|
|
311 ;; else it is of `-same-directory' type
|
|
312 (concat savedir (substring basename 1 -1))))))
|
|
313
|
|
314 (defun auto-save-name-in-fixed-directory (filename &optional prefix)
|
|
315 ;; Unslashify and enclose the whole FILENAME in `#' to make an auto
|
|
316 ;; save file in the auto-save-directory, or if that is nil, in
|
|
317 ;; auto-save-directory-fallback (which must be the name of an
|
|
318 ;; existing directory). If the results would be too long for 14
|
|
319 ;; character filenames, and `auto-save-hash-p' is set, hash FILENAME
|
|
320 ;; into a shorter name.
|
|
321 ;; Optional PREFIX is string to use instead of "#" to prefix name.
|
|
322 (let ((base-name (concat (or prefix "#")
|
|
323 (auto-save-unslashify-name filename)
|
|
324 "#")))
|
|
325 (if (and auto-save-hash-p
|
|
326 auto-save-hash-directory
|
|
327 (> (length base-name) 14))
|
|
328 (expand-file-name (auto-save-cyclic-hash-14 filename)
|
|
329 auto-save-hash-directory)
|
|
330 (expand-file-name base-name
|
|
331 (or auto-save-directory
|
|
332 auto-save-directory-fallback)))))
|
|
333
|
|
334 (defun auto-save-name-in-same-directory (filename &optional prefix)
|
|
335 ;; Enclose the non-directory part of FILENAME in `#' to make an auto
|
|
336 ;; save file in the same directory as FILENAME. But if this
|
|
337 ;; directory is not writable, use auto-save-directory-fallback.
|
|
338 ;; FILENAME is assumed to be in non-directory form (no trailing slash).
|
|
339 ;; It may be a name without a directory part (pesumably it really
|
|
340 ;; comes from a buffer name then), the fallback is used then.
|
|
341 ;; Optional PREFIX is string to use instead of "#" to prefix name.
|
|
342 (let ((directory (file-name-directory filename)))
|
|
343 (or (null directory)
|
|
344 (file-writable-p directory)
|
|
345 (setq directory auto-save-directory-fallback))
|
|
346 (concat directory ; (concat nil) is ""
|
|
347 (or prefix "#")
|
|
348 (file-name-nondirectory filename)
|
|
349 "#")))
|
|
350
|
|
351 (defun auto-save-unslashify-name (s)
|
|
352 ;; "Quote any slashes in string S by replacing them with the two
|
|
353 ;;characters `\\!'.
|
|
354 ;;Also, replace any backslash by double backslash, to make it one-to-one."
|
|
355 (let ((limit 0))
|
|
356 (while (string-match "[/\\]" s limit)
|
|
357 (setq s (concat (substring s 0 (match-beginning 0))
|
|
358 (if (string= (substring s
|
|
359 (match-beginning 0)
|
|
360 (match-end 0))
|
|
361 "/")
|
|
362 "\\!"
|
|
363 "\\\\")
|
|
364 (substring s (match-end 0))))
|
|
365 (setq limit (1+ (match-end 0)))))
|
|
366 s)
|
|
367
|
|
368 (defun auto-save-slashify-name (s)
|
|
369 ;;"Reverse of `auto-save-unslashify-name'."
|
|
370 (let (pos)
|
|
371 (while (setq pos (string-match "\\\\[\\!]" s pos))
|
|
372 (setq s (concat (substring s 0 pos)
|
|
373 (if (eq ?! (aref s (1+ pos))) "/" "\\")
|
|
374 (substring s (+ pos 2)))
|
|
375 pos (1+ pos))))
|
|
376 s)
|
|
377
|
|
378
|
|
379 ;;; Hashing for autosave names
|
|
380
|
|
381 ;;; Hashing function contributed by Andy Norman <ange@hplb.hpl.hp.com>
|
|
382 ;;; based upon C code from pot@fly.cnuce.cnr.IT (Francesco Potorti`).
|
|
383
|
|
384 (defun auto-save-cyclic-hash-14 (s)
|
|
385 ;; "Hash string S into a string of length 14.
|
100
|
386 ;; A 7-bytes cyclic code for burst correction is calculated on a
|
|
387 ;; byte-by-byte basis. The polynomial used is D^7 + D^6 + D^3 +1.
|
0
|
388 ;; The resulting string consists of hexadecimal digits [0-9a-f].
|
|
389 ;; In particular, it contains no slash, so it can be used as autosave name."
|
100
|
390 (let ((crc (make-string 7 0))
|
0
|
391 result)
|
|
392 (mapcar
|
|
393 (function
|
|
394 (lambda (new)
|
100
|
395 (setq new (+ new (aref crc 6)))
|
0
|
396 (aset crc 6 (+ (aref crc 5) new))
|
|
397 (aset crc 5 (aref crc 4))
|
|
398 (aset crc 4 (aref crc 3))
|
|
399 (aset crc 3 (+ (aref crc 2) new))
|
|
400 (aset crc 2 (aref crc 1))
|
|
401 (aset crc 1 (aref crc 0))
|
|
402 (aset crc 0 new)))
|
|
403 s)
|
|
404 (setq result (format "%02x%02x%02x%02x%02x%02x%02x"
|
|
405 (aref crc 0)
|
|
406 (aref crc 1)
|
|
407 (aref crc 2)
|
|
408 (aref crc 3)
|
|
409 (aref crc 4)
|
|
410 (aref crc 5)
|
100
|
411 (aref crc 6)))
|
0
|
412 result))
|
|
413
|
100
|
414 ;; This leaves two characters that could be used to wrap it in `#' or
|
|
415 ;; make two filenames from it: one for autosaving, and another for a
|
|
416 ;; file containing the name of the autosaved filed, to make hashing
|
|
417 ;; reversible.
|
|
418 (defun auto-save-cyclic-hash-12 (s)
|
|
419 "Outputs the 12-characters ascii hex representation of a 6-bytes
|
|
420 cyclic code for burst correction calculated on STRING on a
|
|
421 byte-by-byte basis. The used polynomial is D^6 + D^5 + D^4 + D^3 +1."
|
|
422 (let ((crc (make-string 6 0)))
|
|
423 (mapcar
|
|
424 (function
|
|
425 (lambda (new)
|
|
426 (setq new (+ new (aref crc 5)))
|
|
427 (aset crc 5 (+ (aref crc 4) new))
|
|
428 (aset crc 4 (+ (aref crc 3) new))
|
|
429 (aset crc 3 (+ (aref crc 2) new))
|
|
430 (aset crc 2 (aref crc 1))
|
|
431 (aset crc 1 (aref crc 0))
|
|
432 (aset crc 0 new)))
|
|
433 s)
|
|
434 (format "%02x%02x%02x%02x%02x%02x"
|
|
435 (aref crc 0)
|
|
436 (aref crc 1)
|
|
437 (aref crc 2)
|
|
438 (aref crc 3)
|
|
439 (aref crc 4)
|
|
440 (aref crc 5))))
|
|
441
|
0
|
442
|
|
443
|
|
444 ;;; Recovering files
|
|
445
|
100
|
446 (defun recover-all-files (&optional silent)
|
0
|
447 "Do recover-file for all autosave files which are current.
|
|
448 Only works if you have a non-nil `auto-save-directory'.
|
100
|
449
|
|
450 Optional prefix argument SILENT means to be silent about non-current
|
|
451 autosave files. This is useful if invoked automatically at Emacs
|
|
452 startup.
|
|
453
|
|
454 If `auto-save-offer-delete' is t, this function will offer to delete
|
|
455 old or rejected autosave files.
|
|
456
|
0
|
457 Hashed files (see `auto-save-hash-p') are not understood, use
|
|
458 `recover-file' to recover them individually."
|
100
|
459 (interactive "P")
|
0
|
460 (let ((savefiles (directory-files auto-save-directory t "^#"))
|
|
461 afile ; the auto save file
|
|
462 file ; its original file
|
|
463 (total 0) ; # of files offered to recover
|
|
464 (count 0)) ; # of files actually recovered
|
|
465 (or (equal auto-save-directory auto-save-directory-fallback)
|
|
466 (setq savefiles
|
|
467 (append savefiles
|
|
468 (directory-files auto-save-directory-fallback t "^#"))))
|
|
469 (while savefiles
|
|
470 (setq afile (car savefiles)
|
|
471 file (auto-save-original-name afile)
|
|
472 savefiles (cdr savefiles))
|
|
473 (cond ((and file (not (file-newer-than-file-p afile file)))
|
|
474 (message "autosave file \"%s\" is not current." afile)
|
|
475 (sit-for 2))
|
|
476 (t
|
|
477 (setq total (1+ total))
|
|
478 (with-output-to-temp-buffer "*Directory*"
|
100
|
479 (call-process "ls" nil standard-output nil
|
|
480 "-l" afile (if file (list file))))
|
0
|
481 (if (yes-or-no-p (format "Recover %s from auto save file? "
|
100
|
482 file))
|
0
|
483 (let* ((obuf (current-buffer))
|
|
484 (buf (set-buffer
|
|
485 (if file
|
|
486 (find-file-noselect file t)
|
|
487 (generate-new-buffer "*recovered*"))))
|
|
488 (buffer-read-only nil))
|
|
489 (erase-buffer)
|
|
490 (insert-file-contents afile nil)
|
|
491 (condition-case ()
|
|
492 (after-find-file nil)
|
|
493 (error nil))
|
|
494 (setq buffer-auto-save-file-name nil)
|
|
495 (setq count (1+ count))
|
|
496 (message "\
|
|
497 Auto-save off in buffer \"%s\" till you do M-x auto-save-mode."
|
|
498 (buffer-name))
|
|
499 (set-buffer obuf)
|
100
|
500 (sit-for 1))
|
|
501 ;; If not used for recovering, offer to delete
|
|
502 ;; autosave file
|
|
503 (and auto-save-offer-delete
|
|
504 (or (eq 'always auto-save-offer-delete)
|
|
505 (yes-or-no-p
|
|
506 (format "Delete autosave file for `%s'? " file)))
|
|
507 (delete-file afile))))))
|
0
|
508 (if (zerop total)
|
100
|
509 (or silent (message "Nothing to recover."))
|
0
|
510 (message "%d/%d file%s recovered." count total (if (= count 1) "" "s"))))
|
|
511 (if (get-buffer "*Directory*") (kill-buffer "*Directory*")))
|
|
512
|
100
|
513 ;;; end of auto-save.el
|