Skip to content
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 search #7370

Closed
avdv opened this issue Oct 12, 2016 · 19 comments
Closed

Support ripgrep search #7370

avdv opened this issue Oct 12, 2016 · 19 comments

Comments

@avdv
Copy link
Contributor

avdv commented Oct 12, 2016

It would be nice to have support for ripgrep for searching in spacemacs.

Unfortunately its command line options are not directly compatible with any other search tool so that it could be used as a drop in replacement for one.

@TheBB
Copy link
Collaborator

TheBB commented Oct 12, 2016

If someone writes a package for it we can use it.

@avdv
Copy link
Contributor Author

avdv commented Oct 12, 2016

Um, I not sure I get what you mean. There's a stand-alone package here...

But, is there a common agreed upon interface for search tools in spacemacs that needs to be implemented?

For the time being, I just wrote a quick wrapper script called "ag" which does a best effort translation of ag's command line options and calls "rg" instead.

@ekmecic
Copy link
Contributor

ekmecic commented Oct 13, 2016

If you're using helm-ag, you can easily substitute ripgrep for ag by setting the helm-ag-base-command to "rg --vimgrep --no-heading", as specified in the helm-ag documentation here.

Hope that helps :)

@bmag
Copy link
Collaborator

bmag commented Oct 13, 2016

And since PT and ACK support in Spacemacs is essentially helm-ag + let-binding helm-ag-base-command, that means adding support for RG should be easy. For example, the source of ACK-powered buffer search:

(defun spacemacs/helm-buffers-do-ack (&optional _)
  "Search in opened buffers with `ack'."
  (interactive)
  (let ((helm-ag-base-command "ack --nocolor --nogroup"))
    (helm-do-ag-buffers)))

@avdv
Copy link
Contributor Author

avdv commented Oct 13, 2016

@ekmecic I'm not using helm, I'm using ivy.

Anyway, I'd like spacemacs to take care of which search tool to use by just setting dotspacemacs-search-tools to "rg".

@bmag
Copy link
Collaborator

bmag commented Oct 13, 2016

For Ivy support, this and this need to be modified. Documentation and default value of dotspacemacs-search-tools will also need to change, probably. PR welcome, I guess.

Edit: also key bindings need to be added

@TheBB
Copy link
Collaborator

TheBB commented Oct 13, 2016

OP claimed the command line arguments were not compatible, so I assumed we would need another implementation. If not then that's great, this is basically ready for whomever wants to work on it.

@syl20bnr
Copy link
Owner

syl20bnr commented Oct 13, 2016

Edit: also key bindings need to be added

The current approach is cute but I don't know why I did this because it does not scale well and it is not very useful.
I'm thinking about changing the attribution of specific key bindings for each tool with something else. Some ideas:

  • use a numerical argument to force the use of a specific tool in the list
  • use the universal prefix argument to ask the user for a tool using helm/ivy

@swaroopch
Copy link
Contributor

I'm looking into this, anybody understand helm-ag well can point me in the direction on how to make helm-ag handle grouping options for rg, I see this:

screen shot 2016-10-17 at 5 02 05 pm

@koterpillar
Copy link
Contributor

rg support was just added to Helm: emacs-helm/helm#1625

@agriffis
Copy link
Contributor

WIP PR at #7490

@deb0ch
Copy link
Contributor

deb0ch commented Nov 16, 2016

Shouldn't this issue be closed, or tagged fixed in develop ?

@bmag
Copy link
Collaborator

bmag commented Nov 16, 2016

thanks @deb0ch, I forgot to label it

@Swoorup
Copy link

Swoorup commented Dec 14, 2016

In ag I could do,
SPC / and then --cpp pattern to specify the file type to search.
How do I do this with ripgrep?

@d12frosted
Copy link
Collaborator

@Swoorup I think you should 'contact' ripgrep README file. I found following examples on that page:

$ rg foo -g 'README.*'
$ rg foo -g '!*.min.js'
$ $ rg -thtml -tcss foobar

@mijoharas
Copy link
Contributor

Should we be giving multiple different lines of matches when the same match shows up multiple times on a line?

e.g. have a file with content (example_file.txt):

foobar foobar foobar

search for foobar

see

example_file.txt:1:1:foobar foobar foobar
example_file.txt:1:8:foobar foobar foobar
example_file.txt:1:15:foobar foobar foobar

show up in helm.

@agriffis
Copy link
Contributor

@mijoharas rg returns multiple results with the --vimgrep option, which is recommended by helm-ag upstream. I think helm-ag intends to parse that output though, rather than showing all the results, so this might be an upstream bug.

@agriffis
Copy link
Contributor

@mijoharas see emacsorphanage/helm-ag#293 ... we'll figure this out

agriffis added a commit to agriffis/spacemacs that referenced this issue Feb 19, 2017
See conversation with @mijoharas at
syl20bnr#7370 (comment)
and following conversation with @syohex at
emacsorphanage/helm-ag#293

In a nutshell, emacs-helm-ag recommends --vimgrep to work around a bug
in ag. It doesn't apply to ripgrep.

I also filed a PR against emacs-helm-ag to update their README, see
emacsorphanage/helm-ag#294
@syl20bnr syl20bnr closed this as completed Apr 2, 2017
@alex-ilin
Copy link
Contributor

When will this appear in the master branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests