Subject: bug#53644: 29.0.50; xref-search-program breaks if programm not installed on a remote host

From: Dmitry Gutov <[email-masked]>
Date: Fri, 4 Feb 2022 04:00:17 +0200

Hi Philip,

On 31.01.2022 01:38, Philip Kaludercic wrote:
> When invoking a command that respects xref-search-program via TRAMP,
> e.g. on a remote system that doesn't have (in my case ripgrep)
> installed, an error is signalled indicating that the search query
> couldn't be executed.

One way to work around this will probably involve an addition to 
find-file-hook and some code which checks (file-remote-p 
buffer-file-name) and sets xref-search-program to a particular value 
buffer-locally depending on the result.

Or an around-advice for xref-matches-in-files.

> I managed to temporarily circumvent the issue with this patch
> 
> 
> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index c812f28c1b..92c3d5c9d5 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -794,6 +794,11 @@ project-find-regexp
>     (let* ((caller-dir default-directory)
>            (pr (project-current t))
>            (default-directory (project-root pr))
> +         (xref-search-program
> +          (if (and (eq xref-search-program 'ripgrep)
> +                   (not (executable-find "rg" t)))
> +              'grep
> +              xref-search-program))
>            (files
>             (if (not current-prefix-arg)
>                 (project-files pr)
> 
> 
> but just assuming that grep is available might just push the actual
> problem aside.  Should xref-search-program be able to indicate a
> failback, and perhaps even eventually fall back onto a elisp grep that
> might be slow but at least would do the job?

This seems like it will have to call 'executable-find' every time the 
command is used on a remote host, and I imagine that's not free. 
Especially with high network lag. For fast searches (and distant/slow 
hosts) it might almost double the execution time.

A proper solution would probably look more similar to 
grep-host-defaults-alist and grep-compute-defaults.

I'm not sure whether xref should grow a separate facility like that, 
though, or whether xref-search-program can become more assimilated into 
grep.el instead.