From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Date: Fri, 11 Jun 2021 10:03:25 +0300 Message-ID: References: <87lf7g9ahl.fsf@robertthorpeconsulting.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29439"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: help-gnu-emacs@gnu.org To: Robert Thorpe Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 11 09:08:21 2021 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 1lrbHB-0007SP-CZ for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 11 Jun 2021 09:08:21 +0200 Original-Received: from localhost ([::1]:44102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrbH9-0005NG-S9 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 11 Jun 2021 03:08:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrbGh-0005N7-35 for help-gnu-emacs@gnu.org; Fri, 11 Jun 2021 03:07:51 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:46685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrbGf-0003SW-9w for help-gnu-emacs@gnu.org; Fri, 11 Jun 2021 03:07:50 -0400 Original-Received: from localhost ([::ffff:197.157.0.23]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000D59E2.0000000060C30BC1.00003A36; Fri, 11 Jun 2021 00:07:44 -0700 Mail-Followup-To: Robert Thorpe , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87lf7g9ahl.fsf@robertthorpeconsulting.com> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:130750 Archived-At: * Robert Thorpe [2021-06-11 09:34]: > Jean Louis writes: > > > Definitely good idea and now I was thinking there is some description > > pointing to it and have looked into `completing-read' and > > `read-from-minibuffer' and found nothing, I have to provide a variable > > or cons with variable to those functions. It is good idea definitely, > > but show me the practical way how to use alist or hash in those > > functions. > > AFAICT, What you need to do is to populate a variable from the > alist. Then pass that variable to to `completing-read' or > `read-from-minibuffer'. I got the idea. But then... is that history just temporary or retained over sessions? Common history variables are retained in ~/.emacs.d/history > I'm not sure what you mean here. In one global alist you could put lots > and lots of information. There could be an entry for each history list > that you need. I don't see why you need to pass around functions > here. I do understand the idea that one history pre-variable would be used to keep history for the generated on the fly modified history variable that is used in `read-from-minibuffer', but then it will probably not be retained and it would be vague, unclear to where such history belongs. Additionally I would need to find way to keep the alist variable somewhere stored as well. Idea is understandable, but way too complicated. We better conclude that the issue is solved and it works well without problems. Using `eval' is there for a reason. The snippet below solves it. Shorter solution is useful, if you have one: (defun rcd-symbol-if-not-exist (variable &optional value description) "Return symbol for VARIABLE string. It will generate new VARIABLE if it does not exist." (let ((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))))) (rcd-symbol-if-not-exist "my-new-symbol" "Value here" "Some description") ⇒ my-new-symbol ⇒ "Value here" (setq my-new-symbol 10) ⇒ 10 my-new-symbol ⇒ 10 It is handy that it will not change the existing value of the variable, just return a symbol or generate it: (rcd-symbol-if-not-exist "my-new-symbol" "Value here" "Some description") ⇒ my-new-symbol ⇒ 10 for history it is then very useful to dynamically generate history variables: (let* ((name "Streets") (history (concat name "-history"))) (read-from-minibuffer "Street: " nil nil nil (rcd-symbol-if-not-exist history))) Streets-history ⇒ ("Elm Street") It will be saved in ~/.emacs.d/history as: (setq Streets-history '("Elm Street")) User has to think of how such history variables should be called as not to collide with others. > > It works this way: > > > > (let ((history '("One" "Two" "Three"))) > > (read-from-minibuffer "Tell me: " nil nil nil 'history)) > > > > Or this way: > > > > (let ((history '("One" "Two" "Three"))) > > (read-from-minibuffer "Tell me: " nil nil nil '(history . 1))) > > None of those three work for me. That is, none give a history list. On my side these below work: (let ((history '("One" "Two" "Three"))) (read-from-minibuffer "Tell me: " nil nil nil 'history)) (let ((history '("One" "Two" "Three" "Four"))) (read-from-minibuffer "Tell me: " nil nil nil '(history . 1))) Press arrow up. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/