Function: execute-extended-command
execute-extended-command is an interactive and byte-compiled function
defined in simple.el.gz.
Signature
(execute-extended-command PREFIXARG &optional COMMAND-NAME TYPED)
Documentation
Read a command name, then read the arguments and call the command.
To pass a prefix argument to the command you are
invoking, give a prefix argument to execute-extended-command.
This command provides completion when reading the command name.
Which completion candidates are shown can be controlled by
customizing read-extended-command-predicate.
Probably introduced at or before Emacs version 28.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun execute-extended-command (prefixarg &optional command-name typed)
"Read a command name, then read the arguments and call the command.
To pass a prefix argument to the command you are
invoking, give a prefix argument to `execute-extended-command'.
This command provides completion when reading the command name.
Which completion candidates are shown can be controlled by
customizing `read-extended-command-predicate'."
(declare (interactive-only command-execute))
;; FIXME: Remember the actual text typed by the user before completion,
;; so that we don't later on suggest the same shortening.
(interactive
(let ((execute-extended-command--last-typed nil))
(list current-prefix-arg
(read-extended-command)
execute-extended-command--last-typed)))
;; Emacs<24 calling-convention was with a single `prefixarg' argument.
(unless command-name
(let ((current-prefix-arg prefixarg) ; for prompt
(execute-extended-command--last-typed nil))
(setq command-name (read-extended-command))
(setq typed execute-extended-command--last-typed)))
(let* ((function (and (stringp command-name) (intern-soft command-name)))
(binding (and suggest-key-bindings
(not executing-kbd-macro)
(where-is-internal function overriding-local-map t)))
(delay-before-suggest 0)
find-shorter shorter)
(unless (commandp function)
(error "`%s' is not a valid command name" command-name))
;; If we're executing a command that's remapped, we can't actually
;; execute that command with the keymapping we've found with
;; `where-is-internal'.
(when (and binding (command-remapping function))
(setq binding nil))
;; Some features, such as novice.el, rely on this-command-keys
;; including M-x COMMAND-NAME RET.
(set--this-command-keys (concat "\M-x" (symbol-name function) "\r"))
(setq this-command function)
;; Normally `real-this-command' should never be changed, but here we really
;; want to pretend that M-x <cmd> RET is nothing more than a "key
;; binding" for <cmd>, so the command the user really wanted to run is
;; `function' and not `execute-extended-command'. The difference is
;; visible in cases such as M-x <cmd> RET and then C-x z (bug#11506).
(setq real-this-command function)
(let ((prefix-arg prefixarg))
(command-execute function 'record))
;; Ensure that we never have two of the suggest-binding timers in
;; flight.
(when execute-extended-command--binding-timer
(cancel-timer execute-extended-command--binding-timer))
(when (and suggest-key-bindings
(or binding
(and extended-command-suggest-shorter typed)))
;; If this command displayed something in the echo area, then
;; postpone the display of our suggestion message a bit.
(setq delay-before-suggest
(cond
((zerop (length (current-message))) 0)
((numberp suggest-key-bindings) suggest-key-bindings)
(t 2)))
(when (and extended-command-suggest-shorter
(not binding)
(not executing-kbd-macro)
(symbolp function)
(> (length (symbol-name function)) 2))
;; There's no binding for CMD. Let's try and find the shortest
;; string to use in M-x. But don't actually do anything yet.
(setq find-shorter t))
(when (or binding find-shorter)
(setq execute-extended-command--binding-timer
(run-at-time
delay-before-suggest nil
(lambda ()
;; If the user has typed any other commands in the
;; meantime, then don't display anything.
(when (eq function real-last-command)
;; Find shorter string.
(when find-shorter
(while-no-input
;; FIXME: Can be slow. Cache it maybe?
(setq shorter (execute-extended-command--shorter
(symbol-name function) typed))))
(when (or binding shorter)
(with-temp-message
(execute-extended-command--describe-binding-msg
function binding shorter)
(sit-for (if (numberp suggest-key-bindings)
suggest-key-bindings
2))))))))))))