Grep

38 views
Skip to first unread message

pulsar...@posteo.net

unread,
Jun 27, 2017, 3:45:16 PM6/27/17
to emacs...@googlegroups.com

Hi all,

I am new to helm and I love it, but I am struggling a bit to customise
it the way I want it to be, it may be me who I am not that proficient
at using Emacs more than helm.

I am currently using the helm-find-files function to browse files and I
would like to use it to specify the root directory where a grep/find
should start from.

Currently I am using C-c / when highlighting a certain folder to start
find from that directory and the difficult C-u M-g s to use grep
(recursive).

I am definitely in a need for a shortcut and I have two options in my mind:

i) When I press the TAB the actions menu pops up, unfortunately they are
not mapped to any <f*> button, is there a way to do it ? I'd like to
avoid the actions menu altogether though.

ii) Is there a way to setup a key binding which acts as an "alias" for
other keys ? Something like :

(global-set-key (kbd "<f8>") C-u M-g s)

Thanks a lot,
P.

Thierry Volpiatto

unread,
Jun 28, 2017, 12:17:48 AM6/28/17
to emacs...@googlegroups.com

You don't need find, just use:

C-x C-f (helm-find-files)
Then
C-u C-s (recursive grep)
or (better)
M-g a (AG)
or
M-g g (git-grep)

Both ag and git-grep are recursive and much faster than recursive grep,
you have though to install AG as external program, and git-grep will
work only in git repo.

pulsar...@posteo.net writes:

> i) When I press the TAB the actions menu pops up, unfortunately they are
> not mapped to any <f*> button,

They should, check your helm installation.

Also from helm-find-files, hit C-h m to have help.

--
Thierry
Gpg Key fingerprint = 6CEC 7081 AB33 E251 4AB8 5FC2 28D1 7F53 59F2 9997

Pietro

unread,
Jun 28, 2017, 5:31:08 PM6/28/17
to emacs...@googlegroups.com
Thanks a lot.

Yeah I do not need to do that, once I've pressed C-u C-s
I am presented with a list of patterns for files to choose from such as '*'
or '*.c' but I can't actually type or configure it to be something
different from what isn't there already; I resort selecting '*' and
using a more restrictive pattern for the text I am actually 'grepping'
for.

Is there a way to insert a new pattern for files' names ?



Thierry Volpiatto

Thierry Volpiatto

unread,
Jun 29, 2017, 3:25:08 AM6/29/17
to emacs...@googlegroups.com

Pietro <pulsar...@posteo.net> writes:

> Thanks a lot.
>
> Yeah I do not need to do that, once I've pressed C-u C-s
> I am presented with a list of patterns for files to choose from such as '*'
> or '*.c' but I can't actually type or configure it to be something
> different from what isn't there already;

This was a bug, I fixed it, now you should be able to specify the
extensions you want in prompt separated by a space, then press RET and
type in your pattern, you will have an error message with the command
line used printed in helm-buffer if nothing found.

However I suggest you use modern grep like AG to grep recursively, it is
much faster, no extra prompt, no prefix arg (*), it is based on
directory not files.

(*) Prefix arg in AG or git-grep are provided but have different
meaning.

To use AG you only have to install AG (configured by default)
https://github.com/ggreer/the_silver_searcher
or RG (you will have to configure it)
https://github.com/BurntSushi/ripgrep

rsw...@gmail.com

unread,
Sep 21, 2017, 11:13:57 AM9/21/17
to emacs-helm
Similar to what was said in the first post, helm could use a better, simpler interface to grep, especially for new comers.

Presently, to use helm's grep capability, one must invoke {M-x helm-find-files RET} and then use {C-u C-s}. I think there should be an additional command that immediately invokes helm grep on the current directory, as it would speed up things and be much simpler to learn.

If there is a simple way to code a function to do this with existing helm primitives, please show it. I have tried the following but it does not work. -- Thanks, Bob

(defun helm-grep ()
  "Use helm to grep over the current directory; with prefix argument, recurse into subdirectories."
  (interactive)
  (require 'helm-files)
  (helm-find-files-1 default-directory)
  (sit-for 0.2)
  ;; Prefix arg makes grep recurse subdirectories
  (let ((helm-current-prefix-arg (or current-prefix-arg '(4))))
    (call-interactively #'helm-ff-run-grep))))

Robert Weiner

unread,
Sep 27, 2017, 9:30:29 AM9/27/17
to emacs...@googlegroups.com
On Thu, Sep 21, 2017 at 11:13 AM, <rsw...@gmail.com> wrote:
Similar to what was said in the first post, helm could use a better, simpler interface to grep, especially for new comers.

Presently, to use helm's grep capability, one must invoke {M-x helm-find-files RET} and then use {C-u C-s}. I think there should be an additional command that immediately invokes helm grep on the current directory, as it would speed up things and be much simpler to learn.

If t

​​
here is a simple way to code a function to do this with existing helm primitives, please show it.

With Thierry's help, I settled on this, which works well:
​​
​​
(
​​
d
​​
e
​​
f
​​
​​
u
​​
​​
n
​​
​h
e
​​
l
​​
m
​​
-
​​
rgrep-here ()
​​
  "P
​​
e
​​
rforms a
​​
recursive grep within the current directory using helm."
  (in
​​
t
​​
eractive)
​​
  (re
​​
quire 'hel
​​
m-files) ; This requires helm-grep and defines helm-ff-default-directory.
  (le
​​
t
​​
((helm-f
​​
f-default-directory default-directory))
    (
​​
h
​​
elm-do-
​​
grep-1 (list default-directory) t 'grep)))


Reply all
Reply to author
Forward
0 new messages