From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: carlmarcos--- via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Operating the HIST feature of completing-read Date: Tue, 12 Jul 2022 02:13:29 +0200 (CEST) Message-ID: References: Reply-To: carlmarcos@tutanota.com 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="40730"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs To: Jean Louis Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 12 02:14:04 2022 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 1oB3XP-000AP3-9W for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Jul 2022 02:14:03 +0200 Original-Received: from localhost ([::1]:60794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB3XN-00046T-TL for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 11 Jul 2022 20:14:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB3Wx-00046L-E1 for help-gnu-emacs@gnu.org; Mon, 11 Jul 2022 20:13:35 -0400 Original-Received: from w1.tutanota.de ([81.3.6.162]:36064) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB3Wv-0002lF-5H for help-gnu-emacs@gnu.org; Mon, 11 Jul 2022 20:13:35 -0400 Original-Received: from w3.tutanota.de (unknown [192.168.1.164]) by w1.tutanota.de (Postfix) with ESMTP id 89D76FBF8CD; Tue, 12 Jul 2022 00:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657584809; s=s1; d=tutanota.com; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=TYglLOcBsBWP1MfyhCsOpt4UhjEDbEjPM1+hTzfDfrc=; b=tibapmsGE74saVV3tNfWREVdCTHacr3peryOg+zNA1PfjmctSu+SZw9dD3atGc+G ZrfyjQRI1ttADatW6T1hzMUQf1RUgv/fbUBfElbdrXeEH0pWOJ6Cs3138WABmfGWI2u 1L8JXwtVxFKzrCFPzL1Rc965cEz0hPjtpe/Sri6TPndJ6FTPeqB3bII3pjO5ftWBsQb eAeZBzGD8+qHp6Gh0fgEKAc0eXIHmY/IxNy969+EkOKbayAYZWrbG55U0J9XN2Ts4QU mYL7AVG+EUZq4TVQos9lXTO/pY6CQJsn972wlVdtayt/C7936pRh/AS2ROQfKxzvKOe xvgqoWEk4g== In-Reply-To: Received-SPF: pass client-ip=81.3.6.162; envelope-from=carlmarcos@tutanota.com; helo=w1.tutanota.de 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, HTML_MESSAGE=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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" Xref: news.gmane.io gmane.emacs.help:138420 Archived-At: Jul 11, 2022, 22:43 by bugs@gnu.support: > * carlmarcos--- via Users list for the GNU Emacs text editor [2022-07-11 03:23]: > >> How does HIST work when using completing-read?=C2=A0 Any examples that >> would help me with this? >> > > I find HIST variables a waste in coding, so I am automating it by > automatically assigning HIST variable to every call to the function. > I found your elaboration difficult to follow.=C2=A0 I just need a summary o= n what it is, how to use it, and how it works.=C2=A0 Without wrappers and c= lever stuff. > (defun rcd-symbol-if-not-exist (variable &optional value description) > "Return symbol for VARIABLE.=20 > > It will generate new VARIABLE if it does not exist." > (let* ((variable (replace-regexp-in-string "[^[:alnum:]]" "-" (downcase = variable))) > (rcd-symbol (intern variable)) > (description (or description (format "Generated variable `%s'" variable)= ))) > (if (boundp rcd-symbol) > rcd-symbol > (eval (list 'defvar rcd-symbol value description))))) > > (defun rcd-ask-history-variable (prompt) > "Generate history variable for PROMPT." > (let* ((description (format "History for `%s' prompt." prompt))) > (rcd-symbol-if-not-exist (concat "rcd-" prompt "-history") nil descripti= on))) > > Then there is my wrapper function for `completing-read`: > > (defun rcd-choose (list &optional prompt predicate initial-input def) > "Ask user for LIST of choices. > If only one element, function `y-or-n-p' will be used. > For multiple elements `completing-read' is used. > > If nothing chosen it will return empty string." > (let* ((completion-ignore-case t) > (prompt (or prompt "Choose: ")) > (description (format "History for `%s' completion prompt." prompt)) > (history (rcd-symbol-if-not-exist (concat "rcd-" prompt "-history") nil = description)) > (input (cond ((length=3D list 1) (if (y-or-n-p (nth 0 list)) (nth 0 list= ) "")) > (t (rcd-repeat-until-not-empty-string 'completing-read prompt list predi= cate t initial-input history def t))))) > input)) > > That generates history variables automatically in the line, based on > the prompt: > > (history (rcd-symbol-if-not-exist (concat "rcd-" prompt "-history") nil d= escription)) > > Then this below would use history variable: rcd-choose---history > > (rcd-choose '("One" "Two" "Three")) > > because following evaluates to that symbol: > > (rcd-symbol-if-not-exist (concat "rcd-" "Choose: " "-history") nil "Histo= ry for `Choose: ' completion prompt.") =E2=87=92 rcd-choose---history > > However, any other prompt would yield automatically with a different > history variable based on its prompt like "Choose a number: " > > (rcd-choose '("One" "Two" "Three") "Choose a number: ") =E2=87=92 "One" > > > --=20 > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > In support of Richard M. Stallman > https://stallmansupport.org/ >