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*")
Drew
  • 75,699
  • 9
  • 109
  • 225
tobiasBora
  • 405
  • 2
  • 12

1 Answers1

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)
xuchunyang
  • 14,302
  • 1
  • 18
  • 39
  • 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 Apr 11 '20 at 11:32
  • @tobiasBora No, it's hard-coded https://github.com/emacs-helm/helm/blob/d978f20f4c4dae37108a6b50daf320986aeb7dc3/helm.el#L5110 – xuchunyang Apr 11 '20 at 11:36
  • Ok, thanks for your help! – tobiasBora Apr 11 '20 at 12:40