all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Drew Adams <drew.adams@oracle.com>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Canonical way to add a pre-filter to completing-read
Date: Thu, 10 May 2018 17:36:44 +0000	[thread overview]
Message-ID: <CAFyQvY20eX8+cvPUC-wht6Lc0tuMfmcvP=b8cQtb_CtiMDzPmQ@mail.gmail.com> (raw)
In-Reply-To: <bc515c5a-7ffd-4f37-b163-b6afdc0cfa13@default>

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	other threads:[~2018-05-10 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10 13:09 Canonical way to add a pre-filter to completing-read Kaushal Modi
2018-05-10 14:10 ` Drew Adams
2018-05-10 17:36   ` Kaushal Modi [this message]
2018-05-10 15:21 ` Stefan Monnier
2018-05-10 17:19   ` Kaushal Modi
2018-05-10 22:05     ` Stefan Monnier

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFyQvY20eX8+cvPUC-wht6Lc0tuMfmcvP=b8cQtb_CtiMDzPmQ@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=drew.adams@oracle.com \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.