emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 831a3cb: Fix use of non-nil wdired-use-interactiv


From: Stephen Berman
Subject: [Emacs-diffs] emacs-26 831a3cb: Fix use of non-nil wdired-use-interactive-rename
Date: Sat, 28 Jul 2018 18:17:23 -0400 (EDT)

branch: emacs-26
commit 831a3cb301be8390a6556244e19965285300ce91
Author: Stephen Berman <address@hidden>
Commit: Stephen Berman <address@hidden>

    Fix use of non-nil wdired-use-interactive-rename
    
    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 | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/lisp/wdired.el b/lisp/wdired.el
index bb60e77..9946521 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]