Giter Site home page Giter Site logo

Comments (6)

dajva avatar dajva commented on May 26, 2024

I already had a fix for rg-dwim locally that I have pushed now. See if it solves your use case.
Thanks for the report.

from rg.el.

seagle0128 avatar seagle0128 commented on May 26, 2024

Thanks for the quick fixing, @dajva. I will check once it''s merged in mepla.

from rg.el.

seagle0128 avatar seagle0128 commented on May 26, 2024

rg-dwim works well. Suggest to support in rg as well. Thanks!

from rg.el.

dajva avatar dajva commented on May 26, 2024

The rg defun is a bit of another story since the input is actually supposed to be a regexp that ripgrep's regex engine understands. In your example the ( and ) are for grouping sub expressions and needs to be escaped to be litteral. rgrep actually has the same behavior but parenthesis seems to have no special meaning so this particular example works.

So if I understand you correctly you want a way to search with a litteral string in general instead of a regexp?
I guess the problem with the current approach is that if you want to change the search term in the results buffer with r you will then have to edit a regexp, which would be confusing. It could be a short term solution though since it's trivial to implement.

I need to think a bit about this but my first thought is to have a separate entry point, rg-literal, that sets the --literal flag and in the results buffer you will have the opportunity to toggle this flag if needed. An alternative is to add this flag to rg-command-line-flags but then I just broke this for rg-dwim. :-/

Any thoughs? How does ag.el handle this?

from rg.el.

seagle0128 avatar seagle0128 commented on May 26, 2024

I think you are right. I did some tests with ag and rg.

For example, I want to search (lambda ( in the project.
ag will convert the string into this command:

ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- \(lambda\ \( .

rg will produce this:

rg --color always --colors match:fg:red -n --type elisp --column --heading -i -e \(lambda\ \( .

with this error:

Error parsing regex near 'mbda (' at character offset 8: Unclosed parenthesis.

I tried to add -F or --fixed-strings flag which means "Treat the pattern as a literal string instead of a regular expression".

rg --fixed-string --color always --colors match:fg:red -n --type elisp --column --heading -i -e \(lambda\ \( .

It worked well with no errors.

Then I did some research for the source codes of ag.el. I realized the ag command uses --literal flag by default, and ag-regexp is for the regexp search. It does make sense for the most of people, at least for me.

Of cource rg does great with the regexp by default, but a little bit inconvenient, because at the most of time the people just want to search with some fixed strings. Thinking of this, how about adding rg-regexp command to handle regexp searches and making rg to handle string searches? I think it would be simplify the implementation of rg-dwim as well.

These are just my thoughts. If I set rg-command-line-flags and rg works for me. But the effect side is rg-dwim is broken :(

(setq rg-command-line-flags '("--fixed-strings"))

Appreciate to your great work and patience!

from rg.el.

dajva avatar dajva commented on May 26, 2024

Thanks for you input. I'll look into this.
The ag.el setup definitely makes sense but I probably want to keep rg for backwards compatibility and add rg-literal. But we'll see.

from rg.el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.