ericdanan / counsel-projectile

Ivy UI for Projectile
286 stars 39 forks source link

Cannot search for regexp spanning multiples lines via counsel-projectile-rg #166

Open nordlow opened 4 years ago

nordlow commented 4 years ago

I want to search for a regexp where the whitespace also includes newlines, in my case, to find C-style if-expressions that have an opening brace after the close parenthesis like

if (..) 
{
    ...

The command swiper-isearch understands \n in its minibuffer input and can match such multi-line patterns via for instance if ( ) \n { but counsel-projectile-rg can't with being fed the flag -U. It would be great if it did.

I guess this is related:

https://til.hashrocket.com/posts/9zneks2cbv-multiline-matches-with-ripgrep-rg

Update:

This call rg -U 'if \(.*\) *\n *\{' matches my needs

and in Elisp

(defun counsel-projectile-rg-multiline ()
  "Search the current project with rg pattern spanning multiple lines."
  (interactive)
  (counsel-projectile-rg "--multiline"))

with minibuffer input static if ( ) \n \{ works. Is it standard to have to backquote curly braces in Ivy/Projectile-style searches?

It's not needed with Swiper so I guess we shouldn't need to do that here either for interface consistency.

ericdanan commented 4 years ago

I don't intensively search for regexps in ivy/swiper so am not sure whether it's standard to backquote curly braces. In any case I think counsel-projectile probably doesn't play any part in this because counsel-projectile-rg essentially relies on counsel-rg. You could confirm this by trying your search in counsel-rg.

The difference between counsel-rg and swiper-isearch could come from the way rg processes the regexp it receives from counsel-rg I imagine. Whether or not this is something that counsel-rg should address I don't know. I would suggest to submit the issue on the swiper repo.