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 03:10:26 +0000 Message-ID: <1ZznhcKDmGMQcjaA3pyQaBOnYG81YwX4pE1YSoGxi_Vj_UFqz_DzTcdhZ50XnL3lEDivoq5THtGr-ShAq1PMbkmNHxajYrXWeRmti6_BSD4=@protonmail.com> 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="19631"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Drew Adams , Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 19 05:11:04 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 1rxeeW-0004sK-0V for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 19 Apr 2024 05:11:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxee7-0001QC-Ja; Thu, 18 Apr 2024 23:10:40 -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 1rxee4-0001Pm-Dk for help-gnu-emacs@gnu.org; Thu, 18 Apr 2024 23:10:36 -0400 Original-Received: from mail-40141.protonmail.ch ([185.70.40.141]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxee2-00071a-GR for help-gnu-emacs@gnu.org; Thu, 18 Apr 2024 23:10:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1713496231; x=1713755431; bh=dRaP4IxPf/U9eGEEF87XxgPXcb/YXe+4RCGxoY7CgyA=; 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=o6OIZfsYvG355LydMdwb4K3QJQAPm3k5XUgQhLlo2eEUljxSRa4TNIxSniMYle7e7 g8gAlh3I302U/5M/51UT92kVJKlJ/pMTF2PF+yQFB6fYjXZs5f5SuqfmO0szzmjceV RHu4dvch2dqjPcirMT7z/ssy8JDnnqryXaG0B/fi59J7LBxDG70OZtDmSt2d/tL6kY CRdZPHGHmKmImjnILRO0UHuF5h3B86J+vUK+ib/HQ54i0JsiwYkyUcKAfEyCWjswhB 1GUq02B8wASRE0XS+yDJLLfoM00MGpS91flRmvMM83Rr5fzYt6er/XVVFCF1LbZyzr naL7aP45Xeg3w== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 3b37151681f9dd2cb13913ea86c338616d519f95 Received-SPF: pass client-ip=185.70.40.141; envelope-from=heimeborgia@protonmail.com; helo=mail-40141.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, TO_EQ_FM_DIRECT_MX=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:146367 Archived-At: On Friday, April 19th, 2024 at 2:59 PM, Heime = wrote: > On Friday, April 19th, 2024 at 2:14 PM, Drew Adams drew.adams@oracle.com = wrote: >=20 > > > Haw can I have an interactive function that > > > displays a list of elements from an associated > > > list using completing-read ? > >=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 comple= tions, > > but instead you want to see their keys, then just do this: >=20 > > (completing-read "Choose an alist key: " my-alist nil t) >=20 >=20 > Yes, I wanted to see the keys as completing entries. Right, looking > at the documentation COLLECTION can be an alist and will print the keys. >=20 > I had the cons cells the other way round, with the actual key as the cdr, > making completing-read display the wrong entry. >=20 > > 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): > >=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. How can I get the value associated with a key. The following does not get = me the=20 value associated with my-key.=20 (let ( (lnum (cdr (rassoc my-key my-alist)))) (when lnum (goto-line lnum))))) )