From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: autorevert.el Date: Sat, 20 Mar 2004 20:42:28 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200403210242.i2L2gSM28857@raven.dms.auburn.edu> References: <200403022319.i22NJbG01259@raven.dms.auburn.edu> <200403040508.i2458W811551@raven.dms.auburn.edu> <200403050400.i2540VQ21715@raven.dms.auburn.edu> <200403130310.i2D3A8w28676@raven.dms.auburn.edu> <200403150008.i2F083x04382@raven.dms.auburn.edu> <200403160456.i2G4uVL14097@raven.dms.auburn.edu> <2427-Tue16Mar2004214034+0200-eliz@elta.co.il> <200403190448.i2J4mxQ12087@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1079837201 6219 80.91.224.253 (21 Mar 2004 02:46:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 21 Mar 2004 02:46:41 +0000 (UTC) Cc: eliz@elta.co.il, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Mar 21 03:46:26 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4syo-0006ya-00 for ; Sun, 21 Mar 2004 03:46:26 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4syn-0000j2-00 for ; Sun, 21 Mar 2004 03:46:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4sxS-0005ne-Hi for emacs-devel@quimby.gnus.org; Sat, 20 Mar 2004 21:45:02 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B4sxL-0005nS-MD for emacs-devel@gnu.org; Sat, 20 Mar 2004 21:44:55 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B4swp-0005jG-Av for emacs-devel@gnu.org; Sat, 20 Mar 2004 21:44:54 -0500 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4swp-0005j1-16 for emacs-devel@gnu.org; Sat, 20 Mar 2004 21:44:23 -0500 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i2L2iCKt012980; Sat, 20 Mar 2004 20:44:12 -0600 (CST) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i2L2gSM28857; Sat, 20 Mar 2004 20:42:28 -0600 (CST) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: monnier@iro.umontreal.ca In-reply-to: (message from Stefan Monnier on 19 Mar 2004 01:06:53 -0500) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20656 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20656 Stefan Monnier wrote: Please install your autorevert-stale-function (or whatever the name) patch as soon as it's ready. All it has to do is to get rid of the current autorevert-dired horror. Here is the proposed patch. I actually took a look at the code duplication in the current code and there appeared to be quite some. My patch gets rid of one more function. I _did_ get rid of my auto-revert-flag variable. However, I am not sure that as people try to make more and more modes suitable for auto-reverting the need for that variable will not arise again. If people would object against the modifications I made to the revert-buffer-functions of dired (silencing the revert message) or the buffer-menu (see a later message), then I would need it right now. Some things about the *-stale-function may be up for debate. I called it buffer-stale-function and gave it an optional argument telling it that it is called by auto-revert or something else that does not ask for confirmation. The idea is that the same function also could be useful to warn the user that the buffer is stale, if auto-revert mode is _not_ enabled. Since here the user makes an explicit decision, the behavior could be different for remote files and other time confusing stuff. So the function would (like revert-buffer-function) not necessarily be auto-revert specific. Alternatively, one could make it an auto-revert specific function, call it auto-revert-stale-function and get rid of the optional argument. I will send supporting patches for dired.el and buff-menu.el separately. ===File ~/autorevert-diff=================================== diff -c /home/teirllm/autorevert.old.el /home/teirllm/emacscvsdir/emacs/lisp/autorevert.el *** /home/teirllm/autorevert.old.el Sat Mar 20 19:01:28 2004 --- /home/teirllm/emacscvsdir/emacs/lisp/autorevert.el Sat Mar 20 18:56:29 2004 *************** *** 172,178 **** When non-nil, both file buffers and buffers with a custom `revert-buffer-function' are reverted by Global Auto-Revert Mode. ! Use this option with care since it could lead to excessive reverts." :group 'auto-revert :type 'boolean) --- 172,183 ---- When non-nil, both file buffers and buffers with a custom `revert-buffer-function' are reverted by Global Auto-Revert Mode. ! Use this option with care since it could lead to excessive reverts. ! Note also that for some non-file buffers the check whether the ! buffer needs updating may be imperfect, due to efficiency ! considerations, and may not take all information listed in the ! buffer into account. Hence, a non-nil value for this option does ! not necessarily make manual updates useless for non-file buffers." :group 'auto-revert :type 'boolean) *************** *** 193,198 **** --- 198,215 ---- This variable becomes buffer local when set in any fashion.") (make-variable-buffer-local 'global-auto-revert-ignore-buffer) + (defvar buffer-stale-function nil + "Function to check whether a non-file buffer needs reverting. + This should be a function with one optional argument NOCONFIRM. + Auto Revert Mode sets NOCONFIRM to t. The function should return + non-nil if the buffer should be reverted. The buffer is current + when this function is called. + + The idea behind the NOCONFIRM argument is that the same function + can also be used to ask the user whether the buffer should be + reverted. In such a situation one has to be less careful about, + say, reverting remote files, than if the function ia called at + regular intervals by Auto Revert Mode.") ;; Internal variables: *************** *** 272,332 **** (not (memq major-mode global-auto-revert-ignore-modes))))) - (defun auto-revert-list-diff (a b) - "Check if strings in list A differ from list B." - (when (and a b) - (setq a (sort a 'string-lessp)) - (setq b (sort b 'string-lessp)) - (let (elt1 elt2) - (catch 'break - (while (and (setq elt1 (and a (pop a))) - (setq elt2 (and b (pop b)))) - (if (not (string= elt1 elt2)) - (throw 'break t))))))) - - (defun auto-revert-dired-file-list () - "Return list of dired files." - (let (file list) - (save-excursion - (goto-char (point-min)) - (while (not (eobp)) - (if (setq file (dired-get-filename t t)) - (push file list)) - (forward-line 1))) - list)) - - (defun auto-revert-dired-changed-p () - "Check if dired buffer has changed." - (when (and (stringp dired-directory) - ;; Exclude remote buffers, would be too slow for user - ;; modem, timeouts, network lag ... all is possible - (not (string-match "@" dired-directory)) - (file-directory-p dired-directory)) - (let ((files (directory-files dired-directory)) - (dired (auto-revert-dired-file-list))) - (or (not (eq (length files) (length dired))) - (auto-revert-list-diff files dired))))) - - (defun auto-revert-buffer-p () - "Check if current buffer should be reverted." - ;; - Always include dired buffers to list. It would be too expensive - ;; to test the "revert" status here each time timer launches. - ;; - Same for VC buffers. - (or (and (eq major-mode 'dired-mode) - (or (and global-auto-revert-mode - global-auto-revert-non-file-buffers) - auto-revert-mode)) - (and (not (buffer-modified-p)) - (auto-revert-vc-buffer-p)) - (and (not (buffer-modified-p)) - (if (buffer-file-name) - (and (file-readable-p (buffer-file-name)) - (not (verify-visited-file-modtime (current-buffer)))) - (and revert-buffer-function - (or (and global-auto-revert-mode - global-auto-revert-non-file-buffers) - auto-revert-mode)))))) - (defun auto-revert-vc-cvs-file-version (file) "Get version of FILE by reading control file on disk." (let* ((control "CVS/Entries") --- 289,294 ---- *************** *** 383,407 **** (defun auto-revert-handler () "Revert current buffer." ! (let (revert) ! (cond ! ((eq major-mode 'dired-mode) ! ;; Dired includes revert-buffer-function ! (when (and revert-buffer-function ! (auto-revert-dired-changed-p)) (setq revert t))) ! ((auto-revert-vc-buffer-p) ! (when (auto-revert-handler-vc) ! (setq revert 'vc))) ! ((or (buffer-file-name) ! revert-buffer-function) ! (setq revert t))) ! (when revert ! (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes) ! (if (eq revert 'vc) ! (vc-mode-line buffer-file-name)) ! (if auto-revert-verbose ! (message "Reverting buffer `%s'." (buffer-name)))))) (defun auto-revert-buffers () "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode. --- 345,371 ---- (defun auto-revert-handler () "Revert current buffer." ! (unless (buffer-modified-p) ! (let (revert) ! (cond ! ((auto-revert-vc-buffer-p) ! (when (auto-revert-handler-vc) ! (setq revert 'vc))) ! ((or (and (buffer-file-name) ! (file-readable-p (buffer-file-name)) ! (not (verify-visited-file-modtime (current-buffer)))) ! (and global-auto-revert-non-file-buffers ! revert-buffer-function ! (boundp 'buffer-stale-function) ! (functionp buffer-stale-function) ! (funcall buffer-stale-function t))) (setq revert t))) ! (when revert ! (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes) ! (if (eq revert 'vc) ! (vc-mode-line buffer-file-name)) ! (if auto-revert-verbose ! (message "Reverting buffer `%s'." (buffer-name))))))) (defun auto-revert-buffers () "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode. *************** *** 453,460 **** (memq buf auto-revert-buffer-list)) (setq auto-revert-buffer-list (delq buf auto-revert-buffer-list))) ! (when (and (auto-revert-active-p) ! (auto-revert-buffer-p)) (auto-revert-handler) ;; `preserve-modes' avoids changing the (minor) modes. But we ;; do want to reset the mode for VC, so we do it explicitly. --- 417,423 ---- (memq buf auto-revert-buffer-list)) (setq auto-revert-buffer-list (delq buf auto-revert-buffer-list))) ! (when (auto-revert-active-p) (auto-revert-handler) ;; `preserve-modes' avoids changing the (minor) modes. But we ;; do want to reset the mode for VC, so we do it explicitly. Diff finished. Sat Mar 20 19:30:15 2004 ============================================================