aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/autorevert.el119
2 files changed, 52 insertions, 81 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 289998cc3f5..63dfb74b6a1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
12004-03-31 Luc Teirlinck <teirllm@auburn.edu>
2
3 * autorevert.el: Delete obsolete autoload's and defvar's.
4 (auto-revert-check-vc-info): New variable.
5 (auto-revert-vc-cvs-file-version, auto-revert-vc-buffer-p)
6 (auto-revert-handler-vc): Delete.
7 (auto-revert-handler): Treat return value `fast' of
8 buffer-stale-function specially. Check `auto-revert-check-vc-info'.
9
10 * buff-menu.el (Buffer-menu-mode): Make the buffer-stale-function
11 return `fast'.
12
13 * files.el (buffer-stale-function): Doc change.
14
12004-04-01 Nick Roberts <nick@nick.uklinux.net> 152004-04-01 Nick Roberts <nick@nick.uklinux.net>
2 16
3 * progmodes/gdb-ui.el (gdb-view-source-function, gdb-view-assembler) 17 * progmodes/gdb-ui.el (gdb-view-source-function, gdb-view-assembler)
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 165c6b8b24f..6e74a96eff5 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -70,14 +70,8 @@
70;; Dependencies: 70;; Dependencies:
71 71
72(require 'timer) 72(require 'timer)
73(autoload 'dired-get-filename "dired")
74(autoload 'vc-workfile-version "vc-hooks")
75(autoload 'vc-mode-line "vc-hooks")
76 73
77(eval-when-compile 74(eval-when-compile (require 'cl))
78 (defvar dired-directory)
79 (defvar vc-mode)
80 (require 'cl))
81 75
82 76
83;; Custom Group: 77;; Custom Group:
@@ -191,6 +185,27 @@ not necessarily make manual updates useless for non-file buffers."
191 :group 'auto-revert 185 :group 'auto-revert
192 :type 'hook) 186 :type 'hook)
193 187
188(defcustom auto-revert-check-vc-info nil
189 "If non-nil Auto Revert Mode reliably updates version control info.
190Auto Revert Mode updates version control info whenever the buffer
191needs reverting, regardless of the value of this variable.
192However, the version control state can change without changes to
193the work file. If the change is made from the current Emacs
194session, all info is updated. But if, for instance, a new
195version is checked in from outside the current Emacs session, the
196version control number in the mode line, as well as other version
197control related information, may not be properly updated. If you
198are worried about this, set this variable to a non-nil value.
199
200This currently works by automatically updating the version
201control info every `auto-revert-interval' seconds. Nevertheless,
202it should not cause excessive CPU usage on a reasonably fast
203machine, if it does not apply to too many version controlled
204buffers. CPU usage depends on the version control system"
205 :group 'auto-revert
206 :type 'boolean
207 :version "21.4")
208
194(defvar global-auto-revert-ignore-buffer nil 209(defvar global-auto-revert-ignore-buffer nil
195 "*When non-nil, Global Auto-Revert Mode will not revert this buffer. 210 "*When non-nil, Global Auto-Revert Mode will not revert this buffer.
196 211
@@ -279,87 +294,29 @@ will use an up-to-date value of `auto-revert-interval'"
279 (not (memq major-mode 294 (not (memq major-mode
280 global-auto-revert-ignore-modes))))) 295 global-auto-revert-ignore-modes)))))
281 296
282(defun auto-revert-vc-cvs-file-version (file)
283 "Get version of FILE by reading control file on disk."
284 (let* ((control "CVS/Entries")
285 (name (file-name-nondirectory file))
286 (path (format "%s/%s"
287 (file-name-directory file)
288 control)))
289 (when (file-exists-p path)
290 (with-temp-buffer
291 (insert-file-contents-literally path)
292 (goto-char (point-min))
293 (when (re-search-forward
294 ;; /file.txt/1.3/Mon Sep 15 18:43:20 2003//
295 (format "%s/\\([.0-9]+\\)" (regexp-quote name))
296 nil t)
297 (match-string 1))))))
298
299(defun auto-revert-vc-buffer-p ()
300 "Check if buffer is version controlled."
301 (and (boundp 'vc-mode)
302 (string-match "[0-9]" (or vc-mode ""))))
303
304(defun auto-revert-handler-vc ()
305 "Check if version controlled buffer needs revert."
306 ;; [Emacs 1]
307 ;; 1. File is saved (*)
308 ;; 2. checkin is done 1.1 -> 1.2
309 ;; 3. VC reverts, so that updated version number is shown in mode line
310 ;;
311 ;; Suppose the same file has been opened in another Emacs and
312 ;; autorevert.el is on.
313 ;;
314 ;; [Emacs 2]
315 ;; 1. Step (1) is detected and buffer is reverted.
316 ;; 2. But check in does not always change the file in dis, but possibly only
317 ;; control files like CVS/Entries
318 ;; 3. The buffer is not reverted to update VC version line.
319 ;; Incorrect version number 1.1 is shown in this Emacs
320 ;;
321 (when (featurep 'vc)
322 (let* ((file (buffer-file-name))
323 (backend (vc-backend (buffer-file-name)))
324 (version-buffer (vc-workfile-version file)))
325 (when (stringp version-buffer)
326 (cond
327 ((eq backend 'CVS)
328 (let ((version-file
329 (auto-revert-vc-cvs-file-version (buffer-file-name))))
330 (and (stringp version-file)
331 (not (string-match version-file version-buffer)))))
332 ((eq backend 'RCS)
333 ;; TODO:
334 ))))))
335
336(defun auto-revert-handler () 297(defun auto-revert-handler ()
337 "Revert current buffer, if appropriate. 298 "Revert current buffer, if appropriate.
338This is an internal function used by Auto-Revert Mode." 299This is an internal function used by Auto-Revert Mode."
339 (unless (buffer-modified-p) 300 (unless (buffer-modified-p)
340 (let (revert) 301 (let (revert)
341 (cond 302 (or (and (buffer-file-name)
342 ((auto-revert-vc-buffer-p) 303 (file-readable-p (buffer-file-name))
343 (when (auto-revert-handler-vc) 304 (not (verify-visited-file-modtime (current-buffer)))
344 (setq revert 'vc))) 305 (setq revert t))
345 ((or (and (buffer-file-name) 306 (and (or auto-revert-mode global-auto-revert-non-file-buffers)
346 (file-readable-p (buffer-file-name)) 307 revert-buffer-function
347 (not (verify-visited-file-modtime (current-buffer)))) 308 (boundp 'buffer-stale-function)
348 (and (or auto-revert-mode global-auto-revert-non-file-buffers) 309 (functionp buffer-stale-function)
349 revert-buffer-function 310 (setq revert (funcall buffer-stale-function t))))
350 (boundp 'buffer-stale-function)
351 (functionp buffer-stale-function)
352 (funcall buffer-stale-function t)))
353 (setq revert t)))
354 (when revert 311 (when revert
355 (when auto-revert-verbose 312 (when (and auto-revert-verbose
313 (not (eq revert 'fast)))
356 (message "Reverting buffer `%s'." (buffer-name))) 314 (message "Reverting buffer `%s'." (buffer-name)))
357 (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes) 315 (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))
358 ;; `preserve-modes' avoids changing the (minor) modes. But we 316 ;; `preserve-modes' avoids changing the (minor) modes. But we
359 ;; do want to reset the mode for VC, so we do it explicitly. 317 ;; do want to reset the mode for VC, so we do it manually.
360 (vc-find-file-hook) 318 (when (or revert auto-revert-check-vc-info)
361 (if (eq revert 'vc) 319 (vc-find-file-hook)))))
362 (vc-mode-line buffer-file-name))))))
363 320
364(defun auto-revert-buffers () 321(defun auto-revert-buffers ()
365 "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode. 322 "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.