grep all the files in the current Git repo: problem canceling

28 views
Skip to first unread message

Ted Zlatanov

unread,
Aug 17, 2015, 10:06:36 AM8/17/15
to emacs...@googlegroups.com
I wanted to quickly grep all the files in the current Git repo.

I looked at https://github.com/yasuyk/helm-git-grep (too slow, starts a
LOT of processes) and https://github.com/emacs-helm/helm-ls-git (only
lists files, doesn't grep them).

So I wrote the following, which is fast and does exactly what I need:

(global-set-key [(control kp-enter)]
(lambda ()
(interactive)
(helm-do-grep-1 (list (vc-git-root buffer-file-name)) t nil '("*"))))

Now the problem is, that when I cancel with `C-g', it gets in a weird
state where the minibuffer is still prompting and the Helm window is
editable.

If I switch focus away from Emacs and back a few times and then type
`M-x', it recovers eventually ("command tried to use minibuffer while in
minibuffer"). If you can't replicate it, I can try figuring out exactly
what happens, but it's hard to trigger edebug or anything else to see
the error location.

So my questions are:

1) am I doing the command above correctly? My goal is to a) enter a
pattern incrementally, and b) select a result or cancel. I don't want
anything else.

2) is the cancel error due to my command or an actual bug? I didn't
want to open a bug report if this is just my mistake setting it up.

Thanks
Ted

Thierry Volpiatto

unread,
Aug 17, 2015, 10:49:49 AM8/17/15
to emacs...@googlegroups.com

Ted Zlatanov <t...@lifelogs.com> writes:

> I wanted to quickly grep all the files in the current Git repo.
>
> I looked at https://github.com/yasuyk/helm-git-grep (too slow, starts a
> LOT of processes) and https://github.com/emacs-helm/helm-ls-git (only
> lists files, doesn't grep them).

Wrong.

helm-ls-git is grepping files with git-grep and with your default grep
backend (grep or ack-grep), you can also helm-occur the open buffers in
project, and finally use helm-gid (id-utils).

So from helm-ls-git, use `C-u C-u C-s' which will grep files in all your
repo with git-grep which is really fast.

> So I wrote the following, which is fast and does exactly what I need:

This is available from anywhere in helm.

> (global-set-key [(control kp-enter)]
> (lambda ()
> (interactive)
> (helm-do-grep-1 (list (vc-git-root buffer-file-name)) t nil '("*"))))
>
> Now the problem is, that when I cancel with `C-g', it gets in a weird
> state where the minibuffer is still prompting and the Helm window is
> editable.

Wrap your helm call in helm-exit-and-execute-action.

> If I switch focus away from Emacs and back a few times and then type
> `M-x', it recovers eventually ("command tried to use minibuffer while in
> minibuffer"). If you can't replicate it, I can try figuring out exactly
> what happens, but it's hard to trigger edebug or anything else to see
> the error location.
>
> So my questions are:
>
> 1) am I doing the command above correctly?

No.

> My goal is to a) enter a pattern incrementally, and b) select a result
> or cancel. I don't want anything else.
>
> 2) is the cancel error due to my command or an actual bug?

To your command.

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Thierry Volpiatto

unread,
Aug 17, 2015, 11:10:49 AM8/17/15
to emacs...@googlegroups.com

Thierry Volpiatto <thierry....@gmail.com> writes:

> Wrap your helm call in helm-exit-and-execute-action.

No, that's wrong, I didn't read carefully your code and didn't see it
was a global-command.

Thierry Volpiatto

unread,
Aug 17, 2015, 11:19:10 AM8/17/15
to emacs...@googlegroups.com

Thierry Volpiatto <thierry....@gmail.com> writes:

> Thierry Volpiatto <thierry....@gmail.com> writes:
>
>> Wrap your helm call in helm-exit-and-execute-action.
>
> No, that's wrong, I didn't read carefully your code and didn't see it
> was a global-command.

And yes your code is working fine here (slow though because there is no
filter).

Thierry Volpiatto

unread,
Aug 17, 2015, 11:31:07 AM8/17/15
to emacs...@googlegroups.com

Ted Zlatanov <t...@lifelogs.com> writes:

> I wanted to quickly grep all the files in the current Git repo.

So the best tool to achieve this actually is helm-gid, much much faster
than grep.

Ted Zlatanov

unread,
Aug 17, 2015, 12:32:50 PM8/17/15
to emacs...@googlegroups.com
On Mon, 17 Aug 2015 16:49:42 +0200 Thierry Volpiatto <thierry....@gmail.com> wrote:

TV> Ted Zlatanov <t...@lifelogs.com> writes:

>> I wanted to quickly grep all the files in the current Git repo.
>>
>> I looked at https://github.com/yasuyk/helm-git-grep (too slow, starts a
>> LOT of processes) and https://github.com/emacs-helm/helm-ls-git (only
>> lists files, doesn't grep them).

TV> helm-ls-git is grepping files with git-grep and with your default grep
TV> backend (grep or ack-grep), you can also helm-occur the open buffers in
TV> project, and finally use helm-gid (id-utils).

TV> So from helm-ls-git, use `C-u C-u C-s' which will grep files in all your
TV> repo with git-grep which is really fast.

I am sure this distinction makes sense to you and others, but from my
perspective what you suggest is a complicated UI. As I said I want to
a) enter a pattern incrementally, and b) select a result or cancel. I don't
want anything else to distract me from my task.

Let me explain, because I recall we discussed this last time (regarding
finding files) and you said I should use the full Helm interface.

I know Helm has many cool features, but I work linearly and entering the
full Helm interface is distracting to me. I have to "push" my current
work down the stack and mentally load the set of Helm commands, a pretty
big task. So for me, this kind of context switch is painfully
distracting. I don't claim anyone else has the same experience, just
trying to explain why I'm not diving head-first into the full Helm UI
every time I want to find some pattern.

TV> So the best tool to achieve this actually is helm-gid, much much faster
TV> than grep.

I looked at `helm-gid' and don't get how it would do the two steps above.

TV> Wrap your helm call in helm-exit-and-execute-action.

I'll try that. Thank you very much for your help.

Ted

Ted Zlatanov

unread,
Aug 17, 2015, 12:50:18 PM8/17/15
to emacs...@googlegroups.com
On Mon, 17 Aug 2015 12:32:39 -0400 Ted Zlatanov <t...@lifelogs.com> wrote:

TZ> On Mon, 17 Aug 2015 16:49:42 +0200 Thierry Volpiatto
TZ> <thierry....@gmail.com> wrote:

TV> Wrap your helm call in helm-exit-and-execute-action.

TZ> I'll try that. Thank you very much for your help.

I don't think `helm-exit-and-execute-action' is available globally. At
least I couldn't find a way to use it outside of Helm itself (where
`helm-alive-p').

Ted

Thierry Volpiatto

unread,
Aug 17, 2015, 12:51:17 PM8/17/15
to emacs...@googlegroups.com

Ted Zlatanov <t...@lifelogs.com> writes:

> TV> Wrap your helm call in helm-exit-and-execute-action.
>
> I'll try that. Thank you very much for your help.

No as I said in previous post I didn't realize your command is global, so
this wont work.

Your actual code is working fine here but it is slow (as expected).

As I previously said you have all the tools at your hands, up to you to
learn how to use them or not.

helm gid is working perfectly, but same, if you don't learn how to use
id-utils, it wont work.

Ted Zlatanov

unread,
Aug 17, 2015, 1:09:13 PM8/17/15
to emacs...@googlegroups.com
On Mon, 17 Aug 2015 18:51:10 +0200 Thierry Volpiatto <thierry....@gmail.com> wrote:

TV> Ted Zlatanov <t...@lifelogs.com> writes:

TV> Wrap your helm call in helm-exit-and-execute-action.
>>
>> I'll try that. Thank you very much for your help.

TV> No as I said in previous post I didn't realize your command is global, so
TV> this wont work.

TV> Your actual code is working fine here but it is slow (as expected).

OK, I see. Your followups got interleaved so it wasn't clear. Thanks
for explaining.

TV> As I previously said you have all the tools at your hands, up to you to
TV> learn how to use them or not.

You still haven't explained how "all the tools" can do the 2-step UI I
am looking for. If Helm can't do it, that's fine, but please don't
blame it on a lack of willingness to learn. I don't want to be
distracted, which is not the same thing.

TV> helm gid is working perfectly, but same, if you don't learn how to use
TV> id-utils, it wont work.

AFAIU from https://www.gnu.org/software/idutils/ you're talking about
tools that require a search index. It's hard to figure out exactly what
you mean by "working perfectly" since I could find no docs on what
`helm-gid' does or how it's supposed to integrate with a system.

Assuming it needs a search index file, that's not very useful unless the
search index is kept up to date, and `helm-gid' doesn't seem to do that.
So I need an external process to update a binary database every time I
do a `git pull' or do a global search+replace or otherwise change the
contents?

Ted

Reply all
Reply to author
Forward
0 new messages