comparison lisp/autorevert.el @ 78408:0f698dc9799c

(auto-revert-tail-mode): auto-revert-tail-pos is zero, not nil, when the library is first loaded. Check for a file that has been modified on disk.
author Glenn Morris <rgm@gnu.org>
date Sat, 04 Aug 2007 02:34:46 +0000
parents 9355f9b7bbff
children 7c8949dbfa0d
comparison
equal deleted inserted replaced
78407:377800d78812 78408:0f698dc9799c
335 (error "This buffer is not visiting a file")) 335 (error "This buffer is not visiting a file"))
336 (if (and (buffer-modified-p) 336 (if (and (buffer-modified-p)
337 (not auto-revert-tail-pos) ; library was loaded only after finding file 337 (not auto-revert-tail-pos) ; library was loaded only after finding file
338 (not (y-or-n-p "Buffer is modified, so tail offset may be wrong. Proceed? "))) 338 (not (y-or-n-p "Buffer is modified, so tail offset may be wrong. Proceed? ")))
339 (auto-revert-tail-mode 0) 339 (auto-revert-tail-mode 0)
340 ;; a-r-tail-pos stores the size of the file at the time of the
341 ;; last revert. After this package loads, it adds a
342 ;; find-file-hook to set this variable every time a file is
343 ;; loaded. If the package is loaded only _after_ visiting the
344 ;; file to be reverted, then we have no idea what the value of
345 ;; a-r-tail-pos should have been when the file was visited. If
346 ;; the file has changed on disk in the meantime, all we can do
347 ;; is offer to revert the whole thing. If you choose not to
348 ;; revert, then you might miss some output then happened
349 ;; between visiting the file and activating a-r-t-mode.
350 (and (zerop auto-revert-tail-pos)
351 (not (verify-visited-file-modtime (current-buffer)))
352 (y-or-n-p "File changed on disk, content may be missing. \
353 Perform a full revert? ")
354 ;; Use this (not just revert-buffer) for point-preservation.
355 (auto-revert-handler))
340 ;; else we might reappend our own end when we save 356 ;; else we might reappend our own end when we save
341 (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t) 357 (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t)
342 (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position 358 (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position
343 (set (make-local-variable 'auto-revert-tail-pos) 359 (set (make-local-variable 'auto-revert-tail-pos)
344 (nth 7 (file-attributes buffer-file-name)))) 360 (nth 7 (file-attributes buffer-file-name))))