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

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

Re: Canonical way to add a pre-filter to completing-read


From: Kaushal Modi
Subject: Re: Canonical way to add a pre-filter to completing-read
Date: Thu, 10 May 2018 17:36:44 +0000

Hi Drew,

On Thu, May 10, 2018 at 10:10 AM Drew Adams <drew.adams@oracle.com> wrote:

> Possibilities:
>
> 1. Filter the list of completions before passing it.
>    IOW, pass '("abc" "bcd"), not '("abc" "bcd" "cde").
>    (Or if COMPLETIONS is a function, have it also filter,
>    as and when needed.)
>

Pre-filtering would not work in my case, as I might even need to change the
filter on the fly *after it got initially set using INITIAL-INPUT*. See how
I use it in this GIF (the same that I linked in my earlier reply to
Stefan): https://imgur.com/1Ki7uFX.

2. Provide a PREDICATE arg that filters as needed.  E.g.,
>    (lambda (xx) (string-match-p "bc" xx)).
>

That might.. work. I will have to try.

With vanilla Emacs:
>
> If you use a non-function COMPLETIONS arg then you need
> to establish that list of candidates before completing.
> You have only PREDICATE to play with.  The candidates
> are determined independently of whatever input might be
> in the minibuffer
>
> If you use a function COMPLETIONS arg then the function
> can take into account the current minibuffer input.
> The function can do anything you want, to come up with
>
> the (current, dynamically computed) set of candidates.


Let me play with PREDICATE. At the moment, the COMPLETIONS is just a list.
I will look into that if setting PREDICATE does not work.


> > Below works exactly as I want.. but the docs and manual
> > say that INITIAL-INPUT is deprecated.
> >
> > (completing-read "Entry: " '("abc" "bcd" "cde") nil
> >                  :require-match "bc")
> >
> > So, what would be the right way, i.e. not using the
> > deprecated INITIAL-INPUT?
>
> Ignore the docs.  Emacs was wrong to proclaim INITIAL-INPUT
> deprecated.  It can be useful.  It never hurt anyone for
> Emacs to make it available.  It is enough to suggest to
> users that it is more conventional, and typically more
> user-friendly, to use only DEF.
>
> With luck, this silly uber-control will be removed from
> the docs someday.  Don't be scared away from using it
> when it suits your purpose.
>

For now, I am using the INITIAL-INPUT as that solves the purpose. But I
will later try out the PREDICATE.


> (Just one opinion.)
>

Thanks for that :)
-- 

Kaushal Modi


reply via email to

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