Search code examples
emacsemacs-helm

how to bind helm-do-grep-1 to a key in emacs?


I am using the following.

(global-set-key [f9] 'helm-do-grep-1)

But when I press f9, It complains wrong type argument. I just want it behavior like "C-u C-c h g" to grep recursively. But type so many keys is boring.

update: I need to grep recursively. helm-do-grep run in non-recursive mode.


Solution

  • You can use

    (global-set-key [f9] 
      (lambda ()
        (interactive)
        (let ((current-prefix-arg 't))
          (call-interactively 'helm-do-grep))))
    

    Upd. If you're interested: the version with kbd sequence

    (global-set-key [f9]
      (lambda ()
       (interactive)
         (let ((minibuffer-message-timeout 0))
                    (execute-kbd-macro (read-kbd-macro "C-u C-c h g C-x Q"))))
    

    See the definition of C-x Q here https://stackoverflow.com/a/28435402/1937596