emacs-devel
[Top][All Lists]
Advanced

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

[Patch] Behavior of dired when there already is a dired buffer of the sa


From: Antoine Levitt
Subject: [Patch] Behavior of dired when there already is a dired buffer of the same directory
Date: Mon, 1 Sep 2008 00:50:24 +0200

Hi,
If I have a dired open on x, do external modifications on the structure of x, and rerun dired on x, emacs currently advises me to press g to revert the buffer. This is inefficient, and I'd much rather be offered to revert by a y/n prompt. The relevant function includes the commentary :
;; A pity we can't possibly do "Directory has changed - refresh? "
;; like find-file does.
cvs annotate attributes this to Richard Stallman, in 1992. I didn't find the reason why that was impossible. I contribute this patch in the hope that this comment was motivated by technical difficulties that no longer exist. It creates a new setting, dired-refresh-modified-dirs, which controls the behavior, and defaults to ask the user by y-or-no-p.
I tested it, and found no flaws. I am still not sure about a few points, notably switches : whether to reset the switches after a new invocation of dired, for instance.
I have not much experience in elisp, much less in dired, but I still hope this patch to be relevant. If it's not, feel free to disregard it.
Antoine Levitt


Here is the patch to dired.el against current CVS :
--- emacs/emacs/lisp/dired.el    2008-08-23 10:01:36.000000000 +0200
+++ /usr/share/emacs/23.0.60/lisp/dired.el    2008-09-01 00:42:55.000000000 +0200
@@ -168,6 +168,18 @@
   :type 'boolean
   :group 'dired)
 
+;;;###autoload
+(defcustom dired-refresh-modified-dirs 'ask
+  "*Controls the behavior of dired when invoked on a directory
+that already has a dired buffer.
+If t, always refresh.
+If ask, ask user.
+If nil, never refresh"
+  :type '(choice (const :tag "Refresh" t)
+         (const :tag "Ask user" ask)
+         (const :tag "Don't refresh" nil))
+  :group 'dired)
+
 ; These variables were deleted and the replacements are on files.el.
 ; We leave aliases behind for back-compatibility.
 (defvaralias 'dired-free-space-program 'directory-free-space-program)
@@ -723,15 +735,11 @@
      (dired-directory-changed-p dirname))))
 
 (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.
-  ;; A pity we can't possibly do "Directory has changed - refresh? "
-  ;; like find-file does.
+  ;; If there is an existing dired buffer for DIRNAME, decide whether
+  ;; to revert or not based on the customizable variable
+  ;; dired-refresh-modified-dirs. Note that when switches are passed
+  ;; to this function, it is always assumed that the buffer has to be
+  ;; reverted
   ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
   ;; see there.
   (let* (dirname
@@ -760,9 +768,15 @@
            (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")))))
+         (case dired-refresh-modified-dirs
+           (nil nil)
+           ('ask
+            (when (y-or-n-p "Directory has changed on disk. Refresh?")
+              (dired-revert)))
+           (t
+            (dired-revert)
+            (message
+             "Directory has changed on disk. Buffer refreshed."))))))
       ;; Else a new buffer
       (setq default-directory
         ;; We can do this unconditionally


reply via email to

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