From 4946b5f602ed791f4ed390c9063156e04233bf5a Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 22 Jul 2024 11:56:50 +0200 Subject: [PATCH] (read-extended-command): Add alternative minibuffer action --- lisp/simple.el | 82 ++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 9eb4c062694..2d2135446af 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2277,45 +2277,49 @@ mode when reading the command name." (let ((predicate (or predicate read-extended-command-predicate)) (default (and (commandp (symbol-at-point)) (format "%S" (symbol-at-point))))) - ;; Read a string, completing from and restricting to the set of - ;; all defined commands. Save the command read on the - ;; extended-command history list. - (completing-read - (format-prompt - (concat (cond - ((eq current-prefix-arg '-) "- ") - ((and (consp current-prefix-arg) - (eq (car current-prefix-arg) 4)) - "C-u ") - ((and (consp current-prefix-arg) - (integerp (car current-prefix-arg))) - (format "%d " (car current-prefix-arg))) - ((integerp current-prefix-arg) - (format "%d " current-prefix-arg))) - ;; This isn't strictly correct if `execute-extended-command' - ;; is bound to anything else (e.g. [menu]). - ;; It could use (key-description (this-single-command-keys)), - ;; but actually a prompt other than "M-x" would be confusing, - ;; because "M-x" is a well-known prompt to read a command - ;; and it serves as a shorthand for "Extended command: ". - (or prompt "M-x")) - default) - (completion-table-with-metadata - obarray - `((category . command) - ;; TODO: Add a `narrow-completions-function' using - ;; `command-completion--command-for-this-buffer-function', and - ;; also for filtering out obsolete commands. - ,@(when completions-detailed - '((affixation-function . read-extended-command--affixation))))) - (lambda (sym) - (and (commandp sym) - (or (null predicate) - (condition-case-unless-debug err - (funcall predicate sym minibuffer--original-buffer) - (error (message "read-extended-command-predicate: %s: %s" - sym (error-message-string err))))))) - t nil 'extended-command-history default))) + (minibuffer-with-setup-hook + (lambda () + (setq-local minibuffer-alternative-action + (cons #'describe-function "describe"))) + ;; Read a string, completing from and restricting to the set of + ;; all defined commands. Save the command read on the + ;; extended-command history list. + (completing-read + (format-prompt + (concat (cond + ((eq current-prefix-arg '-) "- ") + ((and (consp current-prefix-arg) + (eq (car current-prefix-arg) 4)) + "C-u ") + ((and (consp current-prefix-arg) + (integerp (car current-prefix-arg))) + (format "%d " (car current-prefix-arg))) + ((integerp current-prefix-arg) + (format "%d " current-prefix-arg))) + ;; This isn't strictly correct if `execute-extended-command' + ;; is bound to anything else (e.g. [menu]). + ;; It could use (key-description (this-single-command-keys)), + ;; but actually a prompt other than "M-x" would be confusing, + ;; because "M-x" is a well-known prompt to read a command + ;; and it serves as a shorthand for "Extended command: ". + (or prompt "M-x")) + default) + (completion-table-with-metadata + obarray + `((category . command) + ;; TODO: Add a `narrow-completions-function' using + ;; `command-completion--command-for-this-buffer-function', and + ;; also for filtering out obsolete commands. + ,@(when completions-detailed + '((affixation-function . read-extended-command--affixation))))) + (lambda (sym) + (and (commandp sym) + (or (null predicate) + (condition-case-unless-debug err + (funcall predicate sym minibuffer--original-buffer) + (error (message "read-extended-command-predicate: %s: %s" + sym (error-message-string err))))))) + t nil 'extended-command-history default)))) (defun command-completion-using-modes-p (symbol buffer) "Say whether SYMBOL has been marked as a mode-specific command in BUFFER." -- 2.39.5