From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs 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 Message-ID: <878ruk4cwo.fsf@posteo.net> References: <87v8y0rdz3.fsf@posteo.net> <87iltvnj3g.fsf@gmx.de> <3b4cfff4-4d95-9f8e-d5ec-db6cc492a9b8@yandex.ru> <87leypml9i.fsf@gmx.de> <01015f05-e40c-c18a-8b03-5012a3cb44ba@yandex.ru> <875ypp624b.fsf@posteo.net> <87iltptnem.fsf@gmx.de> <87k0e5uvtp.fsf@posteo.net> <87a6f1tdlt.fsf@gmx.de> <87bkzhrrd2.fsf@posteo.net> <875ypotqwj.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4126"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 53644@debbugs.gnu.org, Dmitry Gutov To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 09 10:22:52 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHjBa-0000nn-Cz for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Feb 2022 10:22:50 +0100 Original-Received: from localhost ([::1]:49492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHjBZ-0003jO-5C for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Feb 2022 04:22:49 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHj7F-0001U8-Tz for bug-gnu-emacs@gnu.org; Wed, 09 Feb 2022 04:18:22 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHj6w-00034y-55 for bug-gnu-emacs@gnu.org; Wed, 09 Feb 2022 04:18:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHj6v-0007tS-Sw for bug-gnu-emacs@gnu.org; Wed, 09 Feb 2022 04:18:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Feb 2022 09:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53644 X-GNU-PR-Package: emacs Original-Received: via spool by 53644-submit@debbugs.gnu.org id=B53644.164439825829872 (code B ref 53644); Wed, 09 Feb 2022 09:18:01 +0000 Original-Received: (at 53644) by debbugs.gnu.org; 9 Feb 2022 09:17:38 +0000 Original-Received: from localhost ([127.0.0.1]:49795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHj6X-0007lK-Hx for submit@debbugs.gnu.org; Wed, 09 Feb 2022 04:17:37 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:33635) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHj6V-0007fS-IW for 53644@debbugs.gnu.org; Wed, 09 Feb 2022 04:17:36 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 6D4FD240101 for <53644@debbugs.gnu.org>; Wed, 9 Feb 2022 10:17:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1644398249; bh=9O6cSZB443j6GMhK4ZcYZKsxZT3Gc5SFZDkpBAX2fXA=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=fM9Y+b7vvEMuDTuRBPWoS4pNI9a6EYfjU5YV3SMG7wds0wQi1npvALWFo/jHPkOWv hV4drtcfEjwEusA4uaQNqPRd0B5nWACibag1u6W5LwPHTVM8N337nadeBw4xCHI/n4 MhicEXlh0E8ARf1WWGYY3mNICnk0QLZIpiUjeZof0lry6l7k2Wyp3gVQCoI1DjwXvx 79bGqHgOrau4OersoeokxZBE92vZe5NnhiyFeGzheLa/f0VwrU8FBfFOga4a4rHjLj BfXcod3qyzZbUIZPKnqXVkqXL23P33rlel76OlW4RDYq5y4u4FbQOt8KMpM1oDYfwV vGtatL6zI/l5g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JtvRD59vYz9rxM; Wed, 9 Feb 2022 10:17:28 +0100 (CET) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <875ypotqwj.fsf@gmx.de> (Michael Albinus's message of "Wed, 09 Feb 2022 08:55:56 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226448 Archived-At: --=-=-= Content-Type: text/plain Michael Albinus writes: > Philip Kaludercic 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 > . > > Best regards, Michael. In that case, I'd propose this patch: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Check-if-xref-search-program-exists-on-a-remote-syst.patch >From da83d403688b4b5771d08c95975c73a1cfd593c1 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-= Content-Type: text/plain -- Philip Kaludercic --=-=-=--