From: Jean Louis <bugs@gnu.support>
To: tomas@tuxteam.de
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
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 [thread overview]
Message-ID: <YMB6TteQaufPyGTR@protected.localdomain> (raw)
In-Reply-To: <20210609073928.GC21706@tuxteam.de>
* tomas@tuxteam.de <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/
next prev parent reply other threads:[~2021-06-09 8:22 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 13:10 Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 13:41 ` [External] : " Drew Adams
2021-06-08 14:47 ` Jean Louis
2021-06-08 17:14 ` Jean Louis
2021-06-08 18:31 ` tomas
2021-06-08 18:37 ` Oops function? tomas
2021-06-08 19:27 ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:03 ` tomas
2021-06-08 20:06 ` Sorry again tomas
2021-06-08 20:12 ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:23 ` tomas
2021-06-08 20:38 ` Jean Louis
2021-06-08 20:47 ` Jean Louis
2021-06-09 6:09 ` tomas
2021-06-09 6:42 ` Jean Louis
2021-06-09 6:51 ` tomas
2021-06-09 7:03 ` Jean Louis
2021-06-09 7:39 ` tomas
2021-06-09 8:22 ` Jean Louis [this message]
2021-06-09 8:54 ` tomas
2021-06-09 10:56 ` Jean Louis
2021-06-09 11:33 ` tomas
2021-06-09 14:39 ` Jean Louis
2021-06-09 16:41 ` tomas
2021-06-10 2:10 ` Robert Thorpe
2021-06-10 6:56 ` Jean Louis
2021-06-11 6:33 ` Robert Thorpe
2021-06-11 7:03 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YMB6TteQaufPyGTR@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=tomas@tuxteam.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).