From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#49836: Support ripgrep in semantic-symref-tool-grep Date: Tue, 03 Aug 2021 00:05:02 +0300 Organization: LINKOV.NET Message-ID: <87sfzrbke1.fsf_-_@mail.linkov.net> 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="16659"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 49836@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 02 23:40:23 2021 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 1mAffa-00046E-Uj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Aug 2021 23:40:23 +0200 Original-Received: from localhost ([::1]:49014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAffZ-0005SH-E9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Aug 2021 17:40:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAffG-0005Ru-8B for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 17:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAffF-0008Vw-Vv for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 17:40:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mAffF-0007LV-SB for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 17:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Aug 2021 21:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49836 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162794036228186 (code B ref -1); Mon, 02 Aug 2021 21:40:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Aug 2021 21:39:22 +0000 Original-Received: from localhost ([127.0.0.1]:39416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAfec-0007KX-9A for submit@debbugs.gnu.org; Mon, 02 Aug 2021 17:39:22 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:36516) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAfea-0007KP-Kn for submit@debbugs.gnu.org; Mon, 02 Aug 2021 17:39:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAfea-0005PL-Cn for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 17:39:20 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:52931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAfeX-0007yf-IF for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 17:39:19 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 60B87E0002 for ; Mon, 2 Aug 2021 21:39:11 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.196; envelope-from=juri@linkov.net; helo=relay4-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:211083 Archived-At: --=-=-= Content-Type: text/plain Creating a separate bug report from bug#49731 because this is a real problem. Now grep.el completely supports ripgrep when 'grep-find-template' is customized to a command line that uses 'rg' such as e.g. "find -type f -print0 | sort -z | xargs -0 -e rg -nH --no-heading -j8 --sort path -M 200 --max-columns-preview -e " But such grep setting breaks the command 'xref-find-references': >>>> 1. while xref-find-references works fine in `emacs -Q`, >>>> I don't know why with my customization typing e.g. >>>> 'M-? isearch-lazy-highlight RET' reports >>>> "No references found for: isearch-lazy-highlight". >>> >>> Try and see which of the "tools" semantic-symref-perform-search ends >>> up using. >> >> Thanks for the pointers to semantic-symref-perform-search. >> It prepends "-n " to my customized pattern "rg -nH", >> so the arg "-n" is duplicated on the command line: >> `rg -n -nH` >> and signals the error: >> error: The argument '--line-number' was provided more than once, but >> cannot be used multiple times >> This error is caused by the bug in the command line parser used by >> ripgrep: >> https://github.com/clap-rs/clap/issues/2171 >> that was fixed only 6 months ago, so it will take much time >> before this fix will reach ripgrep, and this bug will be closed: >> https://github.com/BurntSushi/ripgrep/issues/1701 > > The above might be worked around with creating a symref-grep specific user > option for grep-find-template which would default to the "global" value of > that variable. Maybe like the existing option 'semantic-symref-grep-shell', e.g.: (defcustom semantic-symref-grep-program 'grep "The program to use for regexp search inside files." :type `(choice (const :tag "Use Grep" grep) (const :tag "Use ripgrep" ripgrep) (symbol :tag "User defined")) :version "28.1") But the problem is that for users it's hard to see the connection between the broken 'xref-find-references' and the need to customize an option with unrelated name 'semantic-symref-grep'. >> But even without duplicated "-n" semantic-symref-perform-search >> doesn't work with ripgrep because it doesn't find such pattern: >> \\\\\\(\\^\\\\\\|\\\\W\\\\\\)isearch-lazy-highlight\\\\\\(\\\\W\\\\\\|\\$\\\\\\) >> Maybe semantic-symref-perform-search could be improved to >> support ripgrep? >> Because without these two problems it works fine with ripgrep. > > ...but the above tells us (I think) that semantic-symref-perform-search is > trying to use the basic regexp syntax, and ripgrep doesn't support that > (only Extended, or PCRE). > > For your personal consumption, perhaps the best approach is to create > a separate "tool", like Grep (by copying symref/grep.el and tweaking some > of its definitions), and then register it in semantic-symref-tool-alist. > > I don't know if ripgrep is that much faster for this particular purpose. So > maybe it's too much work for little benefit. A more general solution would be to add to grep.el the same options that you added to xref: xref-search-program grep/ripgrep xref-search-program-alist '((grep . "xargs -0 grep -snHE -e ") (ripgrep . "xargs -0 rg -nH --no-messages -g '!*/' -e | sort -t: -k1,1 -k2n,2")) This means to turn the existing variable 'grep-program' into the user option as the following patch does. Also later grep.el could use the value "rg" of 'grep-program' to create the corresponding grep-find-template in grep-compute-defaults. But I don't know if it's ok to mention rigrep in grep.el? Anyway, here is the patch that fixes 'xref-find-references': --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=grep-program.patch diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 8f0a5acf70..aba4d59371 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -484,9 +484,13 @@ grep-mode-font-lock-keywords This gets tacked on the end of the generated expressions.") ;;;###autoload -(defvar grep-program (purecopy "grep") +(defcustom grep-program (purecopy "grep") "The default grep program for `grep-command' and `grep-find-command'. -This variable's value takes effect when `grep-compute-defaults' is called.") +This variable's value takes effect when `grep-compute-defaults' is called." + :type `(choice + (const :tag "Use Grep" "grep") + (string :tag "User defined")) + :version "28.1") ;;;###autoload (defvar find-program (purecopy "find") diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el index 180d779a78..e13c21bc07 100644 --- a/lisp/cedet/semantic/symref/grep.el +++ b/lisp/cedet/semantic/symref/grep.el @@ -150,15 +150,17 @@ semantic-symref-perform-search "-l ") ((eq (oref tool searchtype) 'regexp) "-nE ") - (t "-n "))) + (t (if (equal grep-program "rg") "" "-n ")))) (greppat (cond ((eq (oref tool searchtype) 'regexp) (oref tool searchfor)) (t ;; Can't use the word boundaries: Grep ;; doesn't always agree with the language ;; syntax on those. - (format "\\(^\\|\\W\\)%s\\(\\W\\|$\\)" - (oref tool searchfor))))) + (if (equal grep-program "rg") + (oref tool searchfor) + (format "\\(^\\|\\W\\)%s\\(\\W\\|$\\)" + (oref tool searchfor)))))) ;; Misc (b (get-buffer-create "*Semantic SymRef*")) (ans nil) --=-=-=--