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: Thu, 10 Jun 2021 09:56:04 +0300 Message-ID: References: <87y2bibhaq.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="16927"; 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 Thu Jun 10 08:58:20 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 1lrEdw-0004E1-Gv for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Jun 2021 08:58:20 +0200 Original-Received: from localhost ([::1]:60314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrEdv-000469-Fo for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Jun 2021 02:58:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrEdV-00045a-0b for help-gnu-emacs@gnu.org; Thu, 10 Jun 2021 02:57:53 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:48739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrEdT-0005wk-65 for help-gnu-emacs@gnu.org; Thu, 10 Jun 2021 02:57:52 -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 00000000000ADF27.0000000060C1B7E9.00007D20; Wed, 09 Jun 2021 23:57:44 -0700 Mail-Followup-To: Robert Thorpe , tomas@tuxteam.de, help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87y2bibhaq.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:130694 Archived-At: * Robert Thorpe [2021-06-10 05:12]: > I just want to say a couple of things about this. > > I think you should read the Emacs lisp manual more. Or maybe even > another book on Lisp. Understanding of scope is important. So are > macros and quoting if you're using them. > > For the snippet of code that Tomas gives I get the same result: > > (let () > > (let ((x 42)) > > (eval '(progn (setq x 43) (message "in eval: x is %S" x))) > > (message "inner let: x is %S" x)) > > (message "outer let: x is %S" x)) > > Gives: > > > in eval: x is 43 > > inner let: x is 42 > > outer let: x is 43 > > "outer let: x is 43" > > I don't get any errors. With `emacs -Q' I get no errors in *scratch*, now I can see that. I can see that my *scratch* was changing lexical bindings. When I invoke it in a new emacs-lisp-mode buffer there is error under dynamic bindings, and no error under lexical bindings. IMHO everybody should learn more and so I do. Obviously I did not find the way. Whoever has read more than me, then I am asking to give me references. > However, I think that your problem doesn't really require any of > that complexity. I think it can be done with an Alist. > > Why not save all of your histories into one alist? Instead of an alist > you could use a hash. I don't see why you have to create a set of new > global variables to solve the problem. 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. > You have a function that creates one of those variables. Why not > replace it with a function that enters the information in a global > alist? Then you only need one global variable. Then when you need to > call "completing-read" use an assoc to find the sub-list to use.o Your ideas go to the root or to depth of the problem. But how practically to do that? I don't want to change those functions, I want to pass something to them which will have dynamic names or arguments. I could assign a single global buffer-local variable that keeps the name of the edited column, and the function passed could then find that variable and fetch from alist. But how? (read-from-minibuffer PROMPT &optional INITIAL-CONTENTS KEYMAP READ HIST DEFAULT-VALUE INHERIT-INPUT-METHOD) Fifth arg HIST, if non-nil, specifies a history list and optionally the initial position in the list. It can be a symbol, which is the history list variable to use, or a cons cell (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable to use, and HISTPOS is the initial position for use by the minibuffer history commands. For consistency, you should also specify that element of the history as the value of INITIAL-CONTENTS. Positions are counted starting from 1 at the beginning of the list. If HIST is the symbol ‘t’, history is not recorded. It works this way: (let ((history '("One" "Two" "Three"))) (read-from-minibuffer "Tell me: " nil nil nil 'history)) Not this way: (let ((history (lambda () '("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))) and I guess it is similar situation here: (completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD) , if non-nil, specifies a history list and optionally the initial position in the list. It can be a symbol, which is the history list variable to use, or it can be a cons cell (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable to use, and HISTPOS is the initial position (the position in the list used by the minibuffer history commands). For consistency, you should also specify that element of the history as the value of INITIAL-INPUT. (This is the only case in which you should use INITIAL-INPUT instead of DEF.) Positions are counted starting from 1 at the beginning of the list. The variable ‘history-length’ controls the maximum length of a history list. If HIST is the symbol ‘t’, history is not recorded. Question is how practically? -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/