1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<h3 class="section">Defining Commands</h3> <p>The special form <code>interactive</code> turns a Lisp function into a command. The <code>interactive</code> form must be located at top-level in the function body, usually as the first form in the body; this applies to both lambda expressions (see <a href="lambda-expressions">Lambda Expressions</a>) and <code>defun</code> forms (see <a href="defining-functions">Defining Functions</a>). This form does nothing during the actual execution of the function; its presence serves as a flag, telling the Emacs command loop that the function can be called interactively. The argument of the <code>interactive</code> form specifies how the arguments for an interactive call should be read. </p> <p>Alternatively, an <code>interactive</code> form may be specified in a function symbol’s <code>interactive-form</code> property. A non-<code>nil</code> value for this property takes precedence over any <code>interactive</code> form in the function body itself. This feature is seldom used. </p> <p>Sometimes, a function is only intended to be called interactively, never directly from Lisp. In that case, give the function a non-<code>nil</code> <code>interactive-only</code> property, either directly or via <code>declare</code> (see <a href="declare-form">Declare Form</a>). This causes the byte compiler to warn if the command is called from Lisp. The output of <code>describe-function</code> will include similar information. The value of the property can be: a string, which the byte-compiler will use directly in its warning (it should end with a period, and not start with a capital, e.g., <code>"use (system-name) instead."</code>); <code>t</code>; any other symbol, which should be an alternative function to use in Lisp code. </p> <p>Generic functions (see <a href="generic-functions">Generic Functions</a>) cannot be turned into commands by adding the <code>interactive</code> form to them. </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="using-interactive" accesskey="1">Using Interactive</a>
</td>
<td> </td>
<td align="left" valign="top">General rules for <code>interactive</code>. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="interactive-codes" accesskey="2">Interactive Codes</a>
</td>
<td> </td>
<td align="left" valign="top">The standard letter-codes for reading arguments in various ways. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="interactive-examples" accesskey="3">Interactive Examples</a>
</td>
<td> </td>
<td align="left" valign="top">Examples of how to read interactive arguments. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="command-modes" accesskey="4">Command Modes</a>
</td>
<td> </td>
<td align="left" valign="top">Specifying that commands are for a specific mode. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="generic-commands" accesskey="5">Generic Commands</a>
</td>
<td> </td>
<td align="left" valign="top">Select among command alternatives. </td>
</tr> </table><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Commands.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Commands.html</a>
</p>
</div>
|