Arash Esbati <[email protected]> writes: > We could ease the situation if we change `TeX-read-key-val' to: > > (defun TeX-read-key-val (optional key-val-alist &optional prompt) > "Prompt for keys and values in KEY-VAL-ALIST and return them. > If OPTIONAL is non-nil, indicate in the prompt that we are > reading an optional argument. KEY-VAL-ALIST is an alist. The > car of each element should be a string representing a key and the > optional cdr should be a list with strings to be used as values > for the key. KEY-VAL-ALIST can be a symbol or a function call > returning an alist. Use PROMPT as the prompt string." > (multi-prompt-key-value > (TeX-argument-prompt optional prompt "Options (k=v)") > (cond ((and (symbolp key-val-alist) > (boundp key-val-alist)) > (eval key-val-alist t)) > ((and (listp key-val-alist) > (symbolp (car key-val-alist)) > (fboundp (car key-val-alist))) > (let ((head (car key-val-alist)) > (tail (cdr key-val-alist))) > (apply head tail))) > (t > key-val-alist)))) > > > Then one could define a function returning up-to-date key-vals and use > it in the style hook like this: > > (TeX-add-style-hook > "foo" > (lambda () > (TeX-add-symbols > '("bar" (TeX-arg-key-val (function-returning-key-val))))))
Following up myself, I applied the change above (commit 6433dc38e4).
I'm still not happy with it because one can't do something like this in
a style file:
(TeX-add-style-hook
"foo"
(lambda ()
(TeX-add-symbols
'("bar" (TeX-arg-key-val (append alist1 alist2))))))
In order to make it work, `eval' should be used instead of `apply'. I'm
attaching a style file mytest.el which is used in minimal.tex exhibiting
possible solutions. The straight one would be this change:
(defun TeX-read-key-val (optional key-val-alist &optional prompt)
(multi-prompt-key-value
(TeX-argument-prompt optional prompt "Options (k=v)")
(cond ((and (symbolp key-val-alist)
(boundp key-val-alist))
(symbol-value key-val-alist))
((and (listp key-val-alist)
(symbolp (car key-val-alist))
(fboundp (car key-val-alist)))
(eval key-val-alist t))
(t
key-val-alist))))
or maybe this one:
(defun TeX-read-key-val (optional key-val-alist &optional prompt eval)
(multi-prompt-key-value
(TeX-argument-prompt optional prompt "Options (k=v)")
(cond ((and (symbolp key-val-alist)
(boundp key-val-alist))
(symbol-value key-val-alist))
((and (listp key-val-alist)
(symbolp (car key-val-alist))
(fboundp (car key-val-alist)))
(if eval
(eval key-val-alist t)
(let ((head (car key-val-alist))
(tail (cdr key-val-alist)))
(apply head tail))))
(t
key-val-alist))))
Or a version I'm missing? I have a preference for the former one. Any
comments welcome.
Best, Arash
mytest.el
Description: application/emacs-lisp
minimal.tex
Description: TeX document
