comparison lisp/auto-save.el @ 321:19dcec799385 r21-0-58

Import from CVS: tag r21-0-58
author cvs
date Mon, 13 Aug 2007 10:46:44 +0200
parents 90d73dddcdc4
children cc15677e0335
comparison
equal deleted inserted replaced
320:73c75c43c1f2 321:19dcec799385
184 ;;;; end of customization 184 ;;;; end of customization
185 185
186 186
187 ;;; Preparations to be done at load time 187 ;;; Preparations to be done at load time
188 188
189 (defvar auto-save-directory-fallback (expand-file-name "~/.autosave/") 189 ;; Do not call expand-file-name! This is evaluated at dump time now!
190 (defvar auto-save-directory-fallback "~/.autosave/"
190 ;; not user-variable-p, see above 191 ;; not user-variable-p, see above
191 "Directory used for local autosaving of remote files if 192 "Directory used for local autosaving of remote files if
192 both `auto-save-directory' and `efs-auto-save-remotely' are nil. 193 both `auto-save-directory' and `efs-auto-save-remotely' are nil.
193 Also used if a working directory to be used for autosaving is not writable. 194 Also used if a working directory to be used for autosaving is not writable.
194 This *must* always be the name of directory that exists or can be 195 This *must* always be the name of directory that exists or can be
197 (defvar auto-save-hash-directory 198 (defvar auto-save-hash-directory
198 (expand-file-name "hash/" (or auto-save-directory 199 (expand-file-name "hash/" (or auto-save-directory
199 auto-save-directory-fallback)) 200 auto-save-directory-fallback))
200 "If non-nil, directory used for hashed autosave filenames.") 201 "If non-nil, directory used for hashed autosave filenames.")
201 202
202 (defun auto-save-check-directory (var) 203 (defun auto-save-checked-directory (dir)
203 (let ((dir (symbol-value var))) 204 "Make sure the directory DIR exists and return it expanded if non-nil."
204 (if (null dir) 205 (when dir
205 nil 206 (setq dir (expand-file-name dir))
206 ;; Expand and store back into the variable
207 (set var (setq dir (expand-file-name dir)))
208 ;; Make sure directory exists 207 ;; Make sure directory exists
209 (if (file-directory-p dir) 208 (unless (file-directory-p dir)
210 nil
211 ;; Else we create and chmod 0700 the directory 209 ;; Else we create and chmod 0700 the directory
212 (setq dir (directory-file-name dir)) ; some systems need this 210 (setq dir (directory-file-name dir)) ; some systems need this
213 (make-directory dir) 211 (make-directory dir)
214 (set-file-modes dir #o700))))) 212 (set-file-modes dir #o700))
215 213 dir))
216 (mapc #'auto-save-check-directory 214
217 '(auto-save-directory auto-save-directory-fallback)) 215 ;; This make no sense at dump time
218 216 ;; (mapc #'auto-save-check-directory
219 (and auto-save-hash-p 217 ; '(auto-save-directory auto-save-directory-fallback))
220 (auto-save-check-directory 'auto-save-hash-directory)) 218
219 ;(and auto-save-hash-p
220 ; (auto-save-check-directory 'auto-save-hash-directory))
221 221
222 222
223 ;;; Computing an autosave name for a file and vice versa 223 ;;; Computing an autosave name for a file and vice versa
224 224
225 ;; #### Now that this file is dumped, we should turn off the routine 225 ;; #### Now that this file is dumped, we should turn off the routine
333 (savedir (file-name-directory savename))) 333 (savedir (file-name-directory savename)))
334 (cond ((or (not (auto-save-file-name-p basename)) 334 (cond ((or (not (auto-save-file-name-p basename))
335 (string-match "^#%" basename)) 335 (string-match "^#%" basename))
336 nil) 336 nil)
337 ;; now we know it looks like #...# thus substring is safe to use 337 ;; now we know it looks like #...# thus substring is safe to use
338 ((or (equal savedir auto-save-directory) ; 2nd arg may be nil 338 ((or (equal savedir
339 (equal savedir auto-save-directory-fallback)) 339 (and auto-save-directory
340 (expand-file-name auto-save-directory)))
341 ; 2nd arg may be nil
342 (equal savedir
343 (expand-file-name auto-save-directory-fallback)))
340 ;; it is of the `-fixed-directory' type 344 ;; it is of the `-fixed-directory' type
341 (auto-save-slashify-name (substring basename 1 -1))) 345 (auto-save-slashify-name (substring basename 1 -1)))
342 (t 346 (t
343 ;; else it is of `-same-directory' type 347 ;; else it is of `-same-directory' type
344 (concat savedir (substring basename 1 -1)))))) 348 (concat savedir (substring basename 1 -1))))))
356 "#"))) 360 "#")))
357 (if (and auto-save-hash-p 361 (if (and auto-save-hash-p
358 auto-save-hash-directory 362 auto-save-hash-directory
359 (> (length base-name) 14)) 363 (> (length base-name) 14))
360 (expand-file-name (auto-save-cyclic-hash-14 filename) 364 (expand-file-name (auto-save-cyclic-hash-14 filename)
361 auto-save-hash-directory) 365 (auto-save-checked-directory auto-save-hash-directory))
362 (expand-file-name base-name 366 (expand-file-name base-name
363 (or auto-save-directory 367 (auto-save-checked-directory
364 auto-save-directory-fallback))))) 368 (or auto-save-directory
369 auto-save-directory-fallback))))))
365 370
366 (defun auto-save-name-in-same-directory (filename &optional prefix) 371 (defun auto-save-name-in-same-directory (filename &optional prefix)
367 ;; Enclose the non-directory part of FILENAME in `#' to make an auto 372 ;; Enclose the non-directory part of FILENAME in `#' to make an auto
368 ;; save file in the same directory as FILENAME. But if this 373 ;; save file in the same directory as FILENAME. But if this
369 ;; directory is not writable, use auto-save-directory-fallback. 374 ;; directory is not writable, use auto-save-directory-fallback.
372 ;; comes from a buffer name then), the fallback is used then. 377 ;; comes from a buffer name then), the fallback is used then.
373 ;; Optional PREFIX is string to use instead of "#" to prefix name. 378 ;; Optional PREFIX is string to use instead of "#" to prefix name.
374 (let ((directory (file-name-directory filename))) 379 (let ((directory (file-name-directory filename)))
375 (or (null directory) 380 (or (null directory)
376 (file-writable-p directory) 381 (file-writable-p directory)
377 (setq directory auto-save-directory-fallback)) 382 (setq directory (auto-save-checked-directory
383 auto-save-directory-fallback)))
378 (concat directory ; (concat nil) is "" 384 (concat directory ; (concat nil) is ""
379 (or prefix "#") 385 (or prefix "#")
380 (file-name-nondirectory filename) 386 (file-name-nondirectory filename)
381 "#"))) 387 "#")))
382 388
495 t "\\`#" nil t)) 501 t "\\`#" nil t))
496 afile ; the auto save file 502 afile ; the auto save file
497 file ; its original file 503 file ; its original file
498 (total 0) ; # of files offered to recover 504 (total 0) ; # of files offered to recover
499 (count 0)) ; # of files actually recovered 505 (count 0)) ; # of files actually recovered
500 (or (equal auto-save-directory auto-save-directory-fallback) 506 (or (equal (expand-file-name auto-save-directory)
507 (expand-file-name auto-save-directory-fallback))
501 (setq savefiles 508 (setq savefiles
502 (nconc savefiles 509 (nconc savefiles
503 (directory-files auto-save-directory-fallback 510 (directory-files auto-save-directory-fallback
504 t "\\`#" nil t)))) 511 t "\\`#" nil t))))
505 (while savefiles 512 (while savefiles