2

I'm in the process of migrating from helm to ivy/counsel, and I would like to replicate a binding that I had in my previous setup.

When browsing the results minibuffer (for example in counsel-M-x), I would like to have the help for the current result displayed when pressing TAB. To get help currently I need to do M-o h. Since this is an ivy action, I'm not sure how to add a key binding to just TAB.

2

I've found the solution, (intern (ivy-state-current ivy-last)) will return the symbol of the current ivy result, which I can then pass to describe-function or describe-variable.

(defun counsel-describe-function-or-variable ()
  "Display help about the currently selected ivy result.
Assumes the symbol is a function and tries with a variable describe-function fails."
  (interactive)
  (let ((inhibit-message t)
        (current-symbol (intern (ivy-state-current ivy-last))))
    (condition-case nil
        (describe-function current-symbol)
      ('error
       (describe-variable current-symbol)))))

(define-key counsel-describe-map (kbd "TAB") 'counsel-describe-function-or-variable)

I didn't find a way to properly distinguish between counsel-describe-variable and the rest of the describe commands, so I catch the error and try describe-variable when describe-function fails.

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.