emacs-devel
[Top][All Lists]
Advanced

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

TeX-arg-key-val syntax and let go of eval (was: [elpa] externals/auctex


From: Tassilo Horn
Subject: TeX-arg-key-val syntax and let go of eval (was: [elpa] externals/auctex cb0a1e6be1 72/77: Improve function calls to retrieve key=vals in style hooks)
Date: Tue, 30 Aug 2022 07:33:55 +0200
User-agent: mu4e 1.9.0; emacs 29.0.50

Arash Esbati <arash@gnu.org> writes:

>> So what's wrong with this one?
>>
>> (TeX-add-style-hook
>>  "foo"
>>  (lambda ()
>>    (TeX-add-symbols
>>     `("bar" (TeX-arg-key-val
>>              ,(lambda ()
>>                (append (func1-returning-keyval-alist)
>>                        (func2-returning-keyval-alist))))))))
>
> If this is the best/only option, well, I'm buying it :)

It's the typical lispy solution which doesn't require eval.

>> That's again caught by the functionp case and can simply be
>> funcalled.
>
> How would you then re-write `TeX-read-key-val'?

In my suggested version where (TeX-arg-key-val foo) would funcall foo if
it were a function (without having to wrap it in parentheses), it would
be:

--8<---------------cut here---------------start------------->8---
(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 (functionp key-val-alist)
               (fboundp key-val-alist))
          (funcall key-val-alist))
         ((and (symbolp key-val-alist)
               (boundp key-val-alist))
          (symbol-value key-val-alist))
         ((and (listp key-val-alist)
               (listp (car key-val-alist)))
          key-val-alist)
         (t (error "Cannot interpret key-val-alist %S" key-val-alist)))))
--8<---------------cut here---------------end--------------->8---

> And while we're at, what do we do with `TeX-arg-eval'?

Nothing.  It's been there since 1994 so we cannot really do anything
except declaring it obsolete.  But since probably nobody byte-compiles
his styles and therefore might see the warning, we will never be able to
get rid of it.

>> I'd rather prefer to keep the DSL simple, e.g., TeX-arg-key-val
>> arguments can either be a literal alist, a function of no args
>> delivering an alist, or a symbol denoting an alist variable (checked in
>> that order).  That is, I wouldn't even distinguish functions from
>> variables syntactically but prefer functions in general, e.g.,
>>
>>   (TeX-arg-key-val (LaTeX-enumitem-key-val-options))
>>
>> would become
>>
>>   (TeX-arg-key-val LaTeX-enumitem-key-val-options)
>>
>> where LaTeX-enumitem-key-val-options is funcalled and takes
>> precedence of the variable of the same name.
>
> Hmm, Sorry, but I don't like this.  Why taking away the clarity of
> what is currently used, the variable or the function?  I think having
> the function call in () increases the legibility.

Because it makes TeX-read-key-val easy to implement (no need to
distinguish a "funcall list" from a literal alist) and the heuristics
"try function, else try variable, else try literal alist" is really not
hard.  Also because

   '(TeX-arg-key-val (LaTeX-enumitem-key-val-options))

looks like normal evaluation syntax but that symmetry immediately breaks
with

   `(TeX-arg-key-val ,(lambda () ...))

which would need to be

   `(TeX-arg-key-val (,(lambda () ...)))

to keep symmetry.  But then we're in lisp-1 land which also looks
wrong. :-)

>> Sorry, I know we had a discussion back then where I haven't been
>> explicit enough or haven't had an informed opinion yet. :-(
>
> No problem, you will have to adjust all AUCTeX styles for being late
> ;-)

Sure, I can do that but want to achieve a consensus first.  Given that I
haven't written a LaTeX doc in at least 6 years and consequently my
AUCTeX activities have much decreased, I'm not in a position to enforce
my personal preferences.

Bye,
Tassilo

PS: I've added auctex-devel to the Cc and set Reply-To accordingly.



reply via email to

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