1

In helm, when you press TAB, you have access to the actions corresponding to the current entry. By default, they are bound to [F1],[F2]... But I don't like these shortcuts for several reasons:

  1. the F{n} keys are not easy to access on a keyboard
  2. if you have more than 12 entries, then you don't have any keybinding for them
  3. it's hard to associate any mnemonic with F{n} keys

So here is my question: how could I change the shortcuts of an helm action? I'm interested both when I wrote my own code, but also if possible to change them globally.

Here is a MWE:

(helm :sources (helm-build-sync-source "Animal"
                 :candidates '("Duck" "Elephant" "Lion")
                 :action '(("Say hello!" . (lambda (req)
                                             (message (concat "Hello" req))))
                           ("Say bye!" . (lambda (req)
                                           (message (concat "Bye " req))))
                           ("Eat" . (lambda (req)
                                      (message (concat "No, we don't eat " req "!")))))
                 :fuzzy-match t)
      :buffer "*helm test*")

1 Answer 1

1

I'm interested both when I wrote my own code

You can assign any key you want, though the UI (the modeline and the action menu) assumes F1 to F12.

change them globally.

As usual, use C-h k to learn the key binding: 1) which command it runs 2) which keymap it's attached to. Then use define-key to change it.

For example, run your code snippet to enter a helm session, C-h k <f1>

(translated from ) runs the command (lambda nil (interactive) (helm-select-nth-action 0)) (found in helm-map), which is an interactive Lisp function.

It is bound to .

(anonymous)

Not documented.

Let's make C-c C-c to do the same as <f1>

(defun foo ()
  (interactive)
  (helm-select-nth-action 0))

(define-key helm-map (kbd "C-c C-c") #'foo)
3
  • Thanks a lot! And is it possible to also modify the UI to display the new key instead of F1? And for a local change only for my specific code, I can just define the map only locally I guess?
    – tobiasBora
    Commented Apr 11, 2020 at 11:32
  • @tobiasBora No, it's hard-coded github.com/emacs-helm/helm/blob/…
    – xuchunyang
    Commented Apr 11, 2020 at 11:36
  • Ok, thanks for your help!
    – tobiasBora
    Commented Apr 11, 2020 at 12:40

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.