all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Canonical way to add a pre-filter to completing-read
Date: Thu, 10 May 2018 18:05:17 -0400	[thread overview]
Message-ID: <jwv8t8rch86.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAFyQvY3B0xjobM+S53QXUruvhG8EkQOayqdo1yOBGbm=bNvQng@mail.gmail.com> (Kaushal Modi's message of "Thu, 10 May 2018 17:19:52 +0000")

>>     M-: (km-completion "Entry: " '("abc" "bcd" "cde") "bc") RET
>> and then types `a` (and then hits `?` to see the list of remaining
>> completions, or maybe he uses icomplete-mode to always see the list of
>> remaining candidates).  What do you want the list of completions to be
>> at that point?
> If I type `a` there, the entry would become "bca",

Is "bca" really what you think would be ideal here (where the user
never typed "bc")?

That seems to imply the user would have to use something like C-a C-k in
order to type something completely different from "bc".  Most UIs seem
to find such behavior undesirable, AFAIK (in the default Emacs UI we
shun initial inputs altogether, requiring the user to hit M-n if he
wants to edit the default; and in more "mainstream" UIs I know, the
initial input is highlighted/selected at first, and hitting "a" would
first delete it (you'd need to use a cursor key first in order to
de-select the text before hitting "a" in order to keep the "bc")).

>> Some things you can do with the standard completion-UI:
>> - setup your completion table such that it uses `substring` completion
>>   by default.
> That sounds like that would work.. can you please point to an example?

You want to setup your completion table so it returns a `metadata` which
includes a `category` of your choice, and then you want to add an entry
for that category to completion-category-defaults.

This is done for example for read-char-by-name.

>> - use `completion-table-in-turn` with the first table being a sub-table
>>   which only includes the entries that match "bc".
> I did not understand this suggestion.

You could setup your completion table such that the UI would behave as
follows:

- Imagine your list of completion candidates is abc, bcd, acd, cde.
- And you want to start by filtering for "bc".
- At first the minibuffer says "Entry: "
- At this point the available completions would be "abc" and "bcd".
- Then the user hits "a".
- The minibuffer becomes "Entry: a"
- The available completions become just "abc" and nothing else.
- Then the user hits "ac".
- The minibuffer becomes "Entry: ac"
- The available completions become just "acd" and nothing else.

You'd do this by combining (with the mentioned function) two completion
tables: one containing only the entries that match "bc" and the other
containing all the entries, so when the input matches in the first
table, we stay in the first stable, but if it doesn't, then we search in
the second table.


        Stefan



      reply	other threads:[~2018-05-10 22:05 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
2018-05-10 15:21 ` Stefan Monnier
2018-05-10 17:19   ` Kaushal Modi
2018-05-10 22:05     ` Stefan Monnier [this message]

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=jwv8t8rch86.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=kaushal.modi@gmail.com \
    /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.