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

rg --vimgrep shows multiple lines #293

Closed
agriffis opened this issue Feb 17, 2017 · 8 comments
Closed

rg --vimgrep shows multiple lines #293

agriffis opened this issue Feb 17, 2017 · 8 comments

Comments

@agriffis
Copy link
Contributor

  • Emacs 25.1.1
  • Fedora 25
  • ripgrep 0.3.2
  • helm-ag--last-command is ("rg" "--smart-case" "--no-heading" "--vimgrep" "asdf")

Actual behavior

multiple lines returned for a single line containing multiple instances of the same value

screenshot from 2017-02-17 11-37-32

Expected behavior

just show one result, like ag does

Notes

helm-ag has this code for ag:

(defcustom helm-ag-base-command
  (if (helm-ag--windows-p)
      "ag --vimgrep"
    "ag --nocolor --nogroup")
  "Base command of `ag'"
  :type 'string)

I'm not sure why this uses --vimgrep on Windows and not on other platforms, but it could be the reason for the discrepancy we're seeing between ag and rg. What do you recommend?

References

syl20bnr/spacemacs#7370 (comment)

@syohex
Copy link
Contributor

syohex commented Feb 18, 2017

This is --vimgrep specification. You can get same result without Emacs and helm-ag. If you don't like that behavior, please remove --vimgrep option and try. However I don't know ripgrep well and I don't know helm-ag work without it option.

I'm not sure why this uses --vimgrep on Windows and not on other platforms, but it could be the reason for the discrepancy we're seeing between ag and rg. What do you recommend?

helm-ag expects search program(ag, rg etc) always show filename and line number and matched line(For example, test.el:83: asdf foo bar baz. We should set command line options for getting such output.

ag sometimes does not show filename on Windows , while Linux and macOS works as expected with same option. I don't understand why ag does not work on windows. --vimgrep option always show file name, so I set it for windows environment.

@agriffis
Copy link
Contributor Author

@syohex Thanks for the explanation of why you're setting --vimgrep on Windows. I think that makes it clear that we don't need to set it for ripgrep.

agriffis added a commit to agriffis/emacs-helm-ag that referenced this issue Feb 19, 2017
This also adds a reference to emacsorphanage#293 to explain the reason for using --vimgrep with ag on Windows.
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
syohex added a commit that referenced this issue Feb 20, 2017
Don't recommend --vimgrep for rg #293
@agriffis
Copy link
Contributor Author

Thanks for your help, I think we're all set here :-)

@Davidj361
Copy link

I'm confused. I'm on windows so I'm using --vimgrep, but helm-ag seems to only work with --vimgrep. However I get multiple matches per a line which is hell to scroll through.

@syohex
Copy link
Contributor

syohex commented May 8, 2020

Can you use --with-filename(-H) option instead of --vimgrep option ?

@Davidj361
Copy link

Davidj361 commented May 8, 2020

Nothing is showing.
Last ag command:

("ag" "-H" "--ignore" "TAGS" "--ignore" ".#*" "--ignore" "*.o" "--ignore" "*~" "--ignore" "*.bin" "--ignore" "*.bak" "--ignore" "*.obj" "--ignore" "*.map" "--ignore" "*.ico" "--ignore" "*.pif" "--ignore" "*.lnk" "--ignore" "*.a" "--ignore" "*.ln" "--ignore" "*.blg" "--ignore" "*.bbl" "--ignore" "*.dll" "--ignore" "*.drv" "--ignore" "*.vxd" "--ignore" "*.386" "--ignore" "*.elc" "--ignore" "*.lof" "--ignore" "*.glo" "--ignore" "*.idx" "--ignore" "*.lot" "--ignore" "*.fmt" "--ignore" "*.tfm" "--ignore" "*.class" "--ignore" "*.fas" "--ignore" "*.lib" "--ignore" "*.mem" "--ignore" "*.x86f" "--ignore" "*.sparcf" "--ignore" "*.dfsl" "--ignore" "*.pfsl" "--ignore" "*.d64fsl" "--ignore" "*.p64fsl" "--ignore" "*.lx64fsl" "--ignore" "*.lx32fsl" "--ignore" "*.dx64fsl" "--ignore" "*.dx32fsl" "--ignore" "*.fx64fsl" "--ignore" "*.fx32fsl" "--ignore" "*.sx64fsl" "--ignore" "*.sx32fsl" "--ignore" "*.wx64fsl" "--ignore" "*.wx32fsl" "--ignore" "*.fasl" "--ignore" "*.ufsl" "--ignore" "*.fsl" "--ignore" "*.dxl" "--ignore" "*.lo" "--ignore" "*.la" "--ignore" "*.gmo" "--ignore" "*.mo" "--ignore" "*.toc" "--ignore" "*.aux" "--ignore" "*.cp" "--ignore" "*.fn" "--ignore" "*.ky" "--ignore" "*.pg" "--ignore" "*.tp" "--ignore" "*.vr" "--ignore" "*.cps" "--ignore" "*.fns" "--ignore" "*.kys" "--ignore" "*.pgs" "--ignore" "*.tps" "--ignore" "*.vrs" "--ignore" "*.pyc" "--ignore" "*.pyo" "--ignore" "{arch}" "--ignore" "_darcs" "--ignore" "_MTN" "--ignore" ".bzr" "--ignore" ".hg" "--ignore" ".git" "--ignore" ".svn" "--ignore" ".src" "--ignore" "MCVS" "--ignore" "CVS" "--ignore" "RCS" "--ignore" "SCCS" "--ignore" ".idea/" "--ignore" ".ensime_cache/" "--ignore" ".eunit/" "--ignore" ".git/" "--ignore" ".hg/" "--ignore" ".fslckout/" "--ignore" "_FOSSIL_/" "--ignore" ".bzr/" "--ignore" "_darcs/" "--ignore" ".tox/" "--ignore" ".svn/" "--ignore" ".stack-work/" "--ignore" "*.zip" "input" "./")

@syohex
Copy link
Contributor

syohex commented May 8, 2020

(setq helm-ag-base-command "rg --with-filename --line-number" )

How about --with-filename and --line-number as above ? It works on my Windows machine.

@Davidj361
Copy link

Davidj361 commented May 8, 2020

Oh my mistake, if I do from M-x helm-do-ag then it works (i.e. shows results), same with projectile-ag when done from M-x. But when I do C-c p s s it doesn't work. Apparently C-c p s s is shared with helm-projectile-ag and projectile-ag. helm-projectile-ag is the one that breaks.

helm-ag--last-command for helm-projectile-ag

("rg" "--with-filename" "--line-number" "--ignore" "TAGS" "--ignore" ".#*" "--ignore" "*.o" "--ignore" "*~" "--ignore" "*.bin" "--ignore" "*.bak" "--ignore" "*.obj" "--ignore" "*.map" "--ignore" "*.ico" "--ignore" "*.pif" "--ignore" "*.lnk" "--ignore" "*.a" "--ignore" "*.ln" "--ignore" "*.blg" "--ignore" "*.bbl" "--ignore" "*.dll" "--ignore" "*.drv" "--ignore" "*.vxd" "--ignore" "*.386" "--ignore" "*.elc" "--ignore" "*.lof" "--ignore" "*.glo" "--ignore" "*.idx" "--ignore" "*.lot" "--ignore" "*.fmt" "--ignore" "*.tfm" "--ignore" "*.class" "--ignore" "*.fas" "--ignore" "*.lib" "--ignore" "*.mem" "--ignore" "*.x86f" "--ignore" "*.sparcf" "--ignore" "*.dfsl" "--ignore" "*.pfsl" "--ignore" "*.d64fsl" "--ignore" "*.p64fsl" "--ignore" "*.lx64fsl" "--ignore" "*.lx32fsl" "--ignore" "*.dx64fsl" "--ignore" "*.dx32fsl" "--ignore" "*.fx64fsl" "--ignore" "*.fx32fsl" "--ignore" "*.sx64fsl" "--ignore" "*.sx32fsl" "--ignore" "*.wx64fsl" "--ignore" "*.wx32fsl" "--ignore" "*.fasl" "--ignore" "*.ufsl" "--ignore" "*.fsl" "--ignore" "*.dxl" "--ignore" "*.lo" "--ignore" "*.la" "--ignore" "*.gmo" "--ignore" "*.mo" "--ignore" "*.toc" "--ignore" "*.aux" "--ignore" "*.cp" "--ignore" "*.fn" "--ignore" "*.ky" "--ignore" "*.pg" "--ignore" "*.tp" "--ignore" "*.vr" "--ignore" "*.cps" "--ignore" "*.fns" "--ignore" "*.kys" "--ignore" "*.pgs" "--ignore" "*.tps" "--ignore" "*.vrs" "--ignore" "*.pyc" "--ignore" "*.pyo" "--ignore" "{arch}" "--ignore" "_darcs" "--ignore" "_MTN" "--ignore" ".bzr" "--ignore" ".hg" "--ignore" ".git" "--ignore" ".svn" "--ignore" ".src" "--ignore" "MCVS" "--ignore" "CVS" "--ignore" "RCS" "--ignore" "SCCS" "--ignore" ".idea/" "--ignore" ".ensime_cache/" "--ignore" ".eunit/" "--ignore" ".git/" "--ignore" ".hg/" "--ignore" ".fslckout/" "--ignore" "_FOSSIL_/" "--ignore" ".bzr/" "--ignore" "_darcs/" "--ignore" ".tox/" "--ignore" ".svn/" "--ignore" ".stack-work/" "--ignore" "*.zip" "input" "./")

helm-ag--last-command for helm-do-ag and projectile-ag
("rg" "--with-filename" "--line-number" "input" ".")

I believe it's breaking from this: "--ignore" "*.zip" because in my shell I get:

regex parse error: *.zip
error: repetition operator missing expression

Edit: I notice for helm-projectile-ag that (setq helm-ag-base-command "ag --line-numbers --nocolor --nogroup") doesn't work but (setq helm-ag-base-command "ag --vimgrep") does. I assume it's because the first one doesn't have column numbers?

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

No branches or pull requests

3 participants