unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 49836@debbugs.gnu.org
Subject: bug#49836: Support ripgrep in semantic-symref-tool-grep
Date: Thu, 05 Aug 2021 00:23:41 +0300	[thread overview]
Message-ID: <87sfzo3nvm.fsf@mail.linkov.net> (raw)
In-Reply-To: <f211329a-6eb5-a85e-a735-59f098ede4fb@yandex.ru> (Dmitry Gutov's message of "Wed, 4 Aug 2021 06:14:55 +0300")

[-- Attachment #1: Type: text/plain, Size: 2264 bytes --]

>> @@ -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 <C>" "grep <C> -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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: semantic-symref-perform-search-rg.patch --]
[-- Type: text/x-diff, Size: 1573 bytes --]

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 <C> -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)

  reply	other threads:[~2021-08-04 21:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 21:05 bug#49836: Support ripgrep in semantic-symref-tool-grep Juri Linkov
2021-08-03  8:10 ` Juri Linkov
2021-08-04  3:14   ` Dmitry Gutov
2021-08-04 21:23     ` Juri Linkov [this message]
2021-08-05  3:03       ` Dmitry Gutov
2021-08-06  0:35         ` Juri Linkov
2021-08-07 14:12           ` Dmitry Gutov
2021-09-18 13:53 ` Mattias Engdegård
2021-09-18 14:14   ` Eli Zaretskii
2021-09-18 14:18     ` Mattias Engdegård
2021-09-18 14:25       ` Eli Zaretskii
2021-09-18 21:48       ` Dmitry Gutov
2021-09-18 23:53   ` Dmitry Gutov
2021-09-19  0:21     ` Jim Porter
2021-09-19 10:11       ` Mattias Engdegård
2021-09-20  0:14         ` Dmitry Gutov
2021-09-20  5:09           ` Jim Porter
2021-09-20 17:04             ` Dmitry Gutov
     [not found] <83h7elbzo3.fsf@gnu.org>
     [not found] ` <7b0409e3-fc88-b34e-9365-25356bb85859@yandex.ru>
     [not found]   ` <83bl4tbxyu.fsf@gnu.org>
     [not found]     ` <12215e07-af4e-2db7-1869-16ac92feb806@yandex.ru>
     [not found]       ` <8335q5bt9b.fsf@gnu.org>
     [not found]         ` <ee8b7d7f-abd1-42fc-a273-819ccef3c4e7@yandex.ru>
2021-09-17 16:07           ` Juri Linkov
2021-09-17 16:24             ` Lars Ingebrigtsen
2021-09-18 18:37               ` Juri Linkov

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sfzo3nvm.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=49836@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).