bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#49836: Support ripgrep in semantic-symref-tool-grep


From: Dmitry Gutov
Subject: bug#49836: Support ripgrep in semantic-symref-tool-grep
Date: Wed, 4 Aug 2021 06:14:55 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

I think we can improve this part:

On 03.08.2021 11:10, Juri Linkov wrote:
diff --git a/lisp/cedet/semantic/symref/grep.el 
b/lisp/cedet/semantic/symref/grep.el
index 180d779a78..034f797076 100644
--- a/lisp/cedet/semantic/symref/grep.el
+++ b/lisp/cedet/semantic/symref/grep.el
@@ -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.

           (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)))))
+                         (format "\\b%s\\b" (oref tool searchfor)))))
         ;; Misc
         (b (get-buffer-create "*Semantic SymRef*"))
         (ans nil)

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.

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]