dajva / rg.el

Emacs search tool based on ripgrep
https://rgel.readthedocs.io
GNU General Public License v3.0
471 stars 38 forks source link

transient menu's glob filters are overwritten not updated while refining a search. #122

Closed gvoysey closed 2 years ago

gvoysey commented 3 years ago

A typical use of ripgrep for me is to look for something, and then progressively add --globs to filter out projects, directories, etc. that aren't germane. in rg.el, m -g seems to remove all previous --globs in favor of adding a new one, which means i'm currently retyping an increasingly long list every time.

I really prefer the UX of rg.el to repeated command line usage, but kept stubbing my toe on updating, not overwriting, the glob.

Is it possible to have consecutive applications of -g in the m transient menu persist their previous value at the minibuffer prompt?

A concrete example: "how many times is the global keyword used" is a question i had yesterday that i answered by:

rg --type py '\s*global\s+' ~/Projects

except, oh, i don't care about venvs:

 rg --type py --glob='!venv/' '\s*global\s+' ~/Projects

or, oh, huh, cpython sure uses globals a lot in tests, but who cares about that

 rg --type py --glob='!venv/' --glob='!cpython/' '\s*global\s+' ~/Projects

and, gross, so does tensorflow, thank god it's not my code ...

 rg --type py --glob='!venv/' --glob='!cpython/' --glob='!tensorflow/' '\s*global\s+' ~/Projects

and so on.

dajva commented 3 years ago

As far as I know, transient does not support this kind of multiple flags behavior. There is some kind of multi-value flags system but it seems partially broken and only handles the case where you have a single flag accepting multiple values with some kind of separator. May be some way of hacking this into transient by extending it but I don't know the package well enough to work on that efficiently. Probably a fun project though.

Meanwhile you can have this on the side of the transient menu with the following function:

(defun rg-rerun-change-flags ()
  "Change ripgrep command line flags and rerun last search."
  (interactive)
  (setf (rg-search-flags rg-cur-search)
        (split-string
         (read-from-minibuffer
          "Change flags: "
          (mapconcat #'identity (rg-search-flags rg-cur-search) " "))))
  (rg-rerun))

This will not play super nicely with the rg-menu unfortunately so I am unsure if I want to have it as a generic addition into the package. After the move to the transient menu I do prefer to have that as the main interface and mostly want to avoid side interfaces that makes the menu inconsistent. Seems the first flag of a series of flags makes it into the menu. The addition is simple and useful enough so still worth consider as a package addition.

Please try it out. Would be great with some feedback how this works for you.

gvoysey commented 2 years ago

This might not be fixable; as you surmised, it just creates inconsistencies with the transient menu.