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