Hi Keita, Ikumi Keita <[email protected]> writes:
>>>>>> 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)))))) >> WDYT? > > It seems flexible and promising. I like this implementation. Thanks for looking into this and your response. > Two minor points I noticed: > 1. Maybe > (symbol-value key-val-alist) > is more appropriate than > (eval key-val-alist t) > for its directness. In general, you're right, but since we have turned on lexical binding in AUCTeX, we have this situation: ,----[ C-h f eval RET ] | eval is a built-in function in ‘C source code’. | | (eval FORM &optional LEXICAL) | | Evaluate FORM and return its value. | If LEXICAL is t, evaluate using lexical scoping. | LEXICAL can also be an actual lexical environment, in the form of an | alist mapping symbols to their value. `---- and ,----[ C-h f symbol-value RET ] | symbol-value is a built-in function in ‘C source code’. | | (symbol-value SYMBOL) | | Return SYMBOL’s value. Error if that is void. | Note that if ‘lexical-binding’ is in effect, this returns the | global value outside of any lexical scope. `---- I'm not sure if we get into trouble if a globally defvar'ed key-val list is let-bound and changed in a function call using `TeX-read-key-val'. WDYT? I haven't checked the occurrence of this within AUCTeX, though. > 2. "KEY-VAL-ALIST can be a symbol or a function call ..." > It seems that "function call" is a bit ambiguous to me. How about > "KEY-VAL-ALIST can be a variable or a function ..."? I wanted to express that something like this would not work: (TeX-add-style-hook "foo" (lambda () (TeX-add-symbols '("bar" (TeX-arg-key-val function-returning-key-val))))) If you think your suggestion is more clear, I'm happy to adjust the docstring. Thank, Arash
