@gilles and @npostavs have given use cases. To summarize what they said:
When you're already using
M- for part of a key sequence, it can be easier to specify a zero prefix arg using
M-0 than using, say,
A zero numeric prefix arg can have a specific (not necessarily numeric) meaning for a given command. @Gilles mentioned
save-buffer, and @npostavs mentioned
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
Nth thing in one direction (e.g. forward), and negative
N could act on the
Nth 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
C-u -. Results in the symbol
C-u, followed by digit keys. Results in the non-negative integer with those digits.
C-u -, followed by digit keys. Results in the non-positive integer with those digits. (But
-0 are the same number, for Emacs.)
C-u, possibly used multiple times:
C-u C-u C-u,... Results in value that is a list of an integer that is a power of 4:
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.
- 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 4 (producing
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.