Subject: Re: bug#65459: completing-read INITIAL-VALUE unaware of COLLECTION and REQUIRE-MATCH

From: Heime <[email-masked]>
Date: Wed, 23 Aug 2023 16:39:52 +0000

------- Original Message -------
On Thursday, August 24th, 2023 at 4:05 AM, Stefan Monnier <[email-masked]> wrote:

> > Then, repeatedly hit <down>. You get
> > 
> > alpha alpha beta gamma delta epsilon zeta eta alpha beta gamma and-so-on
> 
> Ah, OK, yes, that sounds like a problem (one I've heard before).
> I think it's a problem in the cycling code rather than in INITIAL-VALUE
> or COLLECTION. E.g. the same problem occurs if the initial input is
> empty and the user types `alpha C-n`.

That has been my assessment as well.  It is not a problem of INITIAL-VALUE,
but a problem in the cycling mechanism.
 
> > You do actually get that the consecutive entries appearing in the
> > minibuffer have direct correspondence to the order found in COLLECTION.
> 
> For that form of cycling, apparently so, yes. I don't categorize it as
> "completion" so I haven't looked very closely at that code :-)
> There are other ways to do cycling which use a different ordering.

Correct, it is not categorised as completion.
 
> The cycling through completions via `next-line-or-history-element` is
> not very configurable, AFAICT.
> 
> > Once INITIAL is inserted, I cannot instruct completing-read to continue
> > sequentially starting from a particular element.
> 
> Indeed.
> 
> > For instance, I cannot get the following result when using simple cycling
> > through collection options when repeatedly hitting the <down> key.
> > 
> > To achieve
> > 
> > alpha epsilon zeta eta alpha beta gamma delta epsilon and-so-on
> 
> Could you give a bit more context about why/where you'd want to do that
> so I can better imagine how to attack the problem?
> 
> Hopefully it would explain why you want "alpha epsilon ..." first but
> "alpha beta .." later. 

In such instance one considers collection as a cyclic list for the case of 
simple cycling.  But with possibility of starting from a particular index.

> Also for such uses of `completing-read` we usually recommend against a 
> non-nil value for INITIAL-INPUT, so that context should try to explain 
> why you use "alpha" as INITIAL-INPUT. - Stefan

Because using INITIAL is the only way available to pre-insert a value in 
the minibuffer.

Hence, if I want a pre-insertion candidate for the first element in collection
I get 'alpha' repeated twice.  First from the insertion via INITIAL, and then 
again through the simple cycling of collection (that starts from 'alpha').  

If one can instruct the starting position in collection and subsequently consider
collection as a cyclic list, the problem of ending with the following is solved.

alpha alpha beta gamma delta epsilon zeta eta alpha and-so-on

which means

INITIAL COLLECTION(0) COLLECTION(1) and-so-on.

--------

Starting from entry 1 of collection, you would get

alpha beta gamma delta epsilon zeta eta alpha and-so-on

which means

INITIAL COLLECTION(1) COLLECTION(2) and-so-on

--------

And in general

INITIAL COLLECTION(i) COLLECTION(i+1) ... COLLECTION(0) COLLECTION(1) and-so-on