Next: Command Loop Info Prev: Defining Commands Up: Command Loop
After the command loop has translated a key sequence into a
definition, it invokes that definition using the function
`command-execute'. If the definition is a function that is a command,
`command-execute' calls `call-interactively', which reads the arguments
and calls the command. You can also call these functions yourself.
- Function: commandp OBJECT
Returns `t' if OBJECT is suitable for calling interactively; that
is, if OBJECT is a command. Otherwise, returns `nil'.
The interactively callable objects include strings and vectors
(treated as keyboard macros), lambda expressions that contain a
top-level call to `interactive', byte-code function objects,
autoload objects that are declared as interactive (non-`nil'
fourth argument to `autoload'), and some of the primitive
A symbol is `commandp' if its function definition is `commandp'.
Keys and keymaps are not commands. Rather, they are used to look
up commands (Note: Keymaps.).
See `documentation' in Note: Accessing Documentation, for a
realistic example of using `commandp'.
- Function: call-interactively COMMAND &optional RECORD-FLAG
This function calls the interactively callable function COMMAND,
reading arguments according to its interactive calling
specifications. An error is signaled if COMMAND cannot be called
interactively (i.e., it is not a command). Note that keyboard
macros (strings and vectors) are not accepted, even though they
are considered commands.
If RECORD-FLAG is the symbol `lambda', the interactive calling
arguments for `command' are read and returned as a list, but the
function is not called on them.
If RECORD-FLAG is `t', then this command and its arguments are
unconditionally added to the list `command-history'. Otherwise,
the command is added only if it uses the minibuffer to read an
argument. Note: Command History.
- Function: command-execute COMMAND &optional RECORD-FLAG
This function executes COMMAND as an editing command. The
argument COMMAND must satisfy the `commandp' predicate; i.e., it
must be an interactively callable function or a string.
A string or vector as COMMAND is executed with
`execute-kbd-macro'. A function is passed to
`call-interactively', along with the optional RECORD-FLAG.
A symbol is handled by using its function definition in its place.
A symbol with an `autoload' definition counts as a command if it
was declared to stand for an interactively callable function.
Such a definition is handled by loading the specified library and
then rechecking the definition of the symbol.
- Command: execute-extended-command PREFIX-ARGUMENT
This function reads a command name from the minibuffer using
`completing-read' (Note: Completion.). Then it uses
`command-execute' to call the specified command. Whatever that
command returns becomes the value of `execute-extended-command'.
If the command asks for a prefix argument, the value
PREFIX-ARGUMENT is supplied. If `execute-extended-command' is
called interactively, the current raw prefix argument is used for
PREFIX-ARGUMENT, and thus passed on to whatever command is run.
`execute-extended-command' is the normal definition of `M-x', so
it uses the string `M-x ' as a prompt. (It would be better to
take the prompt from the events used to invoke
`execute-extended-command', but that is painful to implement.) A
description of the value of the prefix argument, if any, also
becomes part of the prompt.
---------- Buffer: Minibuffer ----------
M-x forward-word RET
---------- Buffer: Minibuffer ----------
- Function: interactive-p
This function returns `t' if the containing function (the one that
called `interactive-p') was called interactively, with the function
`call-interactively'. (It makes no difference whether
`call-interactively' was called from Lisp or directly from the
editor command loop.) Note that if the containing function was
called by Lisp evaluation (or with `apply' or `funcall'), then it
was not called interactively.
The usual application of `interactive-p' is for deciding whether to
print an informative message. As a special exception,
`interactive-p' returns `nil' whenever a keyboard macro is being
run. This is to suppress the informative messages and speed
execution of the macro.
(defun foo ()
(defun bar ()
(setq foobar (list (foo) (interactive-p))))
;; Type `M-x foo'.
;; Type `M-x bar'.
;; This does not print anything.
=> (nil t)
automatically generated by info2www