Subject: bug#35609: 26.2; wdired-finish-edit clears find-dired listing

From: Stephen Berman <[email-masked]>
Date: Mon, 15 Jul 2019 12:54:34 +0200

On Tue, 09 Jul 2019 05:03:20 +0200 Lars Ingebrigtsen <[email-masked]> wrote:

> Alvaro Ramirez <[email-masked]> writes:
>
>> Editing a find-dired buffer (via wdired) clears the list of files after
>> saving changes.
>>
>> Steps:
>>
>> 1. M-x find-dired RET
>> 2. RET (empty or any find args should do)
>> 3. C-x C-q (dired-toggle-read-only)
>
> In Emacs 27 (on GNU/Linux), it hangs there in
>
> Debugger entered--Lisp error: (quit)
>   looking-at("^. [0-9 \11]*[.,0-9]*[BkKMGTPEZY]?[ \11]*l[^:]")
>   wdired-preprocess-symlinks()
>
> So there's been further regressions in this area, I guess...

I don't have a fix for the find-dired listing being cleared, but the
hang is due to this change:

commit 249902d5ad5d3ae3e25323c23a2f442913729ceb
Author: Roland Winkler <[email-masked]>
Date:   Tue Jun 11 16:04:45 2019 -0500

    Allow refining the *Find* buffer of find-dired. (Bug#29513)

    * find-dired.el (find-dired-refine-function): New user variable.
    (find-dired-sentinel): Use it.  Simplify.
    (find-dired-sort-by-filename): New function.

Specifically, the change in find-dired-sentinel from this:

-		(insert "\n  find " state)
-		(forward-char -1)		;Back up before \n at end of STATE.
-		(insert " at " (substring (current-time-string) 0 19))

to this:

+                  (insert "\n  find "
+                          (substring state 0 -1) ; omit \n at end of STATE.
+                          " at " (substring (current-time-string) 0 19))

Reverting this change (i.e. just these three lines) prevents the hang,
but it's not clear to me whether this was just meant to simplify the
code, as stated in the ChangeLog, or omitting the final newline is
needed for some find-dired use case.  Roland, can you elucidate?

However, independently of reverting or retaining the above lines, the
hang can also be prevented by changing wdired-preprocess-symlinks thus:

diff --git a/lisp/wdired.el b/lisp/wdired.el
index 0ccaaaca74..44f083bb7f 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -677,8 +677,7 @@ wdired-preprocess-symlinks
 				 'rear-nonsticky '(read-only))
 	      (put-text-property (match-beginning 1)
 				 (match-end 1) 'read-only nil)))
-        (forward-line)
-	(beginning-of-line)))))
+        (forward-line)))))

 (defun wdired-get-previous-link (&optional old move)

These lines are at the end of a while (not (eobp)) loop and, unless I'm
overlooking something, prior to the change to find-dired-sentinel, the
use of beginning-of-line here was a noop, since forward-line always puts
point at BOL -- except when the buffer doesn't end with a newline, and
that's why the change to find-dired-sentinel caused the find-dired hang.
Thus, reverting the above three lines of the find-dired-sentinel change
makes beginning-of-line in wdired-preprocess-symlinks strictly a noop,
while retaining that change makes calling beginning-of-line harmful, so
in any case that call should removed.  Or does anyone see a problem with
that?

Steve Berman