Subject: bug#57385: 28.1.91; project-find-regexp fails over tramp

From: Michael Albinus <[email-masked]>
Date: Fri, 26 Aug 2022 17:08:39 +0200

Dmitry Gutov <[email-masked]> writes:

Hi Dmitry,

>> Dmitry, I tested project-find-regexp over Tramp with a "mundane"
>> system
>> and it failed regardless.  It seems I figured out why.  Shell-file-name
>> (in xref-matches-in-files) seems to get its value from the local
>> machine, not from the remote one.  Therefore, it can't possibly start
>> the grep process remotely.  Any on how to fix this?
>
> Right.
>
> Michael, do you perhaps have a suggestion how xref-matches-in-files
> could use connection-local values for shell-file-name and
> shell-command-switch (when available) without losing compatibility
> with Emacs 26.1?

Hmm, the usual recommendation is to take
with-connection-local-variables, like

(with-connection-local-variables
  (xref--process-file-region (point-min)
                             (point-max)
                             shell-file-name
                             output
                             nil
                             shell-command-switch
                             command))

Unfortunately, the macro exists since Emacs 27 only, so you need to test
its availablility, and to use progn instead if it doesn't exist.

There is another trap, Tramp sets already the connection-local variable
shell-file-name to "/bin/sh". The user must overwrite this (or Tramp
must be pimped up to take whatever the user declares as "remote-shell").

Best regards, Michael.