From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: emacs-devel@gnu.org, storm@cua.dk
Subject: Re: autorevert.el
Date: Sat, 20 Mar 2004 21:26:51 -0600 (CST) [thread overview]
Message-ID: <200403210326.i2L3QpF29260@raven.dms.auburn.edu> (raw)
In-Reply-To: <8011-Fri19Mar2004164602+0200-eliz@elta.co.il>
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)
============================================================
next prev parent reply other threads:[~2004-03-21 3:26 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-02 23:19 autorevert.el Luc Teirlinck
2004-03-03 13:24 ` autorevert.el Stefan Monnier
2004-03-04 5:08 ` autorevert.el Luc Teirlinck
2004-03-04 20:43 ` autorevert.el Stefan Monnier
2004-03-05 4:00 ` autorevert.el Luc Teirlinck
2004-03-13 3:10 ` autorevert.el Luc Teirlinck
2004-03-13 11:29 ` autorevert.el Kai Grossjohann
2004-03-14 23:15 ` autorevert.el Stefan Monnier
2004-03-15 0:08 ` autorevert.el Luc Teirlinck
2004-03-15 2:58 ` autorevert.el Stefan Monnier
2004-03-15 7:04 ` autorevert.el Eli Zaretskii
2004-03-16 4:56 ` autorevert.el Luc Teirlinck
2004-03-16 19:40 ` autorevert.el Eli Zaretskii
2004-03-19 4:48 ` autorevert.el Luc Teirlinck
2004-03-19 6:06 ` autorevert.el Stefan Monnier
2004-03-21 2:42 ` autorevert.el Luc Teirlinck
2004-03-23 15:26 ` autorevert.el Stefan Monnier
2004-03-24 4:20 ` autorevert.el Luc Teirlinck
2004-03-24 4:25 ` autorevert.el Luc Teirlinck
2004-03-21 4:19 ` autorevert.el Luc Teirlinck
2004-03-19 10:19 ` autorevert.el Kim F. Storm
2004-03-19 14:46 ` autorevert.el Eli Zaretskii
2004-03-21 3:26 ` Luc Teirlinck [this message]
2004-03-21 6:46 ` autorevert.el Eli Zaretskii
2004-03-22 2:44 ` autorevert.el Luc Teirlinck
2004-03-22 6:51 ` autorevert.el Eli Zaretskii
2004-03-22 19:39 ` autorevert.el Luc Teirlinck
2004-03-23 19:40 ` autorevert.el Eli Zaretskii
2004-03-23 20:09 ` autorevert.el Stefan Monnier
2004-03-24 4:10 ` autorevert.el Luc Teirlinck
2004-03-24 6:58 ` autorevert.el Eli Zaretskii
2004-03-24 18:03 ` autorevert.el Stefan Monnier
2004-03-25 6:56 ` autorevert.el Eli Zaretskii
2004-03-25 17:01 ` autorevert.el Stefan Monnier
2004-03-24 18:56 ` autorevert.el Luc Teirlinck
2004-03-25 6:20 ` autorevert.el Luc Teirlinck
2004-03-25 6:49 ` autorevert.el Luc Teirlinck
2004-03-25 7:21 ` autorevert.el Eli Zaretskii
2004-03-22 19:47 ` autorevert.el Luc Teirlinck
2004-03-22 16:23 ` autorevert.el Stefan Monnier
2004-03-23 4:24 ` autorevert.el Eli Zaretskii
2004-03-21 19:22 ` autorevert.el Richard Stallman
2004-03-16 5:06 ` autorevert.el Luc Teirlinck
2004-03-05 4:25 ` autorevert.el Luc Teirlinck
2004-03-05 5:55 ` autorevert.el Luc Teirlinck
2004-03-04 5:34 ` autorevert.el Luc Teirlinck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200403210326.i2L3QpF29260@raven.dms.auburn.edu \
--to=teirllm@dms.auburn.edu \
--cc=emacs-devel@gnu.org \
--cc=storm@cua.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.