I'm looking for something similar to Eldoc mode (hover over a function and the parameter list appears in the minibuffer), only I'd like to have a help buffer appear, as if I had just run describe-function. Is there a minor mode that will do this?

Having the help buffer be in a separate frame would be ideal, but I can figure that out at a later point. Funnily enough, I think I saw something like this for SLIME, but I haven't been able to find it again.

up vote 1 down vote accepted

For years I've used the rgr/context-help solution from the EmacsWiki for this, with some slight tweaks. A few aspects still bothered me, though, so this question inspired me to write a new variant of that as a global minor mode. Among other differences, this utilises help-xref-interned to display all (variable, function, face) kinds of help for a symbol instead of arbitrarily choosing between describe-function and describe-variable when both cells are defined.

(define-minor-mode my-contextual-help-mode
  "Displays help for the current symbol whenever the *Help* buffer is visible.

Advises `eldoc-print-current-symbol-info'."
  :lighter " C-h"
  :global t
  (require 'help-mode) ;; for `help-xref-interned'
  (message "Contextual help is %s" (if my-contextual-help-mode "on" "off"))
  (and my-contextual-help-mode
       (eldoc-mode 1)
       (eldoc-current-symbol)
       (my-contextual-help :force)))

(defadvice eldoc-print-current-symbol-info (before my-contextual-help activate)
  "Triggers contextual elisp *Help*. Enabled by `my-contextual-help-mode'."
  (and my-contextual-help-mode
       (derived-mode-p 'emacs-lisp-mode)
       (my-contextual-help)))

(defun my-contextual-help (&optional force)
  "Display function or variable at point in *Help* buffer, if visible."
  (when (or force (get-buffer-window (help-buffer)))
    (let ((sym (eldoc-current-symbol)))
      ;; If something else changes the help buffer contents, ensure we
      ;; don't immediately revert back to the current symbol's help.
      (and sym
           (not (keywordp sym))
           (not (eq sym (get 'my-contextual-help 'last-sym)))
           (put 'my-contextual-help 'last-sym sym)
           (save-selected-window
             (help-xref-interned sym))))))

(my-contextual-help-mode 1)
  • 1
    At present, switching between elisp buffers causes the help to be updated, if point is on a symbol in the new buffer. My feeling is that it's probably preferable in general to not do this, in which case using a buffer-local variable to track the last symbol will prevent that (but means that the user then needs to move off and back onto the symbol in the new buffer if they do want to see that help). If there's any consensus on this, I can update the code accordingly. – phils May 8 '16 at 12:03
  • Thanks for the quick response! This is pretty close to what I was looking for. Is there any way to make it fully replace Eldoc? That is, not have to open a preliminary Help buffer? It may sound somewhat annoying, but in that case I would toggle it with a keybinding or try to have a dedicated Help buffer frame that it would occupy. – mellowmaroon May 8 '16 at 16:14
  • 1
    The (when (or force (get-buffer-window (help-buffer))) ...) wrapper places that particular restriction, so you could just remove that. The force argument is then redundant (but harmless). – phils May 8 '16 at 20:56

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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