The "easiest way" is to just define your own version of describe-function
, and bind that to C-h f
.
Take the vanilla code, and change only the call to completing-read
so that it uses the same history list that M-x
(execute-extended-command
) uses, which is extended-command-history
.
(defun my-describe-function (function)
"Display the full documentation of FUNCTION (a symbol)."
(interactive
(let ((fn (function-called-at-point))
(enable-recursive-minibuffers t)
val)
(setq val (completing-read
(if fn
(format "Describe function (default %s): " fn)
"Describe function: ")
obarray 'fboundp t nil
'extended-command-history ; <======================
(and fn (symbol-name fn))))
(list (if (equal val "") fn (intern val)))))
(if (null function)
(message "You didn't specify a function")
(help-setup-xref (list #'describe-function function)
(called-interactively-p 'interactive))
(save-excursion
(with-help-window (help-buffer)
(prin1 function)
(princ " is ")
(describe-function-1 function)
(with-current-buffer standard-output
(buffer-string))))))
(global-set-key "\C-hf" 'my-describe-function)
How did I find the original code? C-h f describe-function
, C-h k M-x
, C-h f execute-extended-command
. In the code for execute-extended-command
I saw that it reads the command name using read-extended-command
, and that calls completing-read
passing extended-command-history
as the HISTORY
argument.
smex
andhelm-M-x
? the former is in MELPA, the latter is included inhelm
, in MELPA.