unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Heime <heimeborgia@protonmail.com>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: RE: [External] : Use of an associated list with completing-read
Date: Fri, 19 Apr 2024 02:14:31 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488A1858D0EA3912E7C201CF30D2@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <H04SU_eQ3u5Jk9logV5CAmile8akItu13TfFFrB5R5F9t2YXjRt0W6T_skEoFllHvvYcGwKOJBhKmPhOdOsSwDbeUEzjuKkl84bqzfikppI=@protonmail.com>

> Haw can I have an interactive function that
> displays a list of elements from an associated
> list using completing-read ?

The elements of an alist are conses.  Assuming
that you really meant that you want to see and
choose among the elements, then use this:

(completing-read
  "Choose an alist element: "
  (mapcar #'prin1-to-string my-alist)
  nil
  t)

That "displays" elements that match your
input.  Is that what you meant by "displays
a list of elements"?

It returns a string such as "(a . 42)" for
the alist element (a . 42).  Then you can
use (read "(a . 42)") to get a new cons
that's `equal' to the cons in your alist.
___

But if you don't really want to see the
elements of the alist as completions, but
instead you want to see their keys, then
just do this:

(completing-read
  "Choose an alist key: "
  my-alist
  nil
  t)

If the alist keys are symbols then apply
`intern' to the chosen string, to get
the symbol key.  Then use this to get
the element with that key (the exact
same cons, i.e., `eq', not just `equal):

(car (assq THE-SYMBOL my-alist)

I had to do a lot of guessing as to what
you're really requesting.  As usual, you
don't make clear what you're after.  And
you don't show any code that you've tried
so far.

  reply	other threads:[~2024-04-19  2:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 23:48 Use of an associated list with completing-read Heime
2024-04-19  2:14 ` Drew Adams [this message]
2024-04-19  2:59   ` [External] : " Heime
2024-04-19  3:10     ` Heime
2024-04-19 15:10       ` Drew Adams
2024-04-19 19:09         ` Heime
2024-04-19 23:32           ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20  1:13             ` Drew Adams
2024-04-20  1:52               ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20  1:59                 ` Emanuel Berg
2024-04-20  6:14                 ` Heime
2024-04-20  6:37                   ` Heime
2024-04-23  4:44 ` Jean Louis

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=SJ0PR10MB5488A1858D0EA3912E7C201CF30D2@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=heimeborgia@protonmail.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).