Subject: Re: bug#33006: 27.0.50; `dired-do-find-regexp' doesn't work for remote directories

From: Michael Albinus <[email-masked]>
Date: Fri, 12 Oct 2018 14:52:48 +0200

Philipp <[email-masked]> writes:

Hi Philipp,

> 1. emacs -Q
> 2. C-x d /ssh:some-remote-host:/some/dir RET
> 3. Mark any file with `m'
> 4. A . RET
>
> Expected: File is searched for regex `.'
> Actual: user-error: Search failed with status 1: find: ‘/ssh:some-remote-host:/some/dir/file’: No such file or directory

Yep, same behaviour here.

> This is probably because `xref-collect-matches' calls
> `call-process-shell-command', which doesn't work remotely.  It should
> call `process-file-shell-command' instead.

Yes, this must be changed. But the file name needs some massage, too.

The appended patch fixes this for me. But since I don't know xref.el in
detail, I fear I introduce collateral damages. At least a second opinion
about the patch would be welcome, before I commit it to master.

Best regards, Michael.

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index c7ae40eb34..d3e3fe8da5 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -992,7 +992,7 @@ xref-collect-matches
        ;; do that reliably enough, without creating false negatives?
        (command (xref--rgrep-command (xref--regexp-to-extended regexp)
                                      files
-                                     (expand-file-name dir)
+                                     (file-local-name (expand-file-name dir))
                                      ignores))
        (def default-directory)
        (buf (get-buffer-create " *xref-grep*"))
@@ -1003,7 +1003,7 @@ xref-collect-matches
       (erase-buffer)
       (setq default-directory def)
       (setq status
-            (call-process-shell-command command nil t))
+            (process-file-shell-command command nil t))
       (goto-char (point-min))
       ;; Can't use the exit status: Grep exits with 1 to mean "no
       ;; matches found".  Find exits with 1 if any of the invocations
@@ -1151,7 +1151,8 @@ xref--collect-matches-1
             (or (null matches)
                 (> (point) line-beg))
             (re-search-forward regexp line-end t))
-      (let* ((beg-column (- (match-beginning 0) line-beg))
+      (let* ((file (and file (concat (file-remote-p default-directory) file)))
+             (beg-column (- (match-beginning 0) line-beg))
              (end-column (- (match-end 0) line-beg))
              (loc (xref-make-file-location file line beg-column))
              (summary (buffer-substring line-beg line-end)))