aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-03-24 17:08:49 +0000
committerChong Yidong2009-03-24 17:08:49 +0000
commit8421dd353c3df878e25efc4159d12b2f83be1933 (patch)
treeaa43965de304a5c100bf50e325568630a7d6283b
parent6e4ff1b6e0f43228650c667e649b05ecfe1fafd7 (diff)
downloademacs-8421dd353c3df878e25efc4159d12b2f83be1933.tar.gz
emacs-8421dd353c3df878e25efc4159d12b2f83be1933.zip
(Defining Commands): Clarify introduction.
(Using Interactive): Not that interactive can be put in a symbol property. (Interactive Call): Note that a symbol with a non-nil interactive-form property satisfies commandp.
-rw-r--r--doc/lispref/commands.texi73
1 files changed, 41 insertions, 32 deletions
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index 270f3924298..e767574cecf 100644
--- a/doc/lispref/commands.texi
+++ b/doc/lispref/commands.texi
@@ -102,12 +102,15 @@ command does.
102@cindex functions, making them interactive 102@cindex functions, making them interactive
103@cindex interactive function 103@cindex interactive function
104 104
105 A Lisp function becomes a command when its body contains, at top 105 The special form @code{interactive} turns a Lisp function into a
106level, a form that calls the special form @code{interactive}, or if 106command. The @code{interactive} form must be located at top-level in
107the function's symbol has an @code{interactive-form} property. This 107the function body (usually as the first form in the body), or in the
108form does nothing when actually executed, but its presence serves as a 108@code{interactive-form} property of the function symbol. When the
109flag to indicate that interactive calling is permitted. Its argument 109@code{interactive} form is located in the function body, it does
110controls the reading of arguments for an interactive call. 110nothing when actually executed. Its presence serves as a flag, which
111tells the Emacs command loop that the function can be called
112interactively. The argument of the @code{interactive} form controls
113the reading of arguments for an interactive call.
111 114
112@menu 115@menu
113* Using Interactive:: General rules for @code{interactive}. 116* Using Interactive:: General rules for @code{interactive}.
@@ -125,28 +128,33 @@ makes a Lisp function an interactively-callable command, and how to
125examine a command's @code{interactive} form. 128examine a command's @code{interactive} form.
126 129
127@defspec interactive arg-descriptor 130@defspec interactive arg-descriptor
128This special form declares that the function in which it appears is a 131This special form declares that a function is a command, and that it
129command, and that it may therefore be called interactively (via 132may therefore be called interactively (via @kbd{M-x} or by entering a
130@kbd{M-x} or by entering a key sequence bound to it). The argument 133key sequence bound to it). The argument @var{arg-descriptor} declares
131@var{arg-descriptor} declares how to compute the arguments to the 134how to compute the arguments to the command when the command is called
132command when the command is called interactively. 135interactively.
133 136
134A command may be called from Lisp programs like any other function, but 137A command may be called from Lisp programs like any other function, but
135then the caller supplies the arguments and @var{arg-descriptor} has no 138then the caller supplies the arguments and @var{arg-descriptor} has no
136effect. 139effect.
137 140
138The @code{interactive} form has its effect because the command loop
139(actually, its subroutine @code{call-interactively}) scans through the
140function definition looking for it, before calling the function. Once
141the function is called, all its body forms including the
142@code{interactive} form are executed, but at this time
143@code{interactive} simply returns @code{nil} without even evaluating its
144argument.
145
146@cindex @code{interactive-form}, function property 141@cindex @code{interactive-form}, function property
147An interactive form can be added to a function post-facto via the 142The @code{interactive} form must be located at top-level in the
148@code{interactive-form} property of the function's symbol. 143function body, or in the function symbol's @code{interactive-form}
149@xref{Symbol Plists}. 144property (@pxref{Symbol Plists}). It has its effect because the
145command loop looks for it before calling the function
146(@pxref{Interactive Call}). Once the function is called, all its body
147forms are executed; at this time, if the @code{interactive} form
148occurs within the body, the form simply returns @code{nil} without
149even evaluating its argument.
150
151By convention, you should put the @code{interactive} form in the
152function body, as the first top-level form. If there is an
153@code{interactive} form in both the @code{interactive-form} symbol
154property and the function body, the former takes precedence. The
155@code{interactive-form} symbol property can be used to add an
156interactive form to an existing function, or change how its arguments
157are processed interactively, without redefining the function.
150@end defspec 158@end defspec
151 159
152There are three possibilities for the argument @var{arg-descriptor}: 160There are three possibilities for the argument @var{arg-descriptor}:
@@ -553,9 +561,9 @@ Put them into three windows, selecting the last one."
553@section Interactive Call 561@section Interactive Call
554@cindex interactive call 562@cindex interactive call
555 563
556 After the command loop has translated a key sequence into a command it 564 After the command loop has translated a key sequence into a command,
557invokes that command using the function @code{command-execute}. If the 565it invokes that command using the function @code{command-execute}. If
558command is a function, @code{command-execute} calls 566the command is a function, @code{command-execute} calls
559@code{call-interactively}, which reads the arguments and calls the 567@code{call-interactively}, which reads the arguments and calls the
560command. You can also call these functions yourself. 568command. You can also call these functions yourself.
561 569
@@ -563,14 +571,15 @@ command. You can also call these functions yourself.
563Returns @code{t} if @var{object} is suitable for calling interactively; 571Returns @code{t} if @var{object} is suitable for calling interactively;
564that is, if @var{object} is a command. Otherwise, returns @code{nil}. 572that is, if @var{object} is a command. Otherwise, returns @code{nil}.
565 573
566The interactively callable objects include strings and vectors (treated 574Interactively-callable objects include strings and vectors (which are
567as keyboard macros), lambda expressions that contain a top-level call to 575treated as keyboard macros), lambda expressions that contain a
568@code{interactive}, byte-code function objects made from such lambda 576top-level @code{interactive} form (@pxref{Using Interactive}),
569expressions, autoload objects that are declared as interactive 577byte-code function objects made from such lambda expressions, autoload
570(non-@code{nil} fourth argument to @code{autoload}), and some of the 578objects that are declared as interactive (non-@code{nil} fourth
571primitive functions. 579argument to @code{autoload}), and some primitive functions.
572 580
573A symbol satisfies @code{commandp} if its function definition 581A symbol satisfies @code{commandp} if it has a non-@code{nil}
582@code{interactive-form} property, or if its function definition
574satisfies @code{commandp}. Keys and keymaps are not commands. 583satisfies @code{commandp}. Keys and keymaps are not commands.
575Rather, they are used to look up commands (@pxref{Keymaps}). 584Rather, they are used to look up commands (@pxref{Keymaps}).
576 585