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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<h3 class="section">Prefix Command Arguments</h3> <p>Most Emacs commands can use a <em>prefix argument</em>, a number specified before the command itself. (Don’t confuse prefix arguments with prefix keys.) The prefix argument is at all times represented by a value, which may be <code>nil</code>, meaning there is currently no prefix argument. Each command may use the prefix argument or ignore it. </p> <p>There are two representations of the prefix argument: <em>raw</em> and <em>numeric</em>. The editor command loop uses the raw representation internally, and so do the Lisp variables that store the information, but commands can request either representation. </p> <p>Here are the possible values of a raw prefix argument: </p> <ul> <li> <code>nil</code>, meaning there is no prefix argument. Its numeric value is 1, but numerous commands make a distinction between <code>nil</code> and the integer 1. </li>
<li> An integer, which stands for itself. </li>
<li> A list of one element, which is an integer. This form of prefix argument results from one or a succession of <kbd>C-u</kbd>s with no digits. The numeric value is the integer in the list, but some commands make a distinction between such a list and an integer alone. </li>
<li> The symbol <code>-</code>. This indicates that <kbd>M--</kbd> or <kbd>C-u -</kbd> was typed, without following digits. The equivalent numeric value is -1, but some commands make a distinction between the integer -1 and the symbol <code>-</code>. </li>
</ul> <p>We illustrate these possibilities by calling the following function with various prefixes: </p> <div class="example"> <pre class="example">(defun display-prefix (arg)
"Display the value of the raw prefix arg."
(interactive "P")
(message "%s" arg))
</pre>
</div> <p>Here are the results of calling <code>display-prefix</code> with various raw prefix arguments: </p> <div class="example"> <pre class="example"> M-x display-prefix -| nil
C-u M-x display-prefix -| (4)
C-u C-u M-x display-prefix -| (16)
C-u 3 M-x display-prefix -| 3
M-3 M-x display-prefix -| 3 ; <span class="roman">(Same as <code>C-u 3</code>.)</span>
C-u - M-x display-prefix -| -
M-- M-x display-prefix -| - ; <span class="roman">(Same as <code>C-u -</code>.)</span>
C-u - 7 M-x display-prefix -| -7
M-- 7 M-x display-prefix -| -7 ; <span class="roman">(Same as <code>C-u -7</code>.)</span>
</pre>
</div> <p>Emacs uses two variables to store the prefix argument: <code>prefix-arg</code> and <code>current-prefix-arg</code>. Commands such as <code>universal-argument</code> that set up prefix arguments for other commands store them in <code>prefix-arg</code>. In contrast, <code>current-prefix-arg</code> conveys the prefix argument to the current command, so setting it has no effect on the prefix arguments for future commands. </p> <p>Normally, commands specify which representation to use for the prefix argument, either numeric or raw, in the <code>interactive</code> specification. (See <a href="using-interactive">Using Interactive</a>.) Alternatively, functions may look at the value of the prefix argument directly in the variable <code>current-prefix-arg</code>, but this is less clean. </p> <dl> <dt id="prefix-numeric-value">Function: <strong>prefix-numeric-value</strong> <em>arg</em>
</dt> <dd><p>This function returns the numeric meaning of a valid raw prefix argument value, <var>arg</var>. The argument may be a symbol, a number, or a list. If it is <code>nil</code>, the value 1 is returned; if it is <code>-</code>, the value -1 is returned; if it is a number, that number is returned; if it is a list, the <small>CAR</small> of that list (which should be a number) is returned. </p></dd>
</dl> <dl> <dt id="current-prefix-arg">Variable: <strong>current-prefix-arg</strong>
</dt> <dd><p>This variable holds the raw prefix argument for the <em>current</em> command. Commands may examine it directly, but the usual method for accessing it is with <code>(interactive "P")</code>. </p></dd>
</dl> <dl> <dt id="prefix-arg">Variable: <strong>prefix-arg</strong>
</dt> <dd><p>The value of this variable is the raw prefix argument for the <em>next</em> editing command. Commands such as <code>universal-argument</code> that specify prefix arguments for the following command work by setting this variable. </p></dd>
</dl> <dl> <dt id="last-prefix-arg">Variable: <strong>last-prefix-arg</strong>
</dt> <dd><p>The raw prefix argument value used by the previous command. </p></dd>
</dl> <p>The following commands exist to set up prefix arguments for the following command. Do not call them for any other reason. </p> <dl> <dt id="universal-argument">Command: <strong>universal-argument</strong>
</dt> <dd><p>This command reads input and specifies a prefix argument for the following command. Don’t call this command yourself unless you know what you are doing. </p></dd>
</dl> <dl> <dt id="digit-argument">Command: <strong>digit-argument</strong> <em>arg</em>
</dt> <dd><p>This command adds to the prefix argument for the following command. The argument <var>arg</var> is the raw prefix argument as it was before this command; it is used to compute the updated prefix argument. Don’t call this command yourself unless you know what you are doing. </p></dd>
</dl> <dl> <dt id="negative-argument">Command: <strong>negative-argument</strong> <em>arg</em>
</dt> <dd><p>This command adds to the numeric argument for the next command. The argument <var>arg</var> is the raw prefix argument as it was before this command; its value is negated to form the new prefix argument. Don’t call this command yourself unless you know what you are doing. </p></dd>
</dl><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/Prefix-Command-Arguments.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Command-Arguments.html</a>
</p>
</div>
|