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: autorevert.el Date: Tue, 2 Mar 2004 17:19:37 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200403022319.i22NJbG01259@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1078316504 31291 80.91.224.253 (3 Mar 2004 12:21:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 3 Mar 2004 12:21:44 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Mar 03 13:21:33 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 1AyVNV-0002k1-00 for ; Wed, 03 Mar 2004 13:21:33 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AyVNV-0000eW-00 for ; Wed, 03 Mar 2004 13:21:33 +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 1AyV3D-0001xv-0T for emacs-devel@quimby.gnus.org; Wed, 03 Mar 2004 07:00:35 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1AyJIt-0002Hd-OG for emacs-devel@gnu.org; Tue, 02 Mar 2004 18:27:59 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1AyJIM-00027v-N8 for emacs-devel@gnu.org; Tue, 02 Mar 2004 18:27:58 -0500 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1AyJBo-0000h9-71 for emacs-devel@gnu.org; Tue, 02 Mar 2004 18:20:40 -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 i22NKaKt011427 for ; Tue, 2 Mar 2004 17:20:36 -0600 (CST) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i22NJbG01259; Tue, 2 Mar 2004 17:19:37 -0600 (CST) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 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:20233 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20233 This is an amended copy of something I sent to emacs-devel on Thursday. I do not expect the original to ever arrive. Any objections to me applying the patch below? I have been using it without any problems for two weeks now. The purpose is to be able to autorevert dired buffers without excessive CPU-usage and without continuously being overshouted by revert messages when trying to use the minibuffer. If one customizes dired in the "wrong" way (say, not using the "a" switch) or uses the "wrong" dired functionality (for instance, listing subdirectories) this is currently not possible (without my patch applied). Also, without my patch applied, various other dired functionality, for instance dired-undo, no longer properly works if one tries to auto-revert dired buffers. There is one addition to the patch I proposed (but did not install) two weeks ago. That is the new user-option `auto-revert-no-secondary-messages' which allows to suppress the usual "Reading directory %s...done" type messages. The default is nil, do not suppress them. Without this option or with the option set to nil, one still (even after applying my previous patch) can get overshouted in the minibuffer while, say, bootstrapping or stuff like that. With the variable set to t, one can visit every single directory and subdirectory in the Emacs CVS tree, so they all will get updated, and then bootstrap (or do similar stuff that continuously updates the directories), without any minibuffer-overshouting or CPU-usage problems. ===File ~/autorevert.el-diff================================ *** autorevert.el.~1.21.~ Mon Feb 16 20:04:45 2004 --- autorevert.el Thu Feb 26 20:43:07 2004 *************** *** 158,164 **** 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) --- 158,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. ! 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) ! ! (defcustom auto-revert-no-secondary-messages nil ! "If non-nil, Auto-Revert Mode suppresses secondary revert messages. ! These are messages generated by a non-file buffer's `revert-buffer-function'. ! This variable only works for buffers whose`revert-buffer-function' ! supports it. To suppress revert messages generated by Auto-Revert Mode ! itself, use `auto-revert-verbose'." :group 'auto-revert :type 'boolean) *************** *** 260,312 **** (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)))) --- 274,305 ---- (not (memq major-mode global-auto-revert-ignore-modes))))) (defun auto-revert-buffer-p () "Check if current buffer should be reverted." ! ;; - Always include VC buffers to list. It would be too expensive ;; to test the "revert" status here each time timer launches. (or (and (eq major-mode 'dired-mode) (or (and global-auto-revert-mode global-auto-revert-non-file-buffers) ! auto-revert-mode) ! (not (buffer-modified-p)) ! (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) ! (file-readable-p dired-directory) ! (not (let ((attributes (file-attributes dired-directory)) ! (modtime (visited-file-modtime))) ! (or (eq modtime 0) ! (not (eq (car attributes) t)) ! (and (= (car (nth 5 attributes)) (car modtime)) ! (= (nth 1 (nth 5 attributes)) (cdr modtime))))))) ! (and (not (eq major-mode 'dired-mode)) ! (not (buffer-modified-p)) (auto-revert-vc-buffer-p)) ! (and (not (eq major-mode 'dired-mode)) ! (not (buffer-modified-p)) (if (buffer-file-name) (and (file-readable-p (buffer-file-name)) (not (verify-visited-file-modtime (current-buffer)))) *************** *** 369,382 **** ;; TODO: )))))) (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) --- 362,379 ---- ;; TODO: )))))) + (defvar auto-revert-flag nil + "Bound to t by `auto-revert-handler'. + If non-nil, the current function was called as part of auto-reverting + a buffer. This is used to implement `auto-revert-no-secondary-messages'.") + (defun auto-revert-handler () "Revert current buffer." (let (revert) (cond ((eq major-mode 'dired-mode) ;; Dired includes revert-buffer-function ! (when revert-buffer-function (setq revert t))) ((auto-revert-vc-buffer-p) (when (auto-revert-handler-vc) *************** *** 385,395 **** 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. --- 382,393 ---- revert-buffer-function) (setq revert t))) (when revert ! (let ((auto-revert-flag t)) ! (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. ============================================================ ===File ~/dired-diff======================================== *** dired.el.~1.272.~ Tue Feb 3 15:42:36 2004 --- dired.el Thu Feb 26 20:04:48 2004 *************** *** 618,623 **** --- 618,625 ---- ;; Read in a new dired buffer + (defvar auto-revert-flag) + ;; dired-readin differs from dired-insert-subdir in that it accepts ;; wildcards, erases the buffer, and builds the subdir-alist anew ;; (including making it buffer-local and clearing it first). *************** *** 634,640 **** ;; based on dired-directory, e.g. with ange-ftp to a SysV host ;; where ls won't understand -Al switches. (run-hooks 'dired-before-readin-hook) ! (message "Reading directory %s..." dirname) (if (consp buffer-undo-list) (setq buffer-undo-list nil)) (let (buffer-read-only --- 636,645 ---- ;; based on dired-directory, e.g. with ange-ftp to a SysV host ;; where ls won't understand -Al switches. (run-hooks 'dired-before-readin-hook) ! (unless (and (boundp 'auto-revert-flag) ! auto-revert-flag ! auto-revert-no-secondary-messages) ! (message "Reading directory %s..." dirname)) (if (consp buffer-undo-list) (setq buffer-undo-list nil)) (let (buffer-read-only *************** *** 643,649 **** (widen) (erase-buffer) (dired-readin-insert)) ! (message "Reading directory %s...done" dirname) (goto-char (point-min)) ;; Must first make alist buffer local and set it to nil because ;; dired-build-subdir-alist will call dired-clear-alist first --- 648,657 ---- (widen) (erase-buffer) (dired-readin-insert)) ! (unless (and (boundp 'auto-revert-flag) ! auto-revert-flag ! auto-revert-no-secondary-messages) ! (message "Reading directory %s...done" dirname)) (goto-char (point-min)) ;; Must first make alist buffer local and set it to nil because ;; dired-build-subdir-alist will call dired-clear-alist first ============================================================