Subject: Re: bug#40940: 27.0.91; project-query-replace-regexp stops too early

From: Eli Zaretskii <[email-masked]>
Date: Wed, 29 Apr 2020 12:24:36 +0300

> Date: Wed, 29 Apr 2020 11:37:53 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked]
> 
> > From: Simen Heggestøyl <[email-masked]>
> > Cc: Dmitry Gutov <[email-masked]>,  [email-masked],
> >   [email-masked]
> > Date: Wed, 29 Apr 2020 10:29:18 +0200
> > 
> > Eli Zaretskii <[email-masked]> writes:
> > 
> > > Is this a regression since Emacs 26?
> > 
> > project-query-replace-regexp is new in Emacs 27.
> 
> OK, so we should fix this on the release branch.

First, this is broken if the shell doesn't expand ~/ or if the Emacs
notion of the home directory is different from that of the shell.
Here's the proposed patch (ignoring the whitespace changes); OK to
push to the emacs-27 branch?

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 1f4cbe9..dbc967b 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -185,13 +185,17 @@ project--files-in-directory
   (require 'find-dired)
   (require 'xref)
   (defvar find-name-arg)
-  (let ((default-directory dir)
+  (let* ((default-directory dir)
+         (dirname (file-remote-p dir 'localname))
+         (dirname (or dirname
+                      ;; Make sure ~/ etc. in local directory name is
+                      ;; expanded and not left for the shell command
+                      ;; to interpret.
+                      (expand-file-name dir)))
          (command (format "%s %s %s -type f %s -print0"
                           find-program
-                         (file-local-name dir)
-                         (xref--find-ignores-arguments
-                          ignores
-                          (expand-file-name dir))
+                          dirname
+                          (xref--find-ignores-arguments ignores dirname)
                           (if files
                               (concat (shell-quote-argument "(")
                                       " " find-name-arg " "