help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED with `eval']: Why I cannot use this variable in macro call from


From: Jean Louis
Subject: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?
Date: Tue, 8 Jun 2021 22:27:04 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]