(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))