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 21:26:51 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200403210326.i2L3QpF29260@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> <8011-Fri19Mar2004164602+0200-eliz@elta.co.il> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1079839914 10683 80.91.224.253 (21 Mar 2004 03:31:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 21 Mar 2004 03:31:54 +0000 (UTC) Cc: emacs-devel@gnu.org, storm@cua.dk Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Mar 21 04:31:46 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 1B4tgg-0007vR-00 for ; Sun, 21 Mar 2004 04:31:46 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4tgf-00028h-00 for ; Sun, 21 Mar 2004 04:31:46 +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 1B4tf8-00057C-Oc for emacs-devel@quimby.gnus.org; Sat, 20 Mar 2004 22:30:10 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B4teh-00055L-Fp for emacs-devel@gnu.org; Sat, 20 Mar 2004 22:29:43 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B4te7-0004vi-K6 for emacs-devel@gnu.org; Sat, 20 Mar 2004 22:29:38 -0500 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4te7-0004vY-7Q for emacs-devel@gnu.org; Sat, 20 Mar 2004 22:29:07 -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 i2L3SXKt013050; Sat, 20 Mar 2004 21:28:33 -0600 (CST) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i2L3QpF29260; Sat, 20 Mar 2004 21:26:51 -0600 (CST) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: eliz@elta.co.il In-reply-to: <8011-Fri19Mar2004164602+0200-eliz@elta.co.il> 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:20657 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20657 Here is my proposed patch for dired.el supporting the auto-revert patch. Note that, for people not using auto-revert the one visible change is that `g' in dired would no longer print the "Reading directory %s..." and "Reading directory %s...done" messages. I asked before whether this would be OK and the only reactions were from Stefan and Kai who both agreed. If one wants to keep those messages, then I would need an auto-revert-flag variable to tell `dired-internal-noselect' that it is called by auto-revert (to silence those messages), which Stefan finds very unaesthetic. Until somebody takes care of the portability problem mentioned by Eli, I guess that setting global-auto-revert-non-file-buffers to t will have essentially no effect on dired buffers for MS Windows. (I do not know whether there only is a portability problem for MS Windows or whether similar problems exist for mac, VMS and/or other operating systems.) `dired-directory-changed-p' is the exact code priorly used by `dired-internal-noselect'. I could actually do things differently from the way they are done below, and incorporate `dired-directory-changed-p' into `dired-buffer-stale-p', instead of making it a separate function, and have `dired-internal-noselect' call `dired-buffer-stale-p' instead of `dired-directory-changed-p'. Then one could give the variable buffer-stale-function an operating system specific value. I could document the portability problem if it would become clear that it is not going to be solved any time soon. ===File ~/dired-diff======================================== *** dired.el.~1.272.~ Tue Feb 3 15:42:36 2004 --- dired.el Fri Mar 19 14:05:59 2004 *************** *** 513,524 **** (setq dir-or-list dirname)) (dired-internal-noselect dir-or-list switches))) ;; Separate function from dired-noselect for the sake of dired-vms.el. (defun dired-internal-noselect (dir-or-list &optional switches mode) ;; If there is an existing dired buffer for DIRNAME, just leave ;; buffer as it is (don't even call dired-revert). ;; This saves time especially for deep trees or with ange-ftp. ! ;; The user can type `g'easily, and it is more consistent with find-file. ;; But if SWITCHES are given they are probably different from the ;; buffer's old value, so call dired-sort-other, which does ;; revert the buffer. --- 513,546 ---- (setq dir-or-list dirname)) (dired-internal-noselect dir-or-list switches))) + ;; The following is an internal dired function. It returns non-nil if + ;; the directory visited by the current dired buffer has changed on + ;; disk. DIRNAME should be the directory name of that directory. + (defun dired-directory-changed-p (dirname) + (not (let ((attributes (file-attributes dirname)) + (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))))))) + + (defun dired-buffer-stale-p (&optional noconfirm) + "Return non-nil if current dired buffer needs updating. + If NOCONFIRM is non-nil, then this function always returns nil + for a remote directory. This feature is used by Auto Revert Mode." + (let ((dirname + (if (consp dired-directory) (car dired-directory) dired-directory))) + (and (stringp dirname) + (not (when noconfirm (file-remote-p dirname))) + (file-readable-p dirname) + (dired-directory-changed-p dirname)))) + ;; Separate function from dired-noselect for the sake of dired-vms.el. (defun dired-internal-noselect (dir-or-list &optional switches mode) ;; If there is an existing dired buffer for DIRNAME, just leave ;; buffer as it is (don't even call dired-revert). ;; This saves time especially for deep trees or with ange-ftp. ! ;; The user can type `g' easily, and it is more consistent with find-file. ;; But if SWITCHES are given they are probably different from the ;; buffer's old value, so call dired-sort-other, which does ;; revert the buffer. *************** *** 544,563 **** ;; kill-all-local-variables any longer. (setq buffer (create-file-buffer (directory-file-name dirname))))) (set-buffer buffer) ! (if (not new-buffer-p) ; existing buffer ... ! (cond (switches ; ... but new switches ;; file list may have changed (setq dired-directory dir-or-list) ;; this calls dired-revert (dired-sort-other switches)) ;; If directory has changed on disk, offer to revert. ! ((if (let ((attributes (file-attributes dirname)) ! (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))))) ! nil (message "%s" (substitute-command-keys "Directory has changed on disk; type \\[revert-buffer] to update Dired"))))) --- 566,579 ---- ;; kill-all-local-variables any longer. (setq buffer (create-file-buffer (directory-file-name dirname))))) (set-buffer buffer) ! (if (not new-buffer-p) ; existing buffer ... ! (cond (switches ; ... but new switches ;; file list may have changed (setq dired-directory dir-or-list) ;; this calls dired-revert (dired-sort-other switches)) ;; If directory has changed on disk, offer to revert. ! ((when (dired-directory-changed-p dirname) (message "%s" (substitute-command-keys "Directory has changed on disk; type \\[revert-buffer] to update Dired"))))) *************** *** 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 --- 650,655 ---- *************** *** 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 --- 658,663 ---- *************** *** 1201,1206 **** --- 1215,1222 ---- ;; Dired mode is suitable only for specially formatted data. (put 'dired-mode 'mode-class 'special) + (defvar buffer-stale-function) + (defun dired-mode (&optional dirname switches) "\ Mode for \"editing\" directory listings. *************** *** 1279,1284 **** --- 1295,1302 ---- (propertized-buffer-identification "%17b")) (set (make-local-variable 'revert-buffer-function) (function dired-revert)) + (set (make-local-variable 'buffer-stale-function) + (function dired-buffer-stale-p)) (set (make-local-variable 'page-delimiter) "\n\n") (set (make-local-variable 'dired-directory) ============================================================