]> git.eshelyaron.com Git - emacs.git/commitdiff
(read-extended-command): Add alternative minibuffer action
authorEshel Yaron <me@eshelyaron.com>
Mon, 22 Jul 2024 09:56:50 +0000 (11:56 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 22 Jul 2024 10:25:36 +0000 (12:25 +0200)
lisp/simple.el

index 9eb4c062694c881e78fdfe87f5b262e77627c2e9..2d2135446af84852ced6d92f439be96a336ad32c 100644 (file)
@@ -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."