I'm already used to press C-h f and type a function name to ask for help on that function. But if the function name is already under the cursor (e.g. while visiting the .emacs configuration file), is there a way to avoid typing the whole thing again?
My current favorite reference defun (requires popup.el):
(require 'popup) (defun describe-thing-in-popup () (interactive) (let* ((thing (symbol-at-point)) (help-xref-following t) (description (save-window-excursion (with-temp-buffer (help-mode) (help-xref-interned thing) (buffer-string))))) (popup-tip description :point (point) :around t :height 20 :scroll-bar t :margin t)))
Use that with your key binding of choice for unobtrusive help reference for
If you type
C-h f <RET>, it describes the function called by the innermost Lisp expression in the buffer around point, provided that function name is a valid, defined Lisp function. (That name appears as the default while you enter the argument.
As Sean Alfred commented above, the default for C-h f is to already preselect the function at point as the default.
But you could also use
helm-apropos which is part of the standard helm package (available from package repositories, e.g. from MELPA).
Helm apropos will preselect the function under the cursor, and I find it one of the nicest tool to locate documentation.
In addition to what others have said, if you use library
help-fns+.el then the defaulting is a bit better - the cursor needs only to be near the symbol (e.g. function name) that you want to use.
(The vanilla Emacs behavior picks up only the symbol used for the function call surrounding the cursor, even if the cursor is on top of another function name that you want to investigate. Not too good for a language that passes functions around as arguments etc.)
There are also other enhancements to the Emacs help functions in
I get Elisp documentation with lispy. There, C-1 toggles the inline doc for current function. Here's how it looks:
If the docstring is very large,
*Help* window is used instead.
You might want to have the documentation display immediately when you type C-h f on a command (that is, without having to press
<RET>), while keeping the original behaviour of being able to type the function name when you're anywhere else.
That is not so trivial to do, because function-at-point is very greedy. Telling it to display its first suggestion will result in you being unable to use C-h f's prompt almost anywhere, because it will always find a neighbour suggestion.
(defun my-describe-function-at-point () "Behaves like function-at-point, but removes the need to type <RET> when point is over a function." (interactive) (let (sym) ;; sigh, function-at-point is too clever. we want only the first half. (cond ((setq sym (ignore-errors (with-syntax-table emacs-lisp-mode-syntax-table (save-excursion (or (not (zerop (skip-syntax-backward "_w"))) (eq (char-syntax (char-after (point))) ?w) (eq (char-syntax (char-after (point))) ?_) (forward-sexp -1)) (skip-chars-forward "`'") (let ((obj (read (current-buffer)))) (and (symbolp obj) (fboundp obj) obj)))))) (describe-function sym)) (t (call-interactively 'describe-function))))) (define-key emacs-lisp-mode-map (kbd "C-h f") 'my-describe-function-at-point)