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: Thu, 05 Aug 2021 00:23:41 +0300 Organization: LINKOV.NET Message-ID: <87sfzo3nvm.fsf@mail.linkov.net> References: <87sfzrbke1.fsf_-_@mail.linkov.net> <875ywn556i.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="22728"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 49836@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 04 23:26:13 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 1mBOOy-0005kk-Qc for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Aug 2021 23:26:12 +0200 Original-Received: from localhost ([::1]:42936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBOOx-0005MZ-Qq for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Aug 2021 17:26:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBOOo-0005M7-PY for bug-gnu-emacs@gnu.org; Wed, 04 Aug 2021 17:26:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mBOOo-0007tx-IZ for bug-gnu-emacs@gnu.org; Wed, 04 Aug 2021 17:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mBOOo-0002aq-86 for bug-gnu-emacs@gnu.org; Wed, 04 Aug 2021 17:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Aug 2021 21:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49836 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49836-submit@debbugs.gnu.org id=B49836.16281123599959 (code B ref 49836); Wed, 04 Aug 2021 21:26:02 +0000 Original-Received: (at 49836) by debbugs.gnu.org; 4 Aug 2021 21:25:59 +0000 Original-Received: from localhost ([127.0.0.1]:45302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBOOk-0002aZ-QQ for submit@debbugs.gnu.org; Wed, 04 Aug 2021 17:25:59 -0400 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:44891) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBOOi-0002aL-Qj for 49836@debbugs.gnu.org; Wed, 04 Aug 2021 17:25:57 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id C694D60003; Wed, 4 Aug 2021 21:25:49 +0000 (UTC) In-Reply-To: (Dmitry Gutov's message of "Wed, 4 Aug 2021 06:14:55 +0300") 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:211189 Archived-At: --=-=-= Content-Type: text/plain >> @@ -150,15 +150,14 @@ semantic-symref-perform-search >> "-l ") >> ((eq (oref tool searchtype) 'regexp) >> "-nE ") >> - (t "-n "))) >> + (t (if (equal grep-program "rg") "" "-n ")))) > > It might be cleaner to see whether grep-find-template already includes that > flag, and if so, omit it. Though the search might be non-trivial if it's in > the form like "-abcn", still, that's searchable by regexp. Indeed, but such a hack is a temporary measure and can be removed later after ripgrep will be fixed. >> ;; Can't use the word boundaries: Grep >> ;; doesn't always agree with the language >> ;; syntax on those. >> - (format "\\(^\\|\\W\\)%s\\(\\W\\|$\\)" >> - (oref tool searchfor))))) >> + (format "\\b%s\\b" (oref tool searchfor))))) > > I think the original idea (surrounding with \W) is sound: after all, not > every symbol boundary in Emacs sense is a word boundary in Grep or RG. If > a method, say, ends with ?, then it won't be. I tried to search for 'soap-type-is-array?' in the Emacs tree, and ripgrep can find it with "\\b%s\\b", but Grep can't. > The problem with the above regexp is that it uses the basic syntax, instead > of Extended. But we can flip it. > > As long as we're able to ask Grep to search with Extended syntax, we can > use (format "(^|\\W)%s(\\W|$)" (oref tool searchfor)). And that can be > achieved with the same method as is used in xref-matches-in-directory: > > Something like (replace-regexp-in-string "grep " "grep -E" > grep-find-template t t), to be sure it's not ripgrep in there. > > The new user option can be used too, but I'd probably prefer a more > independent solution here. It would be more preferable not to change the existing default logic to avoid possible troubles. Since Grep with Basic syntax works fine, then better not to switch to Extended syntax. The new user option is already used in many places in grep.el in the previous patch, so it should be ok to use it in semantic-symref as well: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=semantic-symref-perform-search-rg.patch diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el index 180d779a78..b7d08409aa 100644 --- a/lisp/cedet/semantic/symref/grep.el +++ b/lisp/cedet/semantic/symref/grep.el @@ -150,15 +150,22 @@ semantic-symref-perform-search "-l ") ((eq (oref tool searchtype) 'regexp) "-nE ") - (t "-n "))) + (t (if (equal grep-program "rg") + ;; TODO: remove this after ripgrep is fixed (bug#49836) + (unless (string-search "rg -nH" grep-find-template) + "-n ") + "-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") + (format "(^|\\W)%s(\\W|$)" + (oref tool searchfor)) + (format "\\(^\\|\\W\\)%s\\(\\W\\|$\\)" + (oref tool searchfor)))))) ;; Misc (b (get-buffer-create "*Semantic SymRef*")) (ans nil) --=-=-=--