Subject: Re: bug#46218: 28.0.50; find-dired errors with non-directory output

From: Stephen Berman <[email-masked]>
Date: Mon, 01 Feb 2021 17:33:23 +0100

On Sun, 31 Jan 2021 20:08:18 +0100 Stephen Berman <[email-masked]> wrote:

> 0. emacs -Q
> 1. In the following find-dired invocation adjust `<emacs/lisp>' to the
> emacs lisp source directory and then evaluate the sexp:
> (find-dired "<emacs/lisp>" "-name \"*.el\" -exec grep 'const' {} \";\"")
> => error in process filter: Invalid use of ‘\’ in replacement text
>
> This also happens with Emacs 27 but not with Emacs 26.
[...]

It occurred to me that invoking `(dired--align-all-files)' in
find-dired-sentinel might render the realigning code in
find-dired-filter superfluous.  But it turns out -- if I didn't make a
mistake or overlook something in testing -- that simply removing the
realigning code in find-dired-filter, without adding
`(dired--align-all-files)' to find-dired-sentinel, fixes all the
problems reported in this bug as well as in Bug#29803.  That is, I am
now proposing the following patch instead of the one in my previous
post:

diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index adc5672eca..68f7752110 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -323,11 +323,7 @@ find-dired-filter
 	    (save-restriction
 	      (widen)
 	      (let ((buffer-read-only nil)
-		    (beg (point-max))
-		    (l-opt (and (consp find-ls-option)
-				(string-match "l" (cdr find-ls-option))))
-		    (ls-regexp (concat "^ +[^ \t\r\n]+\\( +[^ \t\r\n]+\\) +"
-				       "[^ \t\r\n]+ +[^ \t\r\n]+\\( +[^[:space:]]+\\)")))
+		    (beg (point-max)))
 		(goto-char beg)
 		(insert string)
 		(goto-char beg)
@@ -342,18 +338,6 @@ find-dired-filter
 		(goto-char (- beg 3))	; no error if < 0
 		(while (search-forward " ./" nil t)
 		  (delete-region (point) (- (point) 2)))
-		;; Pad the number of links and file size.  This is a
-		;; quick and dirty way of getting the columns to line up
-		;; most of the time, but it's not foolproof.
-		(when l-opt
-		  (goto-char beg)
-		  (goto-char (line-beginning-position))
-		  (while (re-search-forward ls-regexp nil t)
-		    (replace-match (format "%4s" (match-string 1))
-				   nil nil nil 1)
-		    (replace-match (format "%9s" (match-string 2))
-				   nil nil nil 2)
-		    (forward-line 1)))
 		;; Find all the complete lines in the unprocessed
 		;; output and process it to add text properties.
 		(goto-char (point-max))