From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#32173: 26.1; wdired: broken 'wdired-use-interactive-rename' Date: Wed, 18 Jul 2018 18:23:13 +0200 Message-ID: <87efg0343y.fsf@gmx.net> References: <87zhyrfgxu.fsf@delenn.bigo.ensc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1531930926 23228 195.159.176.226 (18 Jul 2018 16:22:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 18 Jul 2018 16:22:06 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 32173@debbugs.gnu.org To: Enrico Scholz Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 18 18:22:02 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffpDF-0005v9-Vt for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Jul 2018 18:22:02 +0200 Original-Received: from localhost ([::1]:37551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffpFN-0001ne-27 for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Jul 2018 12:24:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffpFF-0001nN-M2 for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 12:24:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffpFC-0002hx-Fb for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 12:24:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42098) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffpFC-0002hc-9t for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 12:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ffpFC-000334-0M for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 12:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Jul 2018 16:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32173 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32173-submit@debbugs.gnu.org id=B32173.153193100411666 (code B ref 32173); Wed, 18 Jul 2018 16:24:01 +0000 Original-Received: (at 32173) by debbugs.gnu.org; 18 Jul 2018 16:23:24 +0000 Original-Received: from localhost ([127.0.0.1]:47116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffpEa-000325-84 for submit@debbugs.gnu.org; Wed, 18 Jul 2018 12:23:24 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:57079) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffpEX-00031q-Tz for 32173@debbugs.gnu.org; Wed, 18 Jul 2018 12:23:22 -0400 Original-Received: from rosalinde ([178.6.211.58]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MGip3-1fsjNy0HvV-00DbQy; Wed, 18 Jul 2018 18:23:15 +0200 In-Reply-To: <87zhyrfgxu.fsf@delenn.bigo.ensc.de> (Enrico Scholz's message of "Mon, 16 Jul 2018 15:28:29 +0200") X-Provags-ID: V03:K1:8NqmkbAio1TWgTf86NhpzjJX4MZvozi6v99GvTJhDAIGzYAcbHq N7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: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:148640 Archived-At: On Mon, 16 Jul 2018 15:28:29 +0200 Enrico Scholz wrote: > Hi, > > wdired seems to misbehave when 'wdired-use-interactive-rename' is > active: > > 1. create scratch directory with a file > > mkdir /tmp/test > cd /tmp/test > touch foo.c > > 2. start emacs > > LC_ALL=C emacs -Q -nw > > 3. set option above > > M-: (setq wdired-use-interactive-rename t) > > 4. go into the folder > > C-x C-f /tmp/test > > emacs will show > > | /tmp/test: > | total used in directory 0 available 4023272 > | drwxrwxr-x. 2 ensc ensc 60 Jul 16 15:16 . > | drwxrwxrwt. 18 root root 600 Jul 16 15:17 .. > | -rw-rw-r--. 1 ensc ensc 0 Jul 16 14:58 foo.c > > 5. enter wdired mode > > C-x C-q > > 6. replace 'foo' with 'test'; e.g. > > test M-d > > 7. commit it > > C-c C-c > > > ---> emacs asks > > | Move `c' to `test.c'? [Type yn!q or C-h] > > or > > | Move `.' to `test.c'? [Type yn!q or C-h] > > (seems to differ slightly when repeating step 6). Buffer content is > malformed too (first two lines are merged, or whitespace between time > and filename is removed). > > > Confirming with 'y' will make the operation fail because the requested > source file does not exist. > > > Without the interactive rename, things seem to be fine. The bug is in wdired-search-and-rename (called when wdired-use-interactive-rename is non-nil) and is triggered by leaving part of the original file name unmodified (in the above case, the extension '.c' was not altered), which leaves the dired-filename text property, which dired-move-to-filename, called by wdired-search-and-rename, finds and moves point there, causing the subsequent search for the file name to fail. The patch below fixes this bug, according to my tests, but maybe I overlooked some corner cases. Can you try it and see if it works for you? Steve Berman diff --git a/lisp/wdired.el b/lisp/wdired.el index bb60e77776..968aac0149 100644 --- a/lisp/wdired.el +++ b/lisp/wdired.el @@ -543,19 +543,41 @@ wdired-search-and-rename (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)) + ;; If part of filename-ori is unmodified, + ;; dired-move-to-filename moves point there, which + ;; causes the search to fail (bug#32173). + ;; Removing the dired-filename text property + ;; prevents this (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