From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: RE: [External] : Use of an associated list with completing-read Date: Fri, 19 Apr 2024 02:59:24 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6054"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 19 05:00:21 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rxeU9-0001Oe-Jb for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 19 Apr 2024 05:00:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxeTP-0008TA-GM; Thu, 18 Apr 2024 22:59:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxeTN-0008Ss-HH for help-gnu-emacs@gnu.org; Thu, 18 Apr 2024 22:59:33 -0400 Original-Received: from mail-40138.protonmail.ch ([185.70.40.138]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxeTL-0004vc-HB for help-gnu-emacs@gnu.org; Thu, 18 Apr 2024 22:59:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1713495568; x=1713754768; bh=EheGhsZFTa3Nrd7f3ZIuBusvDJLFl5aSQQQJKAPNooY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=bIf04MYLxppJCzmJL/dkxJIhO/BMb9yIsWZoVfq2WqHsurpcNMt793EE0O39tkiq0 AwSwtZtspqSuW/R8CK5hsxQdSqaF4D0N+yv4w71yCBr8QGL8Z9zFcv9h7w/6eV3V04 a+1FRATYyKyQ7EJL8/M7IHXvSOqpeuWFScYpdpnytN5HO5NGodGszS1orjN3MXS/FG ovDhxu042u9+fSFCyYlEi6CzUob9KjCro60MbuOBgDD9Z7/3Pbp339uaGsLWyCAjTa GwThOkixo/GabnXZ7ozoqsed50l9EYKeTwz8Is8T3nSD3kVvBZj7qbhfoR9pRpO9RA u0jfZgFIzuv/A== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 83a7aba66249051768f982adab66c25a5908b71e Received-SPF: pass client-ip=185.70.40.138; envelope-from=heimeborgia@protonmail.com; helo=mail-40138.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146366 Archived-At: On Friday, April 19th, 2024 at 2:14 PM, Drew Adams = wrote: > > Haw can I have an interactive function that > > displays a list of elements from an associated > > list using completing-read ? >=20 >=20 > 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: >=20 > (completing-read > "Choose an alist element: " > (mapcar #'prin1-to-string my-alist) > nil > t) >=20 > That "displays" elements that match your > input. Is that what you meant by "displays > a list of elements"? >=20 > 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. ___=20 > But if you don't really want to see the elements of the alist as completi= ons,=20 > but instead you want to see their keys, then just do this:=20 > (completing-read "Choose an alist key: " my-alist nil t)=20 Yes, I wanted to see the keys as completing entries. Right, looking=20 at the documentation COLLECTION can be an alist and will print the keys. I had the cons cells the other way round, with the actual key as the cdr, making completing-read display the wrong entry. > If the alist keys are symbols then apply` intern' to the chosen string, t= o get > the symbol key. Then use this to get the element with that key (the exact > same cons, i.e., `eq', not just` equal): >=20 > (car (assq THE-SYMBOL my-alist) >=20 > 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.