diff options
| author | Chong Yidong | 2009-03-24 17:08:49 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-03-24 17:08:49 +0000 |
| commit | 8421dd353c3df878e25efc4159d12b2f83be1933 (patch) | |
| tree | aa43965de304a5c100bf50e325568630a7d6283b | |
| parent | 6e4ff1b6e0f43228650c667e649b05ecfe1fafd7 (diff) | |
| download | emacs-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.texi | 73 |
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 |
| 106 | level, a form that calls the special form @code{interactive}, or if | 106 | command. The @code{interactive} form must be located at top-level in |
| 107 | the function's symbol has an @code{interactive-form} property. This | 107 | the function body (usually as the first form in the body), or in the |
| 108 | form does nothing when actually executed, but its presence serves as a | 108 | @code{interactive-form} property of the function symbol. When the |
| 109 | flag to indicate that interactive calling is permitted. Its argument | 109 | @code{interactive} form is located in the function body, it does |
| 110 | controls the reading of arguments for an interactive call. | 110 | nothing when actually executed. Its presence serves as a flag, which |
| 111 | tells the Emacs command loop that the function can be called | ||
| 112 | interactively. The argument of the @code{interactive} form controls | ||
| 113 | the 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 | |||
| 125 | examine a command's @code{interactive} form. | 128 | examine a command's @code{interactive} form. |
| 126 | 129 | ||
| 127 | @defspec interactive arg-descriptor | 130 | @defspec interactive arg-descriptor |
| 128 | This special form declares that the function in which it appears is a | 131 | This special form declares that a function is a command, and that it |
| 129 | command, and that it may therefore be called interactively (via | 132 | may 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 | 133 | key sequence bound to it). The argument @var{arg-descriptor} declares |
| 131 | @var{arg-descriptor} declares how to compute the arguments to the | 134 | how to compute the arguments to the command when the command is called |
| 132 | command when the command is called interactively. | 135 | interactively. |
| 133 | 136 | ||
| 134 | A command may be called from Lisp programs like any other function, but | 137 | A command may be called from Lisp programs like any other function, but |
| 135 | then the caller supplies the arguments and @var{arg-descriptor} has no | 138 | then the caller supplies the arguments and @var{arg-descriptor} has no |
| 136 | effect. | 139 | effect. |
| 137 | 140 | ||
| 138 | The @code{interactive} form has its effect because the command loop | ||
| 139 | (actually, its subroutine @code{call-interactively}) scans through the | ||
| 140 | function definition looking for it, before calling the function. Once | ||
| 141 | the 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 | ||
| 144 | argument. | ||
| 145 | |||
| 146 | @cindex @code{interactive-form}, function property | 141 | @cindex @code{interactive-form}, function property |
| 147 | An interactive form can be added to a function post-facto via the | 142 | The @code{interactive} form must be located at top-level in the |
| 148 | @code{interactive-form} property of the function's symbol. | 143 | function body, or in the function symbol's @code{interactive-form} |
| 149 | @xref{Symbol Plists}. | 144 | property (@pxref{Symbol Plists}). It has its effect because the |
| 145 | command loop looks for it before calling the function | ||
| 146 | (@pxref{Interactive Call}). Once the function is called, all its body | ||
| 147 | forms are executed; at this time, if the @code{interactive} form | ||
| 148 | occurs within the body, the form simply returns @code{nil} without | ||
| 149 | even evaluating its argument. | ||
| 150 | |||
| 151 | By convention, you should put the @code{interactive} form in the | ||
| 152 | function body, as the first top-level form. If there is an | ||
| 153 | @code{interactive} form in both the @code{interactive-form} symbol | ||
| 154 | property and the function body, the former takes precedence. The | ||
| 155 | @code{interactive-form} symbol property can be used to add an | ||
| 156 | interactive form to an existing function, or change how its arguments | ||
| 157 | are processed interactively, without redefining the function. | ||
| 150 | @end defspec | 158 | @end defspec |
| 151 | 159 | ||
| 152 | There are three possibilities for the argument @var{arg-descriptor}: | 160 | There 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, |
| 557 | invokes that command using the function @code{command-execute}. If the | 565 | it invokes that command using the function @code{command-execute}. If |
| 558 | command is a function, @code{command-execute} calls | 566 | the 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 |
| 560 | command. You can also call these functions yourself. | 568 | command. You can also call these functions yourself. |
| 561 | 569 | ||
| @@ -563,14 +571,15 @@ command. You can also call these functions yourself. | |||
| 563 | Returns @code{t} if @var{object} is suitable for calling interactively; | 571 | Returns @code{t} if @var{object} is suitable for calling interactively; |
| 564 | that is, if @var{object} is a command. Otherwise, returns @code{nil}. | 572 | that is, if @var{object} is a command. Otherwise, returns @code{nil}. |
| 565 | 573 | ||
| 566 | The interactively callable objects include strings and vectors (treated | 574 | Interactively-callable objects include strings and vectors (which are |
| 567 | as keyboard macros), lambda expressions that contain a top-level call to | 575 | treated as keyboard macros), lambda expressions that contain a |
| 568 | @code{interactive}, byte-code function objects made from such lambda | 576 | top-level @code{interactive} form (@pxref{Using Interactive}), |
| 569 | expressions, autoload objects that are declared as interactive | 577 | byte-code function objects made from such lambda expressions, autoload |
| 570 | (non-@code{nil} fourth argument to @code{autoload}), and some of the | 578 | objects that are declared as interactive (non-@code{nil} fourth |
| 571 | primitive functions. | 579 | argument to @code{autoload}), and some primitive functions. |
| 572 | 580 | ||
| 573 | A symbol satisfies @code{commandp} if its function definition | 581 | A symbol satisfies @code{commandp} if it has a non-@code{nil} |
| 582 | @code{interactive-form} property, or if its function definition | ||
| 574 | satisfies @code{commandp}. Keys and keymaps are not commands. | 583 | satisfies @code{commandp}. Keys and keymaps are not commands. |
| 575 | Rather, they are used to look up commands (@pxref{Keymaps}). | 584 | Rather, they are used to look up commands (@pxref{Keymaps}). |
| 576 | 585 | ||