all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Canonical way to add a pre-filter to completing-read
Date: Thu, 10 May 2018 13:09:14 +0000	[thread overview]
Message-ID: <CAFyQvY3gomT-G=oGhYsReZ4O1vdJ09a9OpYYtvyoTsaaSmG0Qw@mail.gmail.com> (raw)

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


             reply	other threads:[~2018-05-10 13:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10 13:09 Kaushal Modi [this message]
2018-05-10 14:10 ` Canonical way to add a pre-filter to completing-read 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

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='CAFyQvY3gomT-G=oGhYsReZ4O1vdJ09a9OpYYtvyoTsaaSmG0Qw@mail.gmail.com' \
    --to=kaushal.modi@gmail.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.