]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix use of non-nil wdired-use-interactive-rename
authorStephen Berman <stephen.berman@gmx.net>
Sat, 28 Jul 2018 21:58:15 +0000 (23:58 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Sat, 28 Jul 2018 21:58:15 +0000 (23:58 +0200)
This is a fairly minimal fix for the release branch; a more
comprehensive fix is on master, so do not merge this to master.

* lisp/wdired.el (wdired-search-and-rename): Remove dired-filename
text property in order to find new filename when it only partially
replaces old filename (bug#32173).  If user quits before renaming
succeeds, restore the dired-filename text property.

lisp/wdired.el

index bb60e7777696e6e23edb5287e9454555c0d628a4..99465212bc5c3f94c1bd4bcf981758b342df5181 100644 (file)
@@ -543,19 +543,39 @@ and proceed depending on the answer."
     (goto-char (point-max))
     (forward-line -1)
     (let ((done nil)
+         (failed t)
          curr-filename)
       (while (and (not done) (not (bobp)))
         (setq curr-filename (wdired-get-filename nil t))
         (if (equal curr-filename filename-ori)
-            (progn
-              (setq done t)
-              (let ((inhibit-read-only t))
-                (dired-move-to-filename)
-                (search-forward (wdired-get-filename t) nil t)
-                (replace-match (file-name-nondirectory filename-ori) t t))
-              (dired-do-create-files-regexp
-               (function dired-rename-file)
-               "Move" 1 ".*" filename-new nil t))
+           (unwind-protect
+               (progn
+                 (setq done t)
+                 (let ((inhibit-read-only t))
+                    ;; Remove dired-filename text property in order to
+                    ;; find filename-new when it only partially
+                    ;; replaces filename-ori (bug#32173); the text
+                    ;; property is added again when renaming succeeds.
+                   (remove-text-properties
+                    (line-beginning-position) (line-end-position)
+                    '(dired-filename nil))
+                   (dired-move-to-filename)
+                   (search-forward (wdired-get-filename t) nil t)
+                   (replace-match (file-name-nondirectory filename-ori) t t))
+                 (dired-do-create-files-regexp
+                  (function dired-rename-file)
+                  "Move" 1 ".*" filename-new nil t)
+                 (setq failed nil))
+              ;; If user quits before renaming succeeds, restore the
+              ;; dired-filename text property.
+             (when failed
+               (beginning-of-line)
+               (let ((beg (re-search-forward
+                           directory-listing-before-filename-regexp
+                           (line-end-position) t))
+                     (end (dired-move-to-end-of-filename))
+                     (inhibit-read-only t))
+                 (add-text-properties beg end '(dired-filename t)))))
          (forward-line -1))))))
 
 ;; marks a list of files for deletion