-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ripgrep in semantic-symref-tool-grep #39
Conversation
tags 49836 + patch
So here is the complete support for rigrep in grep.el: |
I think we can improve this part: On 03.08.2021 11:10, Juri Linkov wrote:
It might be cleaner to see whether grep-find-template already includes
I think the original idea (surrounding with \W) is sound: after all, not The problem with the above regexp is that it uses the basic syntax, As long as we're able to ask Grep to search with Extended syntax, we can Something like (replace-regexp-in-string "grep " "grep -E" The new user option can be used too, but I'd probably prefer a more |
Indeed, but such a hack is a temporary measure and can be removed later
I tried to search for 'soap-type-is-array?' in the Emacs tree,
It would be more preferable not to change the existing default logic The new user option is already used in many places in grep.el |
On 05.08.2021 00:23, Juri Linkov wrote:
Did you search through symref, or in console? If the former, it seems $ rg "\bsoap-type-is-array?\b" ChangeLog.2 $ rg "\bsoap-type-is-array?\b" ^^ no matches And $ rg "\bsoap-type-is-array?" has matches, of course.
See above. But also consider what happens if a user sees that Worse than that, any third-party package that uses grep-find-template It's a hard problem: grep.el is not prepared for abstracting like that. Further: seeing xref-search-program-alist, people asked for support for
I'm actually fine with this part.
This can work. Except the comparison should be with "grep", I think: all |
semantic-symref-grep-use-template constructs such command line: "rg ... -e \\bsoap-type-is-array\?\\b" that finds matches.
This difference could be explained in the documentation.
This already happened after trying to customize grep-find-template
Is there a package that can translate between them reliably?
Why not, semantic-symref already supports alternative tools
I'm worried about the case when the user customizes |
On 06.08.2021 03:35, Juri Linkov wrote:
The correct one will probably look like "rg ... -e \\bsoap-type-is-array\\?\\b" (same number of backslashes before '?' as before 'b'), and it won't find E.g., try searching for 'file-name-as-directory?'. Or 'carr?'.
If it comes to that, yes, but it's usually better to fix usability
The problem exists, and has been for a long time: grep.el doesn't Let's try to make sure we don't create bigger problems when fixing it.
For the limited purpose of symref/grep, we could use Note that it actually translates from a (subset of) Emacs regexp to The above function is how one can use Emacs syntax (though only limited I also saw some commits to ELPA yesterday, that show that Consult https://git.savannah.gnu.org/cgit/emacs/elpa.git/commit/?h=externals/consult&id=7bd3e44929d44cf0e17f38e943e9be2bd6014237 Not sure how mature it is (seems still in development), but perhaps we
It's easy enough for Xref, yes. It only has to support one single,
(string-match "\bgrep\b" grep-program) could take care of this. To sum up, I'm all for adding some clutches to symref/grep.el, to As for having grep-program customizable, perhaps we should add some new Or indeed have templates use Extended syntax, and grep-expand-template |
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':
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'.
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':