unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [Patch] Behavior of dired when there already is a dired buffer of the same directory
@ 2008-08-31 22:50 Antoine Levitt
  2008-08-31 23:02 ` Lennart Borgman (gmail)
  2008-09-01  0:36 ` Miles Bader
  0 siblings, 2 replies; 13+ messages in thread
From: Antoine Levitt @ 2008-08-31 22:50 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 3695 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 5187 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-09-02 14:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-31 22:50 [Patch] Behavior of dired when there already is a dired buffer of the same directory Antoine Levitt
2008-08-31 23:02 ` Lennart Borgman (gmail)
2008-09-01 17:47   ` Mathias Dahl
2008-09-01 18:00     ` David House
2008-09-01  0:36 ` Miles Bader
2008-09-01  0:53   ` Antoine Levitt
2008-09-01  1:11     ` Lennart Borgman (gmail)
2008-09-01  1:26       ` Antoine Levitt
2008-09-01  2:47     ` Miles Bader
2008-09-01  3:06       ` Stefan Monnier
2008-09-01  7:25         ` Lennart Borgman (gmail)
2008-09-02  1:08         ` Richard M. Stallman
2008-09-02 14:00           ` Antoine Levitt

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).