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: Wed, 9 Jun 2021 11:22:38 +0300 Message-ID: References: <20210608200312.GE14693@tuxteam.de> <20210608202326.GG14693@tuxteam.de> <20210609060959.GA21706@tuxteam.de> <20210609065129.GB21706@tuxteam.de> <20210609073928.GC21706@tuxteam.de> 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="13644"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: Help GNU Emacs To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 09 10:26:41 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 1lqtXr-0003Jj-FH for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 10:26:39 +0200 Original-Received: from localhost ([::1]:33030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqtXp-0007kQ-Ky for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 04:26:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqtXW-0007k4-5z for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 04:26:18 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:55989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqtXU-00082b-8Y for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 04:26:17 -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.0000000060C07B25.00005657; Wed, 09 Jun 2021 01:26:12 -0700 Mail-Followup-To: tomas@tuxteam.de, Help GNU Emacs Content-Disposition: inline In-Reply-To: <20210609073928.GC21706@tuxteam.de> 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:130662 Archived-At: * tomas@tuxteam.de [2021-06-09 10:40]: > You snipped the (for me) interesting part: did you notice how > `eval' jumps over the local declaration? Do you mean variables within `let'? (defun rcd-db-completing-table-history (table) "Return symbol of history variable for TABLE. If TABLE is \"businesses\" the symbol will become `rcd-db-completing-table-history-businesses' and it will be used for functions `completing-read' and `read-from-minibuffer' history. If a dynamically generated variable does not exist, it will be generated on the fly." (let ((rcd-symbol (intern (concat "rcd-db-completing-table-history-" table))) (description (format "History for table `%s'" table))) (if (boundp rcd-symbol) rcd-symbol (eval (list 'defvar rcd-symbol nil description))))) In the above function I want to get a symbol of a global history variable. read-from-minibuffer is a built-in function in ‘C source code’. (read-from-minibuffer PROMPT &optional INITIAL-CONTENTS KEYMAP READ HIST DEFAULT-VALUE INHERIT-INPUT-METHOD) (completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD) History symbol HIST is used in the above functions. There are many various columns and database tables and is for time being difficult to find which one references to which one. New tables are created each in a while, new variables would need to be created, that is not handy. Users may create new variables too. It is easier to dynamically (not related to dynamic bindings) assign global variables that keep the history for `completing-read' and `read-from-minibuffer'. It is useful not to mess with the global history. > It doesn't even /see/ it, the defun whithin the eval munged with the > outer scope (which might be buffer-local or just global). There is `defvar' within the eval, it defines global variables. I don't knof is such variable should be really buffer local, most probably not as user may invoke functions from outside of the common modes or buffers. > If this is what you want, fine. If it's not, think again. I can't > even venture a guess towards what you have in mind, I'm that bad > at interpreting what you write. Maybe you should start using history variables in `read-from-minibuffer' or `completing-read' and you will understand that one has to give some symbol. In the context of editing column values in multiple database tables the difficulty is that one would need to assign a history variable to each such column names. Columns are also changeable, they could be even changed by user on the fly. If I hard code the history variable then user would need to modify the source. This way history variables are dynamically created without modification of the source. I have explained what I want: - to dynamically (not related to global bindings) request for a symbol representing a global variable; - function or macro should either create the new global variable and return the symbol or return the existing symbol if variable exists already; The bottom line is, what is the solution? The only solution that works is in the above function, maybe something else would work but I would not know how to implement it. > And then there is the issue of how readable your code becomes, > which will be important or not, depending on whether you want > others to read it or not. Readability can be improved, but if there is no functionality why focus on readability? You imply you know how to make it, so let me know how to make it better. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/