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: Stefan Monnier
Subject: Re: Canonical way to add a pre-filter to completing-read
Date: Thu, 10 May 2018 18:05:17 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>     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 via email to

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