Function: command-execute

command-execute is a byte-compiled function defined in simple.el.gz.

Signature

(command-execute CMD &optional RECORD-FLAG KEYS SPECIAL)

Documentation

Execute CMD as an editor command.

CMD must be a symbol that satisfies the commandp predicate.

Optional second arg RECORD-FLAG non-nil means unconditionally put this command in the variable command-history(var)/command-history(fun). Otherwise, that is done only if an arg is read using the minibuffer.

The argument KEYS specifies the value to use instead of the return value of the this-command-keys function when reading the arguments; if it is nil, this-command-keys is used.

The argument SPECIAL, if non-nil, means that this command is executing a special event, so ignore the prefix argument and don't clear it.

View in manual

Probably introduced at or before Emacs version 19.30.

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun command-execute (cmd &optional record-flag keys special)
  ;; BEWARE: Called directly from the C code.
  "Execute CMD as an editor command.
CMD must be a symbol that satisfies the `commandp' predicate.

Optional second arg RECORD-FLAG non-nil means unconditionally put
this command in the variable `command-history'.  Otherwise, that
is done only if an arg is read using the minibuffer.

The argument KEYS specifies the value to use instead of the
return value of the `this-command-keys' function when reading the
arguments; if it is nil, `this-command-keys' is used.

The argument SPECIAL, if non-nil, means that this command is
executing a special event, so ignore the prefix argument and
don't clear it."
  (setq debug-on-next-call nil)
  (let ((prefixarg (unless special
                     ;; FIXME: This should probably be done around
                     ;; pre-command-hook rather than here!
                     (prog1 prefix-arg
                       (setq current-prefix-arg prefix-arg)
                       (setq prefix-arg nil)
                       (when current-prefix-arg
                         (prefix-command-update)))))
        query)
    (if (and (symbolp cmd)
             (get cmd 'disabled)
             (or (and (setq query (and (consp (get cmd 'disabled))
                                       (eq (car (get cmd 'disabled)) 'query)))
                      (not (command-execute--query cmd)))
                 (and (not query) disabled-command-function)))
        (when (not query)
          ;; FIXME: Weird calling convention!
          (run-hooks 'disabled-command-function))
      (let ((final cmd))
        (while
            (progn
              (setq final (indirect-function final))
              (if (autoloadp final)
                  (setq final (autoload-do-load final cmd)))))
        (cond
         ((arrayp final)
          ;; If requested, place the macro in the command history.  For
          ;; other sorts of commands, call-interactively takes care of this.
          (when record-flag
            (add-to-history
             'command-history `(execute-kbd-macro ,final ,prefixarg) nil t))
          (execute-kbd-macro final prefixarg))
         (t
          ;; Pass `cmd' rather than `final', for the backtrace's sake.
          (prog1 (call-interactively cmd record-flag keys)
            (when-let ((info
                        (and (symbolp cmd)
                             (not (get cmd 'command-execute-obsolete-warned))
                             (get cmd 'byte-obsolete-info))))
              (put cmd 'command-execute-obsolete-warned t)
              (message "%s" (macroexp--obsolete-warning
                             cmd info "command"
                             (help--key-description-fontified
                              (where-is-internal (car info) nil t))))))))))))