@gilles and @npostavs have given use cases. To summarize what they said:
When you're already using C-
or M-
for part of a key sequence, it can be easier to specify a zero prefix arg using C-0
or M-0
than using, say, C-u 0
.
A zero numeric prefix arg can have a specific (not necessarily numeric) meaning for a given command. @Gilles mentioned save-buffer
, and @npostavs mentioned kill-line
.
It's also the case that a command could have a zero-arg behavior, a positive-arg behavior, and a negative-arg behavior. E.g., zero could act on the current thing (line, word, sexp, whatever), positive N
could act on the N
th thing in one direction (e.g. forward), and negative N
could act on the N
th thing in the opposite direction (e.g. backward).
Wrt the second point noted by @Gilles and @npovstas: I disagree with @Gilles that specifying particular behavior for a given prefix arg for a given command in any way flouts Emacs convention. It might not correspond to what most Emacs commands do, but it doesn't violate any convention, as far as I know.
It's true that for most Emacs commands:
- A zero prefix arg has no special behavior - it has no effect.
- If a prefix arg has an effect then (as @Gilles points out) it is usually one of these:
- Its numeric value,
N
, is used by the command (often to perform an action N times or to move forward or backward (abs N)
things (chars, words, sexps, lines, etc.).
- Using a prefix arg has one effect; not using a prefix arg has a different effect.
But a prefix arg can, by design, take several forms, and a command can distinguish them and act differently depending on the form used. Differences include:
- No prefix arg. Results in the value
nil
.
C--
, M--
, or C-u -
. Results in the symbol -
.
C-
, M-
, or C-u
, followed by digit keys. Results in the non-negative integer with those digits.
C--
, M--
, or C-u -
, followed by digit keys. Results in the non-positive integer with those digits. (But 0
and -0
are the same number, for Emacs.)
- Plain
C-u
, possibly used multiple times: C-u C-u
, C-u C-u C-u
,... Results in value that is a list of an integer that is a power of 4: (4)
, (16)
, (256)
,...
Those are the possible raw prefix arg values. A command can choose to act specially for any of them.
Each of those inputs can also, or alternatively, be interpreted by the command numerically:
nil
is interpreted as 1.
- Symbol
-
is interpreted as -1.
- An integer is interpreted as that integer.
- A list of a power of 4 is interpreted as that power of 4.
Those are the possible numeric prefix arg values. A command can choose to act specially for any of them.
There are multiple ways to input the same raw or numeric prefix arg - those results are not distinguishable by the command. But there are also ways to input different raw or numeric args, and those can be distinguished.
A command is free to do whatever its designer likes with a given prefix arg. It could choose, for example, to act one way for even numeric input and another for odd numeric input, taking into account the particular number. Likewise, zero, positive, and negative numbers. Similarly, it can do different things, depending on whether you use C-u
(producing (4)
) or C-u 4
(producing 4
).
There are lots of possibilities. What's important is that the command behavior is clearly documented in its doc string.
See (elisp) Prefix Command Arguments.
C-0
andM-0
allow you to specify a numeric prefix argument and you've remappedM-0
, you can still useC-0
.C-0
toswitch-to-previous-buffer
, because I NEVER useM-0
neitherC-0
, so that is the reason I am asking the Emacs community, what are they using those for...