[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#48456: Revert Dired after copy/rename
From: |
Juri Linkov |
Subject: |
bug#48456: Revert Dired after copy/rename |
Date: |
Wed, 19 May 2021 19:18:37 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) |
> This has been a problem for a long time.
> Every time after copying a file to another directory,
> there is a need to switch to the Dired buffer with the copied file,
> and revert it manually by typing 'g' to restore the correct sorting order,
> because the copied file is inserted where point was located, but not
> where it should be according to the Dired sorting order.
>
> This patch reverts the target buffer only when dired-auto-revert-buffer
> is customized to t.
It seems better to create a new option:
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index eb43ab187d..5df4d6b206 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2065,6 +2065,24 @@ dired-create-files
operation success-count))))
(dired-move-to-filename))
+(defcustom dired-do-revert-buffer nil
+ "Automatically revert Dired buffers after some operations.
+This option controls whether to refresh the directory listing in a
+Dired buffer that is the destination of copy/rename/symlink/hardlink
operations.
+If the value is t, always revert the Dired buffer updated in the result
+of Dired operations.
+If the value is a function, it is called with the destination directory name
+as a single argument, and the buffer is reverted after Dired operations
+if the function returns non-nil."
+ :type '(choice
+ (const :tag "Don't revert" nil)
+ (const :tag "Always revert destination directory" t)
+ (const :tag "Revert only local Dired buffers"
+ (lambda (dir) (not (file-remote-p dir))))
+ (function :tag "Predicate function"))
+ :group 'dired
+ :version "28.1")
+
(defun dired-do-create-files (op-symbol file-creator operation arg
&optional marker-char op1
how-to)
@@ -2168,7 +2186,12 @@ dired-do-create-files
(lambda (from)
(expand-file-name (file-name-nondirectory from) target))
(lambda (_from) target))
- marker-char))))
+ marker-char)
+ (when (or (eq dired-do-revert-buffer t)
+ (and (functionp dired-do-revert-buffer)
+ (funcall dired-do-revert-buffer target)))
+ (dired-fun-in-all-buffers (file-name-directory target) nil
+ #'revert-buffer)))))
;; Read arguments for a marked-files command that wants a file name,
;; perhaps popping up the list of marked files.