GNU bug report logs - #48456
Revert Dired after copy/rename

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Sat, 15 May 2021 21:49:02 UTC

Severity: normal

Tags: fixed

Fixed in version 28.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 48456 in the body.
You can then email your comments to 48456 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Sat, 15 May 2021 21:49:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 15 May 2021 21:49:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Revert Dired after copy/rename
Date: Sun, 16 May 2021 00:45:58 +0300
[Message part 1 (text/plain, inline)]
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:

[dired-do-create-files-revert-buffer.patch (text/x-diff, inline)]
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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Wed, 19 May 2021 16:33:02 GMT) Full text and rfc822 format available.

Message #8 received at 48456 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 48456 <at> debbugs.gnu.org
Subject: Re: bug#48456: Revert Dired after copy/rename
Date: Wed, 19 May 2021 19:18:37 +0300
[Message part 1 (text/plain, inline)]
> 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:

[dired-do-revert-buffer.patch (text/x-diff, inline)]
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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Fri, 21 May 2021 18:33:01 GMT) Full text and rfc822 format available.

Message #11 received at 48456 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 48456 <at> debbugs.gnu.org
Subject: Re: bug#48456: Revert Dired after copy/rename
Date: Fri, 21 May 2021 21:32:29 +0300
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.




Added tag(s) fixed. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Fri, 21 May 2021 18:33:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.0.50, send any further explanations to 48456 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Fri, 21 May 2021 18:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Fri, 21 May 2021 20:09:02 GMT) Full text and rfc822 format available.

Message #18 received at 48456 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Juri Linkov <juri <at> linkov.net>
Cc: 48456 <at> debbugs.gnu.org
Subject: Re: bug#48456: Revert Dired after copy/rename
Date: Fri, 21 May 2021 21:08:33 +0100
Juri Linkov <juri <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Sat, 22 May 2021 21:15:02 GMT) Full text and rfc822 format available.

Message #21 received at 48456 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 48456 <at> debbugs.gnu.org
Subject: Re: bug#48456: Revert Dired after copy/rename
Date: Sun, 23 May 2021 00:06:23 +0300
>   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)))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48456; Package emacs. (Mon, 24 May 2021 11:05:01 GMT) Full text and rfc822 format available.

Message #24 received at 48456 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Juri Linkov <juri <at> linkov.net>
Cc: 48456 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#48456: Revert Dired after copy/rename
Date: Mon, 24 May 2021 12:04:14 +0100
Juri Linkov <juri <at> 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




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 21 Jun 2021 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.