From: Philip Kaludercic <philipk@posteo.net>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 53644@debbugs.gnu.org, Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#53644: 29.0.50; xref-search-program breaks if programm not installed on a remote host
Date: Wed, 09 Feb 2022 09:17:27 +0000 [thread overview]
Message-ID: <878ruk4cwo.fsf@posteo.net> (raw)
In-Reply-To: <875ypotqwj.fsf@gmx.de> (Michael Albinus's message of "Wed, 09 Feb 2022 08:55:56 +0100")
[-- Attachment #1: Type: text/plain, Size: 786 bytes --]
Michael Albinus <michael.albinus@gmx.de> writes:
> Philip Kaludercic <philipk@posteo.net> writes:
>
> Hi Philip,
>
>> But the question here remains precisely what to use instead of the
>> literal "/bin/sh"?
>
> Well, if there isn't a better value, "/bin/sh" should serve as
> fallback. In my experience with Tramp, it works on most of the remote
> systems. It doesn't work on remote Android devices, for example. But
> the
> number of Emacs < 27 users, running xref-* on a remote Android device,
> is rather limited I believe.
>
> POSIX declines this assumptions. It recommends to call "command -v sh"
> in order to determine the shell path, see
> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html>.
>
> Best regards, Michael.
In that case, I'd propose this patch:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Check-if-xref-search-program-exists-on-a-remote-syst.patch --]
[-- Type: text/x-patch, Size: 6133 bytes --]
From da83d403688b4b5771d08c95975c73a1cfd593c1 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Wed, 9 Feb 2022 10:14:38 +0100
Subject: [PATCH] Check if xref-search-program exists on a remote system
* lisp/progmodes/xref.el (xref-matches-in-files): Loop through all
programmes in xref-search-program-alist as a fallback before raising
an error that the search query couldn't be executed.
---
lisp/progmodes/xref.el | 84 ++++++++++++++++++++++++++++--------------
1 file changed, 57 insertions(+), 27 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 6677b4f004..759dbb9778 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1751,44 +1751,74 @@ xref-matches-in-files
(remote-id (file-remote-p dir))
;; The 'auto' default would be fine too, but ripgrep can't handle
;; the options we pass in that case.
- (grep-highlight-matches nil)
- (command (grep-expand-template (cdr
- (or
- (assoc
- xref-search-program
- xref-search-program-alist)
- (user-error "Unknown search program `%s'"
- xref-search-program)))
- (xref--regexp-to-extended regexp))))
+ (grep-highlight-matches nil))
(when remote-id
(require 'tramp)
(setq files (mapcar
(if (tramp-tramp-file-p dir)
#'tramp-file-local-name
- #'file-local-name)
+ #'file-local-name)
files)))
(when (file-name-quoted-p (car files))
(setq files (mapcar #'file-name-unquote files)))
(with-current-buffer output
- (erase-buffer)
(with-temp-buffer
(insert (mapconcat #'identity files "\0"))
- (setq default-directory dir)
- (setq status
- (xref--process-file-region (point-min)
- (point-max)
- shell-file-name
- output
- nil
- shell-command-switch
- command)))
- (goto-char (point-min))
- (when (and (/= (point-min) (point-max))
- (not (looking-at grep-re))
- ;; TODO: Show these matches as well somehow?
- (not (looking-at "Binary file .* matches")))
- (user-error "Search failed with status %d: %s" status
- (buffer-substring (point-min) (line-end-position))))
+ (let* ((default-directory dir)
+ (xref-search-program-alist xref-search-program-alist)
+ (program (if (bound-and-true-p enable-connection-local-variables)
+ (with-connection-local-variables
+ xref-search-program)
+ xref-search-program))
+ (process-file-side-effects nil))
+ ;; In case `xref-search-program' is not installed on a
+ ;; remote system, we will speculatively try to start a
+ ;; different searcher to see if it is installed and works.
+ (catch 'ok
+ (while xref-search-program-alist
+ (with-current-buffer output
+ (erase-buffer))
+ (setq status
+ (let ((sfn shell-file-name)
+ (scs shell-command-switch))
+ (when remote-id
+ (if (bound-and-true-p enable-connection-local-variables)
+ (with-connection-local-variables
+ (setq sfn shell-file-name
+ scs shell-command-switch))
+ (setq sfn "/bin/sh")))
+ (xref--process-file-region
+ (point-min) (point-max)
+ sfn output nil scs
+ (grep-expand-template
+ (or (alist-get program xref-search-program-alist)
+ (user-error "Unknown search program `%s'" program))
+ (xref--regexp-to-extended regexp)))))
+ (with-current-buffer output
+ (goto-char (point-min))
+ (unless (and (/= (point-min) (point-max))
+ (not (looking-at grep-re))
+ ;; TODO: Show these matches as well somehow?
+ (not (looking-at "Binary file .* matches")))
+ (when (and (not (eq program xref-search-program))
+ (version<= "27" emacs-version))
+ ;; If possible and necessary, save whatever program
+ ;; was found as a connection local variable.
+ (let* ((host (file-remote-p dir 'host))
+ (profile (intern (concat "xref-remote-" host))))
+ (connection-local-set-profile-variables
+ profile `((xref-search-program . ,program)))
+ (connection-local-set-profiles
+ (list :machine host) profile)))
+ (throw 'ok t)))
+ (setq xref-search-program-alist
+ (remq (assq program xref-search-program-alist)
+ xref-search-program-alist)
+ program (caar xref-search-program-alist)))
+ (with-current-buffer output
+ (user-error "Search failed with status %d: %s" status
+ (buffer-string)
+ (buffer-substring (point-min) (line-end-position)))))))
(while (re-search-forward grep-re nil t)
(push (list (string-to-number (match-string line-group))
(match-string file-group)
--
2.34.0
[-- Attachment #3: Type: text/plain, Size: 24 bytes --]
--
Philip Kaludercic
next prev parent reply other threads:[~2022-02-09 9:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-30 23:38 bug#53644: 29.0.50; xref-search-program breaks if programm not installed on a remote host Philip Kaludercic
2022-02-04 2:00 ` Dmitry Gutov
2022-02-04 8:15 ` Michael Albinus
2022-02-04 19:45 ` Dmitry Gutov
2022-02-05 14:38 ` Michael Albinus
2022-02-07 2:57 ` Dmitry Gutov
2022-02-07 9:18 ` Michael Albinus
2022-02-07 18:34 ` Michael Albinus
2022-02-08 11:15 ` Philip Kaludercic
2022-02-08 14:59 ` Michael Albinus
2022-02-08 17:12 ` Philip Kaludercic
2022-02-08 18:30 ` Michael Albinus
2022-02-08 21:16 ` Philip Kaludercic
2022-02-09 7:55 ` Michael Albinus
2022-02-09 9:17 ` Philip Kaludercic [this message]
2022-02-12 1:04 ` Dmitry Gutov
2022-02-14 13:57 ` Philip Kaludercic
2022-02-14 14:40 ` Dmitry Gutov
2022-02-14 17:32 ` Philip Kaludercic
2022-02-15 1:27 ` Dmitry Gutov
2022-02-15 16:32 ` Philip Kaludercic
2022-02-15 16:33 ` Dmitry Gutov
2022-02-15 16:37 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878ruk4cwo.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=53644@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=michael.albinus@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.