-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
[WIP] Add first implementation of consult-search #68
Conversation
Thank you so much for working on this. I feel like the first steps to a |
Instead of Projectile, couldn't you use the built-in |
@ackerleytng I will take a look and make some review soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ackerleytng I added some first comments!
I think what you are writing here is already good. I tend to use fewer small functions in elisp since they pollute the namespace/imenu/help-view. And there is not a big benefit in using small functions which are used only once. Furthermore elisp is not as composable as other functional programming languages.
I usually load/install the package by hand (either via load or via package-install-file) and then execute the sexps in the editor directly while editing. This allows me to adjust functions, test changes, repeat. From time to time reload everything if it is necessary. This works well for me, but maybe there is a better way to do things. |
Per #6 (comment) , consider using xref facilities, xref-search-program, xref-matches-in-files. Emacs already has support for searching using grep or ag. It'd be less code to maintain if that was reused, and the xref to completing-read code could likely be reused for other consult functions in future. |
@tomfitzhenry I also thought about that. See also https://github.com/travitch/completing-read-xref.el by @travitch. Does it make sense to have this here? @ackerleytng Could you investigate the xref facilities a bit? I am personally not very familiar with the xref facilities but I had hoped before to have things more integrated with xref. |
FTR, in Emacs 28 one could set |
@manuel-uberti Thanks! I guess it makes only sense to have the command here if it provides something on top of the standard xref function, e.g., if we have preview or some other advantages. |
You can do this in Emacs 27. It just requires xref >= 1.0.4 from https://elpa.gnu.org/packages/xref.html (setq xref-search-program 'ripgrep)
(setq xref-show-xrefs-function 'xref--show-defs-minibuffer) Then |
@tomfitzhenry what do you suggest? Does it still make sense to provide this here with preview support? The implementation could be taken/inspired by the project.el implementation. Another idea - we could try to modify the preview support such that it can enhance already existing commands. But I am not sure how easy this will be and to which commands it would apply. |
I think if consult chooses to implement this, it should only be to add on what isn't provided by xref itself. Perhaps that is preview support (which isn't a strong factor for me, but might be for others). If so, it should do so by implementing xref-show-xrefs-function, and then document how to use this, and possibly provide an interactive function to use it: (defun consult-project-ripgrep ()
(interactive)
(let ((xref-search-program 'ripgrep)
(xref-show-xrefs-function 'consult-xref-show-xrefs-function))
(call-interactively 'project-find-regexp))) I don't think we want to be in the space of customising search programs, or parsing their output. |
I think @tomfitzhenry 's suggestion pretty much solves it for me in terms of search and filtering, that output is also nicely colored, and also jumps to the column! Now for one more request - how would I implement something like wgrep-ag where, after showing all the search results in the minibuffer, I can do C-x C-e to bring up another buffer to edit all the results and then commit them back to multiple files? https://github.com/mhayashi1120/Emacs-wgrep |
@ackerleytng Do you mean you have an implementation for |
Something similar is already provided I guess: |
Actually, setting |
Nope I meant that Also, |
Perfect. Would be nice if consult preview also will works here. |
What is the status here? How should we proceed here? I guess it would still be nice to have a consult variant of |
I'm trying to get a feel of whether I like the experience of being forced to decide what i want to search for in a separate step from the filtering. If the experience from helm-projectile-ag (search and filter, interleaved) is preferred, then I might want to invest more there. For now seeing the preview of the line itself seems sufficient to me... |
I pushed a first version of |
Thanks for that. I am using it like this: (defun consult-project-rg ()
(interactive)
(let ((xref-show-xrefs-function #'consult-show-xrefs))
(call-interactively 'project-find-regexp))) But after hitting RET at the
|
@manuel-uberti It works for me. I cannot help debugging this right now - it is just a poc, maybe you can figure it out. I am not sure if I want to pursue the route via xref. Xref is only synchronous and to me it feels over-engineered for what it offers (I guess, I am not a fan of CLOS). Right now I am looking into the possibility to make the search asynchronous such that grep/rg must not have finished for the candidate selection to get started - see radian-software/selectrum#306. It would still be nice to integrate somehow via xref. What do you think? |
Asynchronous search sounds interesting, although for my use cases ripgrep is already fast enough I am happy to let it finish. About my problem with your solution: I tested it with standard Emacs minibuffer completion, no Selectrum or Icomplete involved. |
Which solution - the asynchronous one? I think this can also work with default completion. |
I meant |
See here for an updated version of the asynchronous proposal #91. The downside is that we cannot use anything from the xref infrastructure, but parsing grep/rg output is not hard. We could still generate xref-items if that is desired and in order to allow integration with xref facilities. Alternatively consult-show-xrefs could be offered for people who prefer a synchronous search with preview. |
I am closing this PR in favor of #91. There exist Independent of #91 there exists the xref branch with |
Seeking comments on code style and implementation as I learn elisp!
Question: How do you develop on consult? Do you symlink this directory into your
~/.emacs.d
?