emacs-devel
[Top][All Lists]
Advanced

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

Re: Dired auto-revert


From: Juri Linkov
Subject: Re: Dired auto-revert
Date: Fri, 04 Dec 2009 02:09:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

>> Or maybe we should add a new option that defines whether revert
>> automatically or just display a message.
>
> Yes, please, if we implement the possibility of auto-reverting, then let's 
> keep
> it only a possibility, not an obligation. IOW, let's also make it possible to
> choose not to auto-revert.

This patch provides a defcustom that allows specifying a predicate function
for anyone who wants a non-standard auto-reverting.  By default it is nil
preserving the current behavior.

Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.445
diff -u -r1.445 dired.el
--- lisp/dired.el       25 Nov 2009 17:11:34 -0000      1.445
+++ lisp/dired.el       4 Dec 2009 00:07:45 -0000
@@ -752,6 +752,25 @@
         buffer-read-only
         (dired-directory-changed-p dirname))))
 
+;;;###autoload
+(defcustom dired-auto-revert-buffer nil
+  "Automatically revert changed dired buffer on revisiting.
+If t, revisiting an existing dired buffer automatically reverts it.
+If its value is a predicate function that checks if directory has
+changed on disk, call this function with the directory name argument
+and revert the buffer if it returns non-nil.
+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 '(choice
+          (const :tag "Don't revert" nil)
+          (const :tag "Always revert visited dired buffer" t)
+          (const :tag "Revert changed dired buffer" dired-directory-changed-p)
+          (function :tag "Predicate function"))
+  :group 'dired
+  :version "23.2")
+
 (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).
@@ -779,6 +798,14 @@
               (setq dired-directory dir-or-list)
               ;; this calls dired-revert
               (dired-sort-other switches))
+             ;; Always revert regardless of whether it has changed or not.
+             ((eq dired-auto-revert-buffer t)
+              (revert-buffer))
+             ;; Revert when a predicate returns non-nil.
+             ((functionp dired-auto-revert-buffer)
+              (when (funcall dired-auto-revert-buffer dirname)
+                (revert-buffer)
+                (message "Changed directory automatically updated")))
              ;; If directory has changed on disk, offer to revert.
              ((when (dired-directory-changed-p dirname)
                 (message "%s"

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




reply via email to

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