I'd like to use ivy completion to select items from my hydra rather than using the specified keymap. The use case would be for a very large hydra. I could create nested hydras, but I want to be lazy and just keep adding stuff to one large hydra without spending time organizing or formatting it. Technically, a hydra isn't required for the solution. Could also just be a list of functions, preferably with hints, and a method to select them via ivy. Thanks.


Instead of starting from hydra, I would start from counsel-M-x. This function uses ivy-read, which wants a list of possible inputs, and a function to run once you've chosen one. You can provide it a list of the commands you want to run, and use counsel-M-x-action as the function to run. Here's an example:

(defvar my/commands '(shell scroll-down text-mode))

(defun my/commands ()
  (ivy-read "Command: " my/commands
            :caller 'my-commands
            :require-match t
            :action #'counsel-M-x-action))

For customization, Ivy has "display transformers", which let you display something other than the command name. You could use this to add hints. First, add :caller 'my-commands to the ivy-read, so that this command has a name. Then, use ivy-configure to tell Ivy to use your function for displaying text:

(defun my/commands-display (candidate)
  (format "%s - add hint here" candidate))
(ivy-configure 'my-commands
  :display-transformer-fn #'my/commands-display)
| improve this answer | |
  • Thanks. This is great. Could you elaborate on ivy-set-display-transformer. Can't seem to figure out how to use it for this use case. – Fred Hansen Aug 26 at 20:05
  • Sure, l'll edit the answer with an example of ivy-set-display-transformer, which seems to have recently changed its name to ivy-configure. – amitp Aug 27 at 15:25
  • Thanks. How do I get it to display different hits for each candidate. This is what I tried, but not working. ''' (defun my/commands-display (candidate) (setq x '((scroll-down . "scroll down hint") (text-mode . "text mode hint"))) (cdr(assoc candidate x))) (ivy-configure 'my-commands :display-transformer-fn #'my/commands-display) ''' – Fred Hansen Aug 31 at 17:42
  • Looks like the display transformer receives the string that was going to be displayed, and needs to return another string. So if you change the symbols to strings it should work: (defun my/commands-display (candidate) (let ((x '(("scroll-down" . "scroll down hint") ("text-mode" . "text mode hint")))) (cdr (assoc candidate x)))) – amitp Sep 2 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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