unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: tomas@tuxteam.de
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?
Date: Tue, 8 Jun 2021 22:27:04 +0300	[thread overview]
Message-ID: <YL/EiLI0CeKB/UnL@protected.localdomain> (raw)
In-Reply-To: <20210608183138.GA14693@tuxteam.de>

Thanks Tomas.

I know you have sharp mind. Is there a way to dynamically
generate global variable based on a string and use it as history?

It's interesting how this works:

(defmacro rcd-gen-defvar (name description)
  `(defvar ,(intern name) nil ,description))

Now I can repeat and use the below and it will remember history:

(read-from-minibuffer "Tell me: " nil nil nil (rcd-gen-defvar "my-history" "This is history"))

I was expecting it NOT to work as I was expecting `defvar' to be
repeated and to nullify the value, but it does not.

In the next step all what I would need is to dynamically
give "my-history" to macro `rcd-gen-defvar', but as I don't know
how to do that, heaven thanks there is function `eval' which
solves the problem.

Now this function is to create the history variable if it does
not exist and basically returns its symbol for completion
function like the one below.

(defun rcd-db-completing-table-history (table)
  (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)))))

(defun rcd-db-combo-selection (table)
  (let* ((prompt (format "Select within table `%s': " table))
	 (prompt (append-colon-space prompt))
	 (sql (format "SELECT * FROM %s_combo ORDER BY id DESC" table)))
    (rcd-completing-read-sql-hash prompt sql cf-db (rcd-db-completing-table-history table))))

I have lost hours trying all possible combinations. From Lisp I
do expect those combinations to be possible. At least `eval'
works. It saves me continous variable definitions for each new
foreign referenced table in PostgreSQL. I guess there must be few
hundreds of such variables overall.

Like table people_prefixes now receivs the variable
`rcd-db-completing-table-history-prefixes' automatically for
history. Table people_sufixes receives
`rcd-db-completing-table-history-suffixes' automatically as that
is useful to minimize repetitions and to avoid errors with the
mixed input history.

-- 

Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



  parent reply	other threads:[~2021-06-08 19:27 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       ` Jean Louis [this message]
2021-06-08 20:03         ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? 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
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=YL/EiLI0CeKB/UnL@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).