bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12331: 24.1; completing-read when COLLECTION has exactly one element


From: Drew Adams
Subject: bug#12331: 24.1; completing-read when COLLECTION has exactly one element
Date: Sat, 1 Sep 2012 19:49:58 -0700

> If the arg COLLECTION of completing-read is a list with exactly one
> element and REQUIRE-MATCH is t, it can be quite redundant to go via
> the minibuffer. Would it make sense if in such a case
> completing-read could skip the minibuffer completely and simply
> return the car of COLLECTION?

Hi Roland.

`completing-read' offers possible candidates, but for lax completion it does not
require you to choose any of them - you can enter anything you like.  So this
would make sense only for strict completion.

Depending on the context, even for strict completion it might sometimes be
surprising for a user not to see any prompt for completion.  That is, if a user
expects to choose and is not offered a choice, that can be surprising/confusing.

Of course if for some given occurrence of `completing-read' in the code
COLLECTION is *always* a singleton, then there will be no surprise.  But in that
case there is also presumably no reason to call `completing-read'. ;-)

As you say, "the surrounding code could also shortcut the call of
completing-read in such a case."  That makes the most sense to me.  It is, after
all, the surrounding code that reflects the design intention and can tell what
it might really mean in the current context to have only a singleton COLLECTION.

"But completing-read is possibly the better place to
implement such a behavior"

I don't think so, for the above reasons.  Why do you think so?

"say via a particular value of REQUIRE-MATCH."

In that case it is the surrounding code that is making the decision, as it
should.  That is better at least than systematically having *any* non-nil
REQUIRE-MATCH mean that a singleton COLLECTION returns the sole candidate.

What you suggest is then equivalent to this:

(if (and COLLECTION (not (cdr COLLECTION)))
    (first-candidate COLLECTION)
  (completing-read ...))

where `first-candidate' returns the candidate corresponding to (car COLLECTION),
doing the right thing for a list or string.

Is it worth moving such logic into `completing-read', adding a particular
non-nil value of REQUIRE-MATCH to implement it?  I don't think so.  FWIW, I use
`completing-read' a lot, and I have never had a use for such treatment.

Others might disagree...

Why don't you try it for a while, and see if you really find it useful?


[FWIW, in Icicles users can choose whether completion happens automatically
whenever there is a sole matching candidate (which is more general than the
cases where COLLECTION is a singleton).  In that case, they need only hit RET,
not TAB RET.  (And they can configure a delay for the automatic completion, to
give them time to change erroneous input, since this is about a sole match
against their input.) But being prompted and hitting RET is still more
interaction than what you are suggesting.]






reply via email to

[Prev in Thread] Current Thread [Next in Thread]