From: Drew Adams <drew.adams@oracle.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>, help-gnu-emacs@gnu.org
Subject: RE: Rationale behind conversion of a nil prefix arg to numeric 1
Date: Mon, 5 Sep 2016 10:04:34 -0700 (PDT) [thread overview]
Message-ID: <56fae654-627a-41bd-8bdb-55418ed2e93f@default> (raw)
In-Reply-To: <e75cb01b-52f2-0aa5-5662-f30e8b6e73c0@easy-emacs.de>
> The ideosyncrasy: it yields the same value for arg = 1 as if no arg were
> given
Idiosyncrasy? That's one way to look at it, I suppose.
Similarly: `C-u' and `M-4' have numeric prefix-arg value 4;
and `M--' and `C-u - 1' have numeric value -1. But they have
different raw prefix-arg values. Idiosyncratic? If you like.
Bothersome? Bad? Ugly? Not at all.
There is simply a _mapping_ from raw prefix-arg values to
numeric prefix-arg values. That mapping is realized by
function `prefix-numeric-value'. There's really nothing
mysterious or idiosyncratic about the behavior. It's just
something to learn.
Raw prefix arg != numeric prefix arg. End of story. And
whether or not a user explicitly provides a prefix arg,
there is ALWAYS a numeric prefix-arg value (default = 1).
This is really one of the first things that someone writing
a command learns. It is NOT something that someone who uses
a command needs to learn.
But if a particular command has behavior that is different
for different kinds of prefix arg then of course the command
doc needs to describe the behavior.
> Regardless of its purpose - such coding style should not
> be encouraged.
What does that mean? What style should be discouraged, and why?
Just because a feature exists that allows code to distinguish
various user behaviors wrt using a prefix arg, that does not
mean that commands should NOT make use of that feature. And
it does not mean that they MUST make use of it.
Clearly, the _default_ behavior of a command, i.e., its behavior
with no prefix arg provided by the user, should be the typical
behavior. That does not mean that a command should not offer
alternative behaviors, which make use of a prefix argument,
provided those alternative behaviors are clearly documented.
> It would be easy and consistent to write (or arg (setq arg 1))
What would be the point of writing that?
That's essentially `(prefix-numeric-value arg)', except that
if ARG is non-nil then you won't necessarily get a number;
you'll get a number OR a cons OR the symbol `-'.
Perhaps you were proposing a redesign, where there would be
NO raw prefix arg, and the numeric value would try to do
double-duty, to both be numeric and provide a way to test
whether a prefix arg was actually provided by the user?
There are good reasons why Emacs has a raw prefix arg, if
that is your underlying question. For one thing, it lets
code know how many `C-u's a user used: 0, 1, 2, 3...
And that's handy because `C-u C-u' is quick to type. Just
distinguishing zero, one, and two `C-u's gives a command 3
possible behaviors - no need to compare numeric values etc.
It's really not a big deal. It's a flexible feature and is
easy to learn. Admittedly (like much in Emacs), if you have
not yet learned it, and you try to write a command that
takes advantage of a prefix arg, then you might be surprised
to learn it. Your surprise should be a welcome one, as you
now know what you can do with it.
next prev parent reply other threads:[~2016-09-05 17:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-04 12:23 Rationale behind conversion of a nil prefix arg to numeric 1 Florian v. Savigny
2016-09-04 14:23 ` Eli Zaretskii
2016-09-04 17:11 ` Andreas Röhler
2016-09-04 18:33 ` Eli Zaretskii
2016-09-05 7:16 ` Andreas Röhler
2016-09-05 14:56 ` Eli Zaretskii
2016-09-05 15:22 ` Kaushal Modi
2016-09-05 16:32 ` Drew Adams
2016-09-05 18:41 ` Andreas Röhler
2016-09-05 19:02 ` Eli Zaretskii
2016-09-06 7:10 ` tomas
2016-09-06 9:45 ` Florian v. Savigny
2016-09-06 10:27 ` tomas
2016-09-06 11:27 ` Andreas Röhler
2016-09-06 13:27 ` Florian v. Savigny
2016-09-06 15:22 ` Drew Adams
2016-09-06 14:20 ` Kaushal Modi
2016-09-06 16:44 ` Andreas Röhler
2016-09-06 16:41 ` Kaushal Modi
2016-09-07 23:11 ` Charles Millar
2016-09-08 13:10 ` Kaushal Modi
2016-09-08 14:42 ` Charles Millar
2016-09-08 15:40 ` Drew Adams
2016-09-06 7:22 ` Andreas Röhler
2016-09-05 17:04 ` Drew Adams [this message]
2016-09-05 21:39 ` Florian v. Savigny
[not found] ` <<877faqvxfp.fsf@bertrandrussell.Speedport_W_723V_1_40_000>
2016-09-05 23:32 ` Drew Adams
2016-09-06 3:45 ` B.V. Raghav
2016-09-04 22:53 ` Florian v. Savigny
[not found] ` <<87d1kjjmys.fsf@bertrandrussell.Speedport_W_723V_1_40_000>
2016-09-05 0:52 ` Drew Adams
2016-09-15 12:47 ` Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56fae654-627a-41bd-8bdb-55418ed2e93f@default \
--to=drew.adams@oracle.com \
--cc=andreas.roehler@easy-emacs.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).