]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix wdired with (dired '(dir f1 f2 ...))
authorThierry Volpiatto <thievol@posteo.net>
Tue, 23 Aug 2022 10:03:22 +0000 (12:03 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 23 Aug 2022 10:03:22 +0000 (12:03 +0200)
* lisp/wdired.el (wdired-finish-edit): Fix wdired with (dired
'(dir f1 f2 ...)) (bug#57334).

lisp/wdired.el

index 106d57174d564faa3beb5473580fab27584892ad..09f5b069f4bf4583e7e40e0a25a685f3b1da2475 100644 (file)
@@ -537,15 +537,28 @@ non-nil means return old filename."
     (wdired-change-to-dired-mode)
     (if changes
        (progn
-         ;; If we are displaying a single file (rather than the
-         ;; contents of a directory), change dired-directory if that
-         ;; file was renamed.  (This ought to be generalized to
-         ;; handle the multiple files case, but that's less trivial).
-         (when (and (stringp dired-directory)
-                    (not (file-directory-p dired-directory))
-                    (null some-file-names-unchanged)
-                    (= (length files-renamed) 1))
-           (setq dired-directory (cdr (car files-renamed))))
+         (cond
+           ((and (stringp dired-directory)
+                 (not (file-directory-p dired-directory))
+                 (null some-file-names-unchanged)
+                 (= (length files-renamed) 1))
+            ;; If we are displaying a single file (rather than the
+           ;; contents of a directory), change dired-directory if that
+           ;; file was renamed.
+            (setq dired-directory (cdr (car files-renamed))))
+           ((and (consp dired-directory)
+                 (cdr dired-directory)
+                 files-renamed)
+            ;; Fix dired buffers created with
+            ;; (dired '(foo f1 f2 f3)).
+            (setq dired-directory
+                  (cons (car dired-directory)
+                        ;; Replace in `dired-directory' files that have
+                        ;; been modified with their new name keeping
+                        ;; the ones that are unmodified at the same place.
+                        (cl-loop for f in (cdr dired-directory)
+                                 collect (or (assoc-default f files-renamed)
+                                             f))))))
          ;; Re-sort the buffer.
          (revert-buffer)
          (let ((inhibit-read-only t))