* bug#48456: Revert Dired after copy/rename
@ 2021-05-15 21:45 Juri Linkov
2021-05-19 16:18 ` Juri Linkov
0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2021-05-15 21:45 UTC (permalink / raw)
To: 48456
[-- Attachment #1: Type: text/plain, Size: 458 bytes --]
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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-do-create-files-revert-buffer.patch --]
[-- Type: text/x-diff, Size: 569 bytes --]
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 8fce402c7a..12064d27d9 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2117,7 +2117,9 @@ dired-do-create-files
(lambda (from)
(expand-file-name (file-name-nondirectory from) target))
(lambda (_from) target))
- marker-char))))
+ marker-char)
+ (when (eq dired-auto-revert-buffer t)
+ (dired-fun-in-all-buffers target nil #'revert-buffer)))))
;; Read arguments for a marked-files command that wants a file name,
;; perhaps popping up the list of marked files.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#48456: Revert Dired after copy/rename
2021-05-15 21:45 bug#48456: Revert Dired after copy/rename Juri Linkov
@ 2021-05-19 16:18 ` Juri Linkov
2021-05-21 18:32 ` Juri Linkov
0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2021-05-19 16:18 UTC (permalink / raw)
To: 48456
[-- Attachment #1: Type: text/plain, Size: 516 bytes --]
> 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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-do-revert-buffer.patch --]
[-- Type: text/x-diff, Size: 1837 bytes --]
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))
\f
+(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.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#48456: Revert Dired after copy/rename
2021-05-19 16:18 ` Juri Linkov
@ 2021-05-21 18:32 ` Juri Linkov
2021-05-21 20:08 ` Basil L. Contovounesios
0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2021-05-21 18:32 UTC (permalink / raw)
To: 48456
tags 48456 fixed
close 48456 28.0.50
quit
> 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
> +(defcustom dired-do-revert-buffer nil
Now pushed to master and closed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#48456: Revert Dired after copy/rename
2021-05-21 18:32 ` Juri Linkov
@ 2021-05-21 20:08 ` Basil L. Contovounesios
2021-05-22 21:06 ` Juri Linkov
0 siblings, 1 reply; 6+ messages in thread
From: Basil L. Contovounesios @ 2021-05-21 20:08 UTC (permalink / raw)
To: Juri Linkov; +Cc: 48456
Juri Linkov <juri@linkov.net> writes:
>> 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
>> +(defcustom dired-do-revert-buffer nil
>
> Now pushed to master and closed.
Thanks, but I now see:
Test dired-test-bug30624 condition:
(ert-test-failed
((should
(dired-do-create-files 'copy 'dired-copy-file "Copy" nil))
:form
(dired-do-create-files copy dired-copy-file "Copy" nil)
:value nil))
Should the 'should' be removed? AFAICT the return value of
dired-do-create-files is unspecified (and unused).
--
Basil
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#48456: Revert Dired after copy/rename
2021-05-21 20:08 ` Basil L. Contovounesios
@ 2021-05-22 21:06 ` Juri Linkov
2021-05-24 11:04 ` Basil L. Contovounesios
0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2021-05-22 21:06 UTC (permalink / raw)
To: Basil L. Contovounesios; +Cc: 48456
> Test dired-test-bug30624 condition:
> (ert-test-failed
> ((should
> (dired-do-create-files 'copy 'dired-copy-file "Copy" nil))
> :form
> (dired-do-create-files copy dired-copy-file "Copy" nil)
> :value nil))
>
> Should the 'should' be removed? AFAICT the return value of
> dired-do-create-files is unspecified (and unused).
It's hard to guess how important the return value was.
It seems the return value of dired-do-create-files
via dired-create-files and via dired-move-to-filename
was the position of the beginning of the filename,
or nil if none found.
If it should be preserved, then dired-do-create-files
could be changed to something like this:
(prog1 (dired-create-files
...
(when (or (eq dired-do-revert-buffer t)
...
Otherwise, the 'should' should be replaced with
diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el
index 7f1743f88d..1fd14e72aa 100644
--- a/test/lisp/dired-aux-tests.el
+++ b/test/lisp/dired-aux-tests.el
@@ -109,7 +109,8 @@ dired-test-bug30624
(progn
(dired-revert)
(dired-mark-files-regexp "bug30624_file")
- (should (dired-do-create-files 'copy 'dired-copy-file "Copy" nil)))
+ (dired-do-create-files 'copy 'dired-copy-file "Copy" nil)
+ (should (dired-move-to-filename)))
(delete-directory target-dir 'recursive)
(mapc #'delete-file `(,file1 ,file2))
(kill-buffer buf)))))
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#48456: Revert Dired after copy/rename
2021-05-22 21:06 ` Juri Linkov
@ 2021-05-24 11:04 ` Basil L. Contovounesios
0 siblings, 0 replies; 6+ messages in thread
From: Basil L. Contovounesios @ 2021-05-24 11:04 UTC (permalink / raw)
To: Juri Linkov; +Cc: 48456, Tino Calancha
Juri Linkov <juri@linkov.net> writes:
>> Test dired-test-bug30624 condition:
>> (ert-test-failed
>> ((should
>> (dired-do-create-files 'copy 'dired-copy-file "Copy" nil))
>> :form
>> (dired-do-create-files copy dired-copy-file "Copy" nil)
>> :value nil))
>>
>> Should the 'should' be removed? AFAICT the return value of
>> dired-do-create-files is unspecified (and unused).
>
> It's hard to guess how important the return value was.
> It seems the return value of dired-do-create-files
> via dired-create-files and via dired-move-to-filename
> was the position of the beginning of the filename,
> or nil if none found.
>
> If it should be preserved, then dired-do-create-files
> could be changed to something like this:
>
> (prog1 (dired-create-files
> ...
> (when (or (eq dired-do-revert-buffer t)
> ...
>
> Otherwise, the 'should' should be replaced with
>
> diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el
> index 7f1743f88d..1fd14e72aa 100644
> --- a/test/lisp/dired-aux-tests.el
> +++ b/test/lisp/dired-aux-tests.el
> @@ -109,7 +109,8 @@ dired-test-bug30624
> (progn
> (dired-revert)
> (dired-mark-files-regexp "bug30624_file")
> - (should (dired-do-create-files 'copy 'dired-copy-file "Copy" nil)))
> + (dired-do-create-files 'copy 'dired-copy-file "Copy" nil)
> + (should (dired-move-to-filename)))
> (delete-directory target-dir 'recursive)
> (mapc #'delete-file `(,file1 ,file2))
> (kill-buffer buf)))))
Either (as well as ignoring the unspecified return value) sounds fine to
me. CCing Tino for comment.
Thanks,
--
Basil
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-05-24 11:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-15 21:45 bug#48456: Revert Dired after copy/rename Juri Linkov
2021-05-19 16:18 ` Juri Linkov
2021-05-21 18:32 ` Juri Linkov
2021-05-21 20:08 ` Basil L. Contovounesios
2021-05-22 21:06 ` Juri Linkov
2021-05-24 11:04 ` Basil L. Contovounesios
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.