helm-M-x with initial inpu

20 views
Skip to first unread message

Louis Pan

unread,
Jun 15, 2016, 7:51:19 AM6/15/16
to emacs-helm
Hi, I'm wondering if it is possible to bind a key to 'helm-M-x with some initial input.

Use case: eg.
(global-set-key (kbd "M-p") (apply-partially #'helm-M-x-with "helm-projectile"))

I'd like to bind a key to "helm-projectile" so the one key brings up helm with an already narrowed down list of candidates.

Currently, I am using "M-x" then typing "helm proj" manually, but I'm hoping that I'll be able to skip a step.

I apologise if this is possible and  documented somewhere, but my google fu has failed me.

Louis

Michael Heerdegen

unread,
Jun 15, 2016, 10:30:14 PM6/15/16
to emacs...@googlegroups.com
Louis Pan <lo...@pan.me> writes:

> Hi, I'm wondering if it is possible to bind a key to 'helm-M-x with
> some initial input.
>
> Use case: eg. (global-set-key (kbd "M-p") (apply-partially
> #'helm-M-x-with "helm-projectile"))
>
> I'd like to bind a key to "helm-projectile" so the one key brings up
> helm with an already narrowed down list of candidates.

I don't know of a built-in solution. I would try with
`minibuffer-with-setup-hook', like in

#+begin_src emacs-lisp
(minibuffer-with-setup-hook
(lambda () (insert "helm-"))
(helm-M-x-read-extended-command))
#+end_src


Regards,

Michael.

Louis Pan

unread,
Jun 16, 2016, 9:05:31 AM6/16/16
to emacs...@googlegroups.com
Thank you Micheal. You are awesome, your code snippet worked perfectly!!


--
You received this message because you are subscribed to a topic in the Google Groups "emacs-helm" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emacs-helm/oajEe5ERLkY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emacs-helm+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Louis Pan

unread,
Jun 16, 2016, 9:45:45 AM6/16/16
to emacs...@googlegroups.com
I spoke too soon, but I only had to modify your code a little bit. Your idea was essential to getting it working. The following works:

(defun helm-M-x-with (str)
  (minibuffer-with-setup-hook
       (lambda () (insert str))
    (call-interactively 'helm-M-x)))

(global-set-key (kbd "M-p") #'(lambda () (interactive) (helm-M-x-with "helm-projectile ")))


Michael Heerdegen

unread,
Jun 16, 2016, 9:58:24 AM6/16/16
to emacs...@googlegroups.com
Louis Pan <loui...@gmail.com> writes:

> I spoke too soon, but I only had to modify your code a little bit. Your idea was essential
> to getting it working. The following works:
>
> (defun helm-M-x-with (str)
> (minibuffer-with-setup-hook
> (lambda () (insert str))
> (call-interactively 'helm-M-x)))
>
> (global-set-key (kbd "M-p") #'(lambda () (interactive) (helm-M-x-with "helm-projectile
> ")))

Yeah, I thought you would figure out the rest, it was already late ;-)

Reply all
Reply to author
Forward
0 new messages