[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Canonical way to add a pre-filter to completing-read
From: |
Kaushal Modi |
Subject: |
Canonical way to add a pre-filter to completing-read |
Date: |
Thu, 10 May 2018 13:09:14 +0000 |
Hello,
I want to use completing-read to provide a "pre-filter" to narrow down the
completion list.
My real use use is to take the symbol-at-point as the pre-filter to narrow
down in a list of all identifiers. For a real example, the symbol name is
"walkDirRec", but the completion list contains "os.walkDirRec".. so I am
trying to figure out how to use completing-read with that.
(I am aware that I can use the counsel library to make this easier, but was
looking for a way for completing-read to Just Work(TM).)
So here are some minimal examples to explain my conundrum..
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")
;INITIAL-INPUT deprecated, but works as I want
Above will show in the completion list with just the filtered items
matching "bc":
abc
bcd
So following the manual, I tried using the DEF (default) argument instead,
but that doesn't work as I want.. that just throws in that DEF value
verbatim to the completion list..
(completing-read "Entry: " '("abc" "bcd" "cde") nil :require-match nil nil
"bc") ;Using DEF does not work.. it just inserts that as one more element
in the completion list
Above will end up with this list:
bc
abc
bcd
cde
So the DEF approach is not useful unless the DEF value is matching exactly
with one of the items in COLLECTION.
So, what would be the right way, i.e. not using the deprecated
INITIAL-INPUT?
Thanks.
--
Kaushal Modi
- Canonical way to add a pre-filter to completing-read,
Kaushal Modi <=