From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Antoine Levitt" Newsgroups: gmane.emacs.devel 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 Message-ID: <6fa54e4e0808311550p7b2524dbg8c903904a09d4474@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_42491_23114117.1220223024619" X-Trace: ger.gmane.org 1220223049 14340 80.91.229.12 (31 Aug 2008 22:50:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 31 Aug 2008 22:50:49 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 01 00:51:43 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KZvli-0005ey-Sa for ged-emacs-devel@m.gmane.org; Mon, 01 Sep 2008 00:51:42 +0200 Original-Received: from localhost ([127.0.0.1]:37069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZvki-00040p-Tw for ged-emacs-devel@m.gmane.org; Sun, 31 Aug 2008 18:50:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KZvkc-00040J-Es for emacs-devel@gnu.org; Sun, 31 Aug 2008 18:50:30 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KZvka-0003zG-Hz for emacs-devel@gnu.org; Sun, 31 Aug 2008 18:50:29 -0400 Original-Received: from [199.232.76.173] (port=44020 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZvka-0003z4-Cw for emacs-devel@gnu.org; Sun, 31 Aug 2008 18:50:28 -0400 Original-Received: from ey-out-1920.google.com ([74.125.78.149]:31862) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KZvkZ-0001rr-K2 for emacs-devel@gnu.org; Sun, 31 Aug 2008 18:50:28 -0400 Original-Received: by ey-out-1920.google.com with SMTP id 4so603481eyg.24 for ; Sun, 31 Aug 2008 15:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=XTFaUAT5kqx7Nttjf5r7B6UU1uVwFnw4iF4r3TGVwjo=; b=GLuVx29aB9i6FbEd9uUTzMykWUZDI3K/v3iXurOohkIjhhrhX1fsRgc7bILxnJeBRm qatVnDSx5u2xGLUtr0089qweWjkgLgQtNUClqwaQ77+N2cJ4KmAHA0K3s7XIR1BNvHJH RQ6pzMHVjEYUH2aVtwNQrxP4sA10zfeaCUnAU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=U//zC1nMPU0a9iVf+hzyvERp0Xzg5PSwdVAAQuoG9zCPccS1zHQEyK1FkR/jzW7m/c pj1uKvdRkVu0dN9lZudfPeXHCsT4tB7jnaz7UDc8YyFb5VaBfGqYFLnVr/6QMVbzfKMm /aYMfIUHUyZVrAEP4zpSWjtHSz1Vg3oHNwiE4= Original-Received: by 10.210.80.17 with SMTP id d17mr5541317ebb.67.1220223024633; Sun, 31 Aug 2008 15:50:24 -0700 (PDT) Original-Received: by 10.210.141.18 with HTTP; Sun, 31 Aug 2008 15:50:24 -0700 (PDT) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103340 Archived-At: ------=_Part_42491_23114117.1220223024619 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_42491_23114117.1220223024619 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
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

------=_Part_42491_23114117.1220223024619--