It seems by default this can't be done. For example, if I try to activate helm-mini, and then from there activate helm-M-x, I get the error message: Error: Trying to run helm within a running helm session. Is there a good way around this constraint when writing a custom function?

My use case is this: I am trying to write my own function that will try to call helm-mini, but if helm is already running (i.e., if helm-alive-p evaluates to t) it will run helm-projectile-find-file instead. What I have so far is:

(defun es/helm-mini-or-projectile-find-file ()
  (if (not (helm-alive-p))
    (progn (helm-keyboard-quit)

I am trying to kill helm if it is running before calling helm-projectile-find-file, because, as mentioned above, I can't run a helm command if I am already in the middle of another helm command. However, it seems like helm-keyboard-quit breaks out of the function before helm-projectile-find-file is executed. Or perhaps there is something else wrong with my code. I am still not very proficient at all with emacs lisp. Is there a good way to get around the constraint of no helm commands during a running helm session?

1 Answer 1


(helm-run-after-exit FUNCTION &rest ARGS)

helm-run-after-exit exits current helm session, and then runs FUNCTION, so this is what you want:

(defun es/helm-mini-or-projectile-find-file ()
  (if (helm-alive-p)
      (helm-run-after-exit #'helm-projectile-find-file)

To call this command from a helm session, you need to bind a key to it since you can't use helm-M-x, e.g.,

(bind-key "C-c C-p" #'es/helm-mini-or-projectile-find-file)

Similarly, if you want to use helm-M-x from arbitrary helm commands, you can wrap helm-M-x with a new command and assign a key from helm-map to it.

(defun my-helm-M-x ()
     (lambda () (call-interactively #'helm-M-x)))))

(bind-key "M-x" #'my-helm-M-x helm-map)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.