From: "Antoine Levitt" <smeuuh@gmail.com>
To: emacs-devel@gnu.org
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 [thread overview]
Message-ID: <6fa54e4e0808311550p7b2524dbg8c903904a09d4474@mail.gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2008-08-31 22:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-31 22:50 Antoine Levitt [this message]
2008-08-31 23:02 ` [Patch] Behavior of dired when there already is a dired buffer of the same directory 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6fa54e4e0808311550p7b2524dbg8c903904a09d4474@mail.gmail.com \
--to=smeuuh@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).