emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dired auto-revert (was: Emacs inotify support?)


From: Juri Linkov
Subject: Dired auto-revert (was: Emacs inotify support?)
Date: Tue, 22 Sep 2009 00:45:28 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

There are at least three possible levels of automatic reverting of
a dired buffer:

1. When the user visits a dired buffer with `C-x d' or with
dired navigation commands like `^', etc.

2. Polling at given time intervals like `auto-revert-mode' does.

3. inotify support.

Currently I'd like to focus on the shortcomings of the first method.
Visiting an existing dired buffer with `C-x d' or with dired navigation
keys doesn't automatically revert its old content.  Instead of that,
a message "Directory has changed on disk; type g to update Dired"
is displayed in the echo area.  But the first problem is that it's hard
to notice this message (especially with quick dired navigation).
And the second problem is that even when this message is noticed,
it is still inconvenient to type `g' in every changed dired buffer.

A comment at the beginning of `dired-internal-noselect' says:

  (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).

Why should the user do the tedious task of manual reverting?

  ;; This saves time especially for deep trees or with ange-ftp.

The function `dired-buffer-stale-p' could be use to detect such special
cases and not to automatically revert remote directories.

  ;; The user can type `g' easily, and it is more consistent with find-file.

It is not easy to type `g' in every changed visited dired buffer.
And it is not consistent with find-file because visiting a changed file
prompts for "File changed on disk.  Reread from disk? (yes or no)"
so it is impossible to avoid this message since it requires a confirmation.

  ;; A pity we can't possibly do "Directory has changed - refresh? "
  ;; like find-file does.

Yes, using the same prompt for dired buffers would be annoying because
untracked changes of a visited directory are much more frequent than
changes of a visited 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.

A new SWITCHES reverts the buffer, thus reverting is not a problem,
so why not revert it automatically.

Or maybe we should add a new option that defines whether revert
automatically or just display a message.  The following patch implements
this option:

Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.429
diff -c -r1.429 dired.el
*** lisp/dired.el       18 Sep 2009 16:59:36 -0000      1.429
--- lisp/dired.el       21 Sep 2009 21:35:03 -0000
***************
*** 753,758 ****
--- 753,770 ----
         buffer-read-only
         (dired-directory-changed-p dirname))))
  
+ ;;;###autoload
+ (defcustom dired-auto-revert-buffer nil
+   "Automatically revert changed dired buffer on revisiting.
+ If non-nil, revisiting an existing dired buffer automatically reverts it
+ if directory has changed on disk.  Otherwise, a message offering to revert
+ the changed dired buffer is displayed.
+ Note that this is not the same as `auto-revert-mode' that
+ periodically reverts at specified time intervals."
+   :type 'boolean
+   :version "23.2"
+   :group 'dired)
+ 
  (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).
***************
*** 780,790 ****
               (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")))))
        ;; Else a new buffer
        (setq default-directory
            ;; We can do this unconditionally
--- 792,805 ----
               (setq dired-directory dir-or-list)
               ;; this calls dired-revert
               (dired-sort-other switches))
!             ;; If directory has changed on disk, revert or offer to revert.
              ((when (dired-directory-changed-p dirname)
!                (if (not dired-auto-revert-buffer)
!                    (message "%s"
!                             (substitute-command-keys
!                              "Directory has changed on disk; type 
\\[revert-buffer] to update Dired")))
!                (revert-buffer)
!                (message "%s" "Changed directory automatically updated"))))
        ;; Else a new buffer
        (setq default-directory
            ;; We can do this unconditionally

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]