Mercurial > hg > xemacs-beta
comparison lisp/packages/auto-save.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 56c54cf7c5b6 |
children | 4be1180a9e89 |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;; -*- Emacs-Lisp -*- | 1 ;;; auto-save.el --- safer auto saving with support for ange-ftp and /tmp |
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2 |
3 ;; | 3 (defconst auto-save-version "cvs ate me") |
4 ;; File: auto-save.el | 4 |
5 ;; Version: $Revision: 1.4 $ | 5 ;;;; Copyright (C) 1992, 1993, 1994 by Sebastian Kremer <sk@thp.uni-koeln.de> |
6 ;; RCS: | 6 ;;;; Modified by jwz |
7 ;; Description: Safer autosaving with support for efs and /tmp. | 7 |
8 ;; This version of auto-save is designed to work with efs, | 8 ;; This file is part of XEmacs. |
9 ;; instead of ange-ftp. | 9 |
10 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>, | 10 ;; XEmacs is free software; you can redistribute it and/or modify it |
11 ;; | 11 ;; under the terms of the GNU General Public License as published by |
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
13 | 13 ;; any later version. |
14 (defconst auto-save-version (substring "$Revision: 1.4 $" 11 -2) | 14 |
15 "Version number of auto-save.") | 15 ;; XEmacs is distributed in the hope that it will be useful, but |
16 | 16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de> | 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | 18 ;; General Public License for more details. |
19 ;;; This program is free software; you can redistribute it and/or modify | 19 |
20 ;;; it under the terms of the GNU General Public License as published by | 20 ;; You should have received a copy of the GNU General Public License |
21 ;;; the Free Software Foundation; either version 1, or (at your option) | 21 ;; along with XEmacs; see the file COPYING. If not, write to the |
22 ;;; any later version. | 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
23 | 23 ;; Boston, MA 02111-1307, USA. |
24 ;;; This program is distributed in the hope that it will be useful, | 24 |
25 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 25 ;;; Synched up with: Not in FSF. |
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 26 |
27 ;;; GNU General Public License for more details. | 27 ;;;; LISPDIR ENTRY for the Elisp Archive =============================== |
28 | 28 ;;;; LCD Archive Entry: |
29 ;;; You should have received a copy of the GNU General Public License | 29 ;;;; auto-save|Sebastian Kremer|sk@thp.uni-koeln.de |
30 ;;; along with this program; if not, write to the Free Software | 30 ;;;; |safer auto saving with support for ange-ftp and /tmp |
31 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
32 | 31 |
33 ;;;; OVERVIEW ========================================================== | 32 ;;;; OVERVIEW ========================================================== |
34 | 33 |
35 ;;; Combines autosaving for efs (to a local or remote directory) | 34 ;;;; Combines autosaving for ange-ftp (to a local or remote directory) |
36 ;;; with the ability to do autosaves to a fixed directory on a local | 35 ;;;; 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 | 36 ;;;; disk, in case NFS is slow. The auto-save file used for |
38 ;;; /usr/foo/bar/baz.txt | 37 ;;;; /usr/foo/bar/baz.txt |
39 ;;; will be | 38 ;;;; will be |
40 ;;; AUTOSAVE/#\!usr\!foo\!bar\!baz.txt# | 39 ;;;; AUTOSAVE/#\!usr\!foo\!bar\!baz.txt# |
41 ;;; assuming AUTOSAVE is the non-nil value of the variable | 40 ;;;; assuming AUTOSAVE is the non-nil value of the variable |
42 ;;; `auto-save-directory'. | 41 ;;;; `auto-save-directory'. |
43 | 42 |
44 ;;; Takes care that autosave files for non-file-buffers (e.g. *mail*) | 43 ;;;; Takes care that autosave files for non-file-buffers (e.g. *mail*) |
45 ;;; from two simultaneous Emacses don't collide. | 44 ;;;; from two simultaneous Emacses don't collide. |
46 | 45 |
47 ;;; Autosaves even if the current directory is not writable. | 46 ;;;; Autosaves even if the current directory is not writable. |
48 | 47 |
49 ;;; Can limit autosave names to 14 characters using a hash function, | 48 ;;;; Can limit autosave names to 14 characters using a hash function, |
50 ;;; see `auto-save-hash-p'. | 49 ;;;; see `auto-save-hash-p'. |
51 | 50 |
52 ;;; See `auto-save-directory' and `make-auto-save-file-name' and | 51 ;;;; See `auto-save-directory' and `make-auto-save-file-name' and |
53 ;;; references therein for complete documentation. | 52 ;;;; references therein for complete documentation. |
54 | 53 |
55 ;;; Meta-x recover-all-files will effectively do recover-file on all | 54 ;;;; 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 | 55 ;;;; files whose autosave file is newer (one of the benefits of having |
57 ;;; all autosave files in the same place). | 56 ;;;; all autosave files in the same place). |
58 | 57 |
59 ;;;; INSTALLATION ====================================================== | 58 ;;;; INSTALLATION ====================================================== |
60 | 59 |
61 ;;; Put this file into your load-path and the following in your ~/.emacs: | 60 ;;;; Put this file into your load-path and the following in your ~/.emacs: |
62 | 61 |
63 ;;; If you want to autosave in the fixed directory /tmp/USER-autosave/ | 62 ;;;; If you want to autosave in the fixed directory /tmp/USER-autosave/ |
64 ;;; (setq auto-save-directory | 63 ;;;; (setq auto-save-directory |
65 ;;; (concat "/tmp/" (user-login-name) "-autosave/")) | 64 ;;;; (concat "/tmp/" (user-login-name) "-autosave/")) |
66 | 65 |
67 ;;; If you don't want to save in /tmp (e.g., because it is swap | 66 ;;;; If you don't want to save in /tmp (e.g., because it is swap |
68 ;;; mounted) but rather in ~/autosave/ | 67 ;;;; mounted) but rather in ~/autosave/ |
69 ;;; (setq auto-save-directory (expand-file-name "~/autosave/")) | 68 ;;;; (setq auto-save-directory (expand-file-name "~/autosave/")) |
70 | 69 |
71 ;;; If you want to save each file in its own directory (the default) | 70 ;;;; If you want to save each file in its own directory (the default) |
72 ;;; (setq auto-save-directory nil) | 71 ;;;; (setq auto-save-directory nil) |
73 ;;; You still can take advantage of autosaving efs remote files | 72 ;;;; You still can take advantage of autosaving ange-ftp remote files |
74 ;;; in a fixed local directory, `auto-save-directory-fallback' will | 73 ;;;; in a fixed local directory, `auto-save-directory-fallback' will |
75 ;;; be used. | 74 ;;;; be used. |
76 | 75 |
77 ;;; If you want to use 14 character hashed autosave filenames | 76 ;;;; If you want to use 14 character hashed autosave filenames |
78 ;;; (setq auto-save-hash-p t) | 77 ;;;; (setq auto-save-hash-p t) |
79 | 78 |
80 ;;; Finally, put this line after the others in your ~/.emacs: | 79 ;;;; Finally, put this line after the others in your ~/.emacs: |
81 ;;; (require 'auto-save) | 80 ;;;; (require 'auto-save) |
82 | 81 |
83 | 82 |
84 ;;;; ACKNOWLEDGEMENT =================================================== | 83 ;;;; ACKNOWLEDGEMENT =================================================== |
85 | 84 |
86 ;;; This code is loosely derived from autosave-in-tmp.el by Jamie | 85 ;;;; 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 | 86 ;;;; 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 | 87 ;;;; 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). | 88 ;;;; 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 | 89 ;;;; auto-save.el tries to cover the functionality of those two |
91 ;;; packages. | 90 ;;;; packages. |
92 | 91 |
93 ;;; Valuable comments and help from Dale Worley, Andy Norman, Jamie | 92 ;;;; Valuable comments and help from Dale Worley, Andy Norman, Jamie |
94 ;;; Zawinski and Sandy Rutherford are gratefully acknowledged. | 93 ;;;; Zawinski and Sandy Rutherford are gratefully acknowledged. |
95 | |
96 ;;;; PROVISION ======================================================== | |
97 | |
98 (provide 'auto-save) | |
99 | 94 |
100 ;;;; CUSTOMIZATION ===================================================== | 95 ;;;; CUSTOMIZATION ===================================================== |
101 | 96 |
102 (defvar auto-save-directory nil | 97 (defvar auto-save-directory nil |
103 | 98 |
122 The value \(expand-file-name \"~/autosave/\"\) might be better if /tmp | 117 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) | 118 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 | 119 and thus vanishes after a reboot, or if your system is particularly |
125 thorough when cleaning up /tmp, clearing even non-empty subdirectories. | 120 thorough when cleaning up /tmp, clearing even non-empty subdirectories. |
126 | 121 |
127 It should never be an efs remote filename because that would | 122 It should never be an ange-ftp remote filename because that would |
128 defeat `efs-auto-save-remotely'. | 123 defeat `ange-ftp-auto-save-remotely'. |
129 | 124 |
130 Unless you set `auto-save-hash-p', you shouldn't set this to a | 125 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 | 126 directory in a filesystem that does not support long filenames, since |
132 a file named | 127 a file named |
133 | 128 |
137 | 132 |
138 AUTO-SAVE-DIRECTORY/#\\!home\\!sk\\!lib\\!emacs\\!lisp\\!auto-save.el# | 133 AUTO-SAVE-DIRECTORY/#\\!home\\!sk\\!lib\\!emacs\\!lisp\\!auto-save.el# |
139 | 134 |
140 as auto save file. | 135 as auto save file. |
141 | 136 |
142 See also variables `auto-save-directory-fallback', | 137 See also variables `auto-save-directory-fallback', `auto-save-hash-p', |
143 `efs-auto-save' and `efs-auto-save-remotely'.") | 138 `ange-ftp-auto-save' and `ange-ftp-auto-save-remotely'.") |
144 | 139 |
145 (defvar auto-save-hash-p nil | 140 (defvar auto-save-hash-p nil |
146 "If non-nil, hashed autosave names of length 14 are used. | 141 "If non-nil, hashed autosave names of length 14 are used. |
147 This is to avoid autosave filenames longer than 14 characters. | 142 This is to avoid autosave filenames longer than 14 characters. |
148 The directory used is `auto-save-hash-directory' regardless of | 143 The directory used is `auto-save-hash-directory' regardless of |
149 `auto-save-directory'. | 144 `auto-save-directory'. |
150 Hashing defeats `recover-all-files', you have to recover files | 145 Hashing defeats `recover-all-files', you have to recover files |
151 individually by doing `recover-file'.") | 146 individually by doing `recover-file'.") |
152 | 147 |
153 ;;; This defvar is in efs.el now, but doesn't hurt to give it here as | 148 ;;; This defvar is in ange-ftp.el now, but for older versions it |
154 ;;; well so that loading first auto-save.el does not abort. | 149 ;;; doesn't hurt to give it here as well so that loading auto-save.el |
155 (or (boundp 'efs-auto-save) (defvar efs-auto-save 0)) | 150 ;;; does not abort. |
156 (or (boundp 'efs-auto-save-remotely) (defvar efs-auto-save-remotely nil)) | 151 (defvar ange-ftp-auto-save 0 |
157 | 152 "If 1, allows ange-ftp files to be auto-saved. |
158 (defvar auto-save-offer-delete nil | 153 If 0, suppresses auto-saving of ange-ftp files. |
159 "*If non-nil, `recover-all-files' offers to delete autosave files | 154 Don't use any other value.") |
160 that are out of date or were dismissed for recovering. | 155 |
161 Special value 'always deletes those files silently.") | 156 (defvar ange-ftp-auto-save-remotely nil |
157 "*If non-nil, causes the auto-save file for an ange-ftp file to be written in | |
158 the remote directory containing the file, rather than in a local directory. | |
159 | |
160 For remote files, this being true overrides a non-nil | |
161 `auto-save-directory'. Local files are unaffected. | |
162 | |
163 If you want to use this feature, you probably only want to set this | |
164 true in a few buffers, rather than globally. You might want to give | |
165 each buffer its own value using `make-variable-buffer-local'. | |
166 | |
167 See also variable `ange-ftp-auto-save'.") | |
162 | 168 |
163 ;;;; end of customization | 169 ;;;; end of customization |
164 | 170 |
165 | 171 |
166 ;;; Preparations to be done at load time | 172 ;;; Preparations to be done at load time |
167 | 173 |
168 (defvar auto-save-directory-fallback (expand-file-name "~/autosave/") | 174 (defvar auto-save-directory-fallback (expand-file-name "~/autosave/") |
169 ;; not user-variable-p, see above | 175 ;; not user-variable-p, see above |
170 "Directory used for local autosaving of remote files if | 176 "Directory used for local autosaving of remote files if |
171 both `auto-save-directory' and `efs-auto-save-remotely' are nil. | 177 both `auto-save-directory' and `ange-ftp-auto-save-remotely' are nil. |
172 Also used if a working directory to be used for autosaving is not writable. | 178 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 | 179 This *must* always be the name of directory that exists or can be |
174 created by you, never nil.") | 180 created by you, never nil.") |
175 | 181 |
176 (defvar auto-save-hash-directory | 182 (defvar auto-save-hash-directory |
190 ;; Else we create and chmod 0700 the directory | 196 ;; Else we create and chmod 0700 the directory |
191 (setq dir (directory-file-name dir)) ; some systems need this | 197 (setq dir (directory-file-name dir)) ; some systems need this |
192 (if (fboundp 'make-directory) ; V19 or tree dired | 198 (if (fboundp 'make-directory) ; V19 or tree dired |
193 (make-directory dir) | 199 (make-directory dir) |
194 (call-process "mkdir" nil nil nil dir)) | 200 (call-process "mkdir" nil nil nil dir)) |
201 ;; This is 1300, aka "d-wx-----T" | |
202 ;; The sticky bit means that you can only delete your own files, | |
203 ;; even if you have write permission in the directory (which is | |
204 ;; moot, since the directory is only writable by owner.) | |
195 (set-file-modes dir (* 7 8 8)))))) | 205 (set-file-modes dir (* 7 8 8)))))) |
196 | 206 |
197 (mapcar (function auto-save-check-directory) | 207 (mapcar (function auto-save-check-directory) |
198 '(auto-save-directory auto-save-directory-fallback)) | 208 '(auto-save-directory auto-save-directory-fallback)) |
199 | 209 |
212 | 222 |
213 Offers to autosave all files in the same `auto-save-directory'. All | 223 Offers to autosave all files in the same `auto-save-directory'. All |
214 autosave files can then be recovered at once with function | 224 autosave files can then be recovered at once with function |
215 `recover-all-files'. | 225 `recover-all-files'. |
216 | 226 |
217 Takes care to make autosave files for files accessed through efs | 227 Takes care to make autosave files for files accessed through ange-ftp |
218 be local files if variable `efs-auto-save-remotely' is nil. | 228 be local files if variable `ange-ftp-auto-save-remotely' is nil. |
219 | 229 |
220 Takes care of slashes in buffer names to prevent autosave errors. | 230 Takes care of slashes in buffer names to prevent autosave errors. |
221 | |
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 | 231 |
226 Uses 14 character autosave names if `auto-save-hash-p' is true. | 232 Uses 14 character autosave names if `auto-save-hash-p' is true. |
227 | 233 |
228 Autosaves even if the current directory is not writable, using | 234 Autosaves even if the current directory is not writable, using |
229 directory `auto-save-directory-fallback'. | 235 directory `auto-save-directory-fallback'. |
234 ;; We have to be very careful about not signalling an error in this | 240 ;; 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 | 241 ;; function since files.el does not provide for this (e.g. find-file |
236 ;; would fail for each new file). | 242 ;; would fail for each new file). |
237 | 243 |
238 (condition-case error-data | 244 (condition-case error-data |
239 (let* ((file-name (or (and (boundp 'buffer-file-truename) | 245 (let* ((file-name (or (and (boundp 'buffer-file-truename) ; From jwz, |
240 buffer-file-truename | 246 buffer-file-truename) ; for Emacs 19? |
241 ;; Make sure that the file name is expanded. | 247 buffer-file-name)) |
242 (expand-file-name buffer-file-name)) | |
243 (and buffer-file-name | |
244 (expand-file-name buffer-file-name)))) | |
245 ;; So autosavename looks like #%...#, roughly as with the | 248 ;; So autosavename looks like #%...#, roughly as with the |
246 ;; old make-auto-save-file-name function. The | 249 ;; old make-auto-save-file-name function. The |
247 ;; make-temp-name inserts the pid of this Emacs: this | 250 ;; make-temp-name inserts the pid of this Emacs: this |
248 ;; avoids autosaving from two Emacses into the same file. | 251 ;; avoids autosaving from two Emacses into the same file. |
249 ;; It cannot be recovered automatically then because in | 252 ;; It cannot be recovered automatically then because in |
265 ;; Prevent autosave errors. Buffername | 268 ;; Prevent autosave errors. Buffername |
266 ;; (to become non-dir part of filename) will | 269 ;; (to become non-dir part of filename) will |
267 ;; be unslashified twice. Don't care. | 270 ;; be unslashified twice. Don't care. |
268 (auto-save-unslashify-name (buffer-name)))) | 271 (auto-save-unslashify-name (buffer-name)))) |
269 (remote-p (and (stringp file-name) | 272 (remote-p (and (stringp file-name) |
270 (fboundp 'efs-ftp-path) | 273 (fboundp 'ange-ftp-ftp-path) |
271 (efs-ftp-path file-name)))) | 274 (ange-ftp-ftp-path file-name)))) |
272 ;; Return the appropriate auto save file name: | 275 ;; Return the appropriate auto save file name: |
273 (expand-file-name;; a buffername needs this, a filename not | 276 (expand-file-name;; a buffername needs this, a filename not |
274 (if remote-p | 277 (if remote-p |
275 (if efs-auto-save-remotely | 278 (if ange-ftp-auto-save-remotely |
276 (auto-save-name-in-same-directory save-name) | 279 (auto-save-name-in-same-directory save-name) |
277 ;; We have to use the `fixed-directory' now since the | 280 ;; We have to use the `fixed-directory' now since the |
278 ;; `same-directory' would be remote. | 281 ;; `same-directory' would be remote. |
279 ;; It will use the fallback if needed. | 282 ;; It will use the fallback if needed. |
280 (auto-save-name-in-fixed-directory save-name)) | 283 (auto-save-name-in-fixed-directory save-name)) |
281 ;; Else it is a local file (or a buffer without a file, hence | 284 ;; Else it is a local file (or a buffer without a file, hence |
282 ;; the name-prefix). | 285 ;; the name-prefix). |
283 ;; Hashed files always go into the special hash dir, never | 286 ;; Hashed files always go into the special hash dir, never |
284 ;; in the same directory, to make recognizing reliable. | 287 ;; in the same directory, to make recognizing reliable. |
285 (if (or auto-save-directory auto-save-hash-p) | 288 (if (or auto-save-directory auto-save-hash-p) |
286 (auto-save-name-in-fixed-directory save-name name-prefix) | 289 (auto-save-name-in-fixed-directory save-name name-prefix) |
287 (auto-save-name-in-same-directory save-name name-prefix))))) | 290 (auto-save-name-in-same-directory save-name name-prefix))))) |
288 | 291 |
289 ;; If any error occurs in the above code, return what the old | 292 ;; If any error occurs in the above code, return what the old |
290 ;; version of this function would have done. It is not ok to | 293 ;; version of this function would have done. It is not ok to |
291 ;; return nil, e.g., when after-find-file tests | 294 ;; return nil, e.g., when after-find-file tests |
292 ;; file-newer-than-file-p, nil would bomb. | 295 ;; file-newer-than-file-p, nil would bomb. |
293 | 296 |
391 ;;; Hashing function contributed by Andy Norman <ange@hplb.hpl.hp.com> | 394 ;;; Hashing function contributed by Andy Norman <ange@hplb.hpl.hp.com> |
392 ;;; based upon C code from pot@fly.cnuce.cnr.IT (Francesco Potorti`). | 395 ;;; based upon C code from pot@fly.cnuce.cnr.IT (Francesco Potorti`). |
393 | 396 |
394 (defun auto-save-cyclic-hash-14 (s) | 397 (defun auto-save-cyclic-hash-14 (s) |
395 ;; "Hash string S into a string of length 14. | 398 ;; "Hash string S into a string of length 14. |
396 ;; A 7-bytes cyclic code for burst correction is calculated on a | |
397 ;; byte-by-byte basis. The polynomial used is D^7 + D^6 + D^3 +1. | |
398 ;; The resulting string consists of hexadecimal digits [0-9a-f]. | 399 ;; The resulting string consists of hexadecimal digits [0-9a-f]. |
399 ;; In particular, it contains no slash, so it can be used as autosave name." | 400 ;; In particular, it contains no slash, so it can be used as autosave name." |
400 (let ((crc (make-string 7 0)) | 401 (let ((crc (make-string 8 0)) |
401 result) | 402 result) |
402 (mapcar | 403 (mapcar |
403 (function | 404 (function |
404 (lambda (new) | 405 (lambda (new) |
405 (setq new (+ new (aref crc 6))) | 406 (setq new (+ new (aref crc 7))) |
407 (aset crc 7 (aref crc 6)) | |
406 (aset crc 6 (+ (aref crc 5) new)) | 408 (aset crc 6 (+ (aref crc 5) new)) |
407 (aset crc 5 (aref crc 4)) | 409 (aset crc 5 (aref crc 4)) |
408 (aset crc 4 (aref crc 3)) | 410 (aset crc 4 (aref crc 3)) |
409 (aset crc 3 (+ (aref crc 2) new)) | 411 (aset crc 3 (+ (aref crc 2) new)) |
410 (aset crc 2 (aref crc 1)) | 412 (aset crc 2 (aref crc 1)) |
416 (aref crc 1) | 418 (aref crc 1) |
417 (aref crc 2) | 419 (aref crc 2) |
418 (aref crc 3) | 420 (aref crc 3) |
419 (aref crc 4) | 421 (aref crc 4) |
420 (aref crc 5) | 422 (aref crc 5) |
421 (aref crc 6))) | 423 (aref crc 6) |
424 (aref crc 7))) | |
422 result)) | 425 result)) |
423 | 426 |
424 ;; This leaves two characters that could be used to wrap it in `#' or | |
425 ;; make two filenames from it: one for autosaving, and another for a | |
426 ;; file containing the name of the autosaved filed, to make hashing | |
427 ;; reversible. | |
428 (defun auto-save-cyclic-hash-12 (s) | |
429 "Outputs the 12-characters ascii hex representation of a 6-bytes | |
430 cyclic code for burst correction calculated on STRING on a | |
431 byte-by-byte basis. The used polynomial is D^6 + D^5 + D^4 + D^3 +1." | |
432 (let ((crc (make-string 6 0))) | |
433 (mapcar | |
434 (function | |
435 (lambda (new) | |
436 (setq new (+ new (aref crc 5))) | |
437 (aset crc 5 (+ (aref crc 4) new)) | |
438 (aset crc 4 (+ (aref crc 3) new)) | |
439 (aset crc 3 (+ (aref crc 2) new)) | |
440 (aset crc 2 (aref crc 1)) | |
441 (aset crc 1 (aref crc 0)) | |
442 (aset crc 0 new))) | |
443 s) | |
444 (format "%02x%02x%02x%02x%02x%02x" | |
445 (aref crc 0) | |
446 (aref crc 1) | |
447 (aref crc 2) | |
448 (aref crc 3) | |
449 (aref crc 4) | |
450 (aref crc 5)))) | |
451 | |
452 | 427 |
453 | 428 |
454 ;;; Recovering files | 429 ;;; Recovering files |
455 | 430 |
456 (defun recover-all-files (&optional silent) | 431 ;; jwz: changed this to also offer to recover auto-saved buffers which |
432 ;; had no associated file name (such as sendmail buffers.) | |
433 (defun recover-all-files () | |
457 "Do recover-file for all autosave files which are current. | 434 "Do recover-file for all autosave files which are current. |
458 Only works if you have a non-nil `auto-save-directory'. | 435 Only works if you have a non-nil `auto-save-directory'. |
459 | |
460 Optional prefix argument SILENT means to be silent about non-current | |
461 autosave files. This is useful if invoked automatically at Emacs | |
462 startup. | |
463 | |
464 If `auto-save-offer-delete' is t, this function will offer to delete | |
465 old or rejected autosave files. | |
466 | |
467 Hashed files (see `auto-save-hash-p') are not understood, use | 436 Hashed files (see `auto-save-hash-p') are not understood, use |
468 `recover-file' to recover them individually." | 437 `recover-file' to recover them individually." |
469 (interactive "P") | 438 (interactive) |
470 (let ((savefiles (directory-files auto-save-directory t "^#")) | 439 (let ((savefiles (directory-files auto-save-directory t "^#")) |
471 afile ; the auto save file | 440 afile ; the auto save file |
472 file ; its original file | 441 file ; its original file |
473 (total 0) ; # of files offered to recover | 442 (total 0) ; # of files offered to recover |
474 (count 0)) ; # of files actually recovered | 443 (count 0)) ; # of files actually recovered |
505 (setq count (1+ count)) | 474 (setq count (1+ count)) |
506 (message "\ | 475 (message "\ |
507 Auto-save off in buffer \"%s\" till you do M-x auto-save-mode." | 476 Auto-save off in buffer \"%s\" till you do M-x auto-save-mode." |
508 (buffer-name)) | 477 (buffer-name)) |
509 (set-buffer obuf) | 478 (set-buffer obuf) |
510 (sit-for 1)) | 479 (sit-for 1)))))) |
511 ;; If not used for recovering, offer to delete | |
512 ;; autosave file | |
513 (and auto-save-offer-delete | |
514 (or (eq 'always auto-save-offer-delete) | |
515 (yes-or-no-p | |
516 (format "Delete autosave file for `%s'? " file))) | |
517 (delete-file afile)))))) | |
518 (if (zerop total) | 480 (if (zerop total) |
519 (or silent (message "Nothing to recover.")) | 481 (message "Nothing to recover.") |
520 (message "%d/%d file%s recovered." count total (if (= count 1) "" "s")))) | 482 (message "%d/%d file%s recovered." count total (if (= count 1) "" "s")))) |
521 (if (get-buffer "*Directory*") (kill-buffer "*Directory*"))) | 483 (if (get-buffer "*Directory*") (kill-buffer "*Directory*"))) |
522 | 484 |
523 ;;; end of auto-save.el | 485 (provide 'auto-save) |