From 831a3cb301be8390a6556244e19965285300ce91 Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Sat, 28 Jul 2018 23:58:15 +0200 Subject: [PATCH] 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 bb60e777769..99465212bc5 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 -- 2.39.2