[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elpa] externals/auctex cb0a1e6be1 72/77: Improve function calls to
From: |
Tassilo Horn |
Subject: |
Re: [elpa] externals/auctex cb0a1e6be1 72/77: Improve function calls to retrieve key=vals in style hooks |
Date: |
Fri, 26 Aug 2022 22:47:47 +0200 |
User-agent: |
mu4e 1.9.0; emacs 29.0.50 |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
Hi Stefan & Arash,
> Tassilo Horn [2022-08-26 16:06:39] wrote:
>> Improve function calls to retrieve key=vals in style hooks
>>
>> * latex.el (TeX-read-key-val): Improve call of functions as
>> argument of `TeX-arg-key-val' inside style hooks.
> [...]
>> (fboundp (car key-val-alist)))
>> - (let ((head (car key-val-alist))
>> - (tail (cdr key-val-alist)))
>> - (apply head tail)))
>> + (if (> (length key-val-alist) 1)
>> + (eval key-val-alist t)
>> + (funcall (car key-val-alist))))
>> (t
>
> FWIW, replacing `apply` with `eval` is not an "Improve"ment in my book
> :-) It means now that `key-val-alist` contains code represented as
> data (i.e. code to which flymake, the compiler, the eager
> macroexpander, etc... don't have access) whereas it previously only
> contains values (which can't contain code that needs macroexpansion,
> for example).
That's true. I've searched the auctex lists and found out that Arash
made this change because he wanted to make it possible for styles to do
stuff like
(TeX-add-style-hook
"foo"
(lambda ()
(TeX-add-symbols
'("bar" (TeX-arg-key-val (append alist1 alist2))))))
where (append alist1 alist2) is what's being evaled. Arash, wouldn't
(TeX-add-style-hook
"foo"
(lambda ()
(TeX-add-symbols
`("bar" (TeX-arg-key-val ,(append alist1 alist2))))))
be just as good? I guess no because IIRC the context was that alist1
and alist2 might be populated dynamically (by parsing the document) so
we need to take the values at the time the \bar macro is inserted. So
probably
(TeX-add-style-hook
"foo"
(lambda ()
(TeX-add-symbols
`("bar" (TeX-arg-key-val ,(lambda () (append alist1 alist2)))))))
would be the right thing which works without eval, right? It's a bit
longer but I wouldn't mind. Wrapping code in a lambda to be evaluated
later is a common concept.
Bye,
Tassilo
Re: [elpa] externals/auctex cb0a1e6be1 72/77: Improve function calls to retrieve key=vals in style hooks, Emanuel Berg, 2022/08/26
Re: [elpa] externals/auctex cb0a1e6be1 72/77: Improve function calls to retrieve key=vals in style hooks, Richard Stallman, 2022/08/28