changeset 100066:96fae56a7d72

(wdired-finish-edit): If displaying a single file, change dired-directory if that file was renamed.
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 30 Nov 2008 05:42:35 +0000
parents ff059e39686f
children b9da91c473e1
files lisp/wdired.el
diffstat 1 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/wdired.el	Sun Nov 30 05:42:01 2008 +0000
+++ b/lisp/wdired.el	Sun Nov 30 05:42:35 2008 +0000
@@ -369,10 +369,11 @@
   (interactive)
   (wdired-change-to-dired-mode)
   (let ((changes nil)
-	(files-deleted nil)
-        (file-renames ())
 	(errors 0)
-	file-ori file-new tmp-value)
+	files-deleted
+	files-renamed
+	some-file-names-unchanged
+	file-old file-new tmp-value)
     (save-excursion
       (when (and wdired-allow-to-redirect-links
 		 (fboundp 'make-symbolic-link))
@@ -386,20 +387,32 @@
 	(setq changes (or changes (car tmp-value))))
       (goto-char (point-max))
       (while (not (bobp))
-	(setq file-ori (wdired-get-filename nil t))
-	(when file-ori
+	(setq file-old (wdired-get-filename nil t))
+	(when file-old
 	  (setq file-new (wdired-get-filename))
-          (unless (equal file-new file-ori)
+          (if (equal file-new file-old)
+	      (setq some-file-names-unchanged t)
             (setq changes t)
             (if (not file-new)		;empty filename!
-                (push file-ori files-deleted)
-              (push (cons file-ori (substitute-in-file-name file-new))
-                    file-renames))))
+                (push file-old files-deleted)
+              (push (cons file-old (substitute-in-file-name file-new))
+                    files-renamed))))
 	(forward-line -1)))
-    (when file-renames
-      (setq errors (+ errors (wdired-do-renames file-renames))))
+    (when files-renamed
+      (setq errors (+ errors (wdired-do-renames files-renamed))))
     (if changes
-        (revert-buffer) ;The "revert" is necessary to re-sort the buffer
+	(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))))
+	  ;; Re-sort the buffer.
+	  (revert-buffer))
       (let ((inhibit-read-only t))
 	(remove-text-properties (point-min) (point-max)
 				'(old-name nil end-name nil old-link nil