auctex-devel
[Top][All Lists]
Advanced

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

Re: [AUCTeX-devel] Adding key/vals to predefined ones


From: Tassilo Horn
Subject: Re: [AUCTeX-devel] Adding key/vals to predefined ones
Date: Fri, 13 Feb 2015 11:22:58 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Arash Esbati <address@hidden> writes:

Hi Arash,

> Thanks for your suggestion, will do so.  But I am still struggling
> with one other issue.  Consider this example (say filename.tex):
>
> \documentclass{article}
>
> \usepackage[inline]{enumitem}
>
> \SetEnumitemKey{twocol}{itemsep=1\itemsep}
> \SetEnumitemValue{label}{numeric}{\arabic*}
> \SetEnumitemValue{leftmargin}{standard}{\parindent}
>
> \begin{document}
> \begin{itemize}[twocol,label=numeric,leftmargin=standard]
> \item 
> \end{itemize}
> \end{document}
>
>
> When I insert all above, everything works and
> `LaTeX-enumitem-key-val-options' gets updated.

I think that shouldn't be added there but instead into (the currently
commented) buffer-local `LaTeX-enumitem-key-val-options'.  I see that
now `LaTeX-enumitem-key-val-options' is buffer-local, but IMHO it makes
sense to separate always available options from local custom-defined
ones.  So I'd have that var non-buffer-local + a buffer-local *-local
var.

> After hitting `C-c C-n', AUCTeX writes this into `filename.el'
>
> (TeX-add-style-hook ...
>   (LaTeX-add-enumitem-SetEnumitemKeys
>     "twocol")
>   (LaTeX-add-enumitem-SetEnumitemValues
>     '("label" "numeric")
>     '("leftmargin" "standard"))
>
> Now I close the file and re-open it.  My question is: What is the best
> way to get the key/vals back into
> `LaTeX-enumitem-key-val-options[-local]'?  My simple approach below
> returns always nil for `TEST'.

After re-opening the file, (LaTeX-enumitem-SetEnumitemKey-list) and
(LaTeX-enumitem-SetEnumitemValue-list) already return the key/key-vals
parsed previously, so that works fine.

Hm, thinking about it, I guess you should drop
`LaTeX-enumitem-key-val-options-local' completely (and have the
non-"-local" one not buffer-local), and use these two functions in your
completion functions directly because I don't see a value in moving
stuff from these two already working functions (and their underlying
vars) into other variables whose only benefit it a better name.  So your
completion functions would use as completion table

  (append (LaTeX-enumitem-SetEnumitemKey-list)
          (LaTeX-enumitem-SetEnumitemValue-list)
          LaTeX-enumitem-key-val-options)

With that order, custom keys/key-vals would take preference over
standard ones, e.g., you could override standard opts.  I don't use
enumitem, so I'm not sure if that's possible/allowed, but I guess that
should answer your question.

> (defun LaTeX-enumitem-auto-cleanup ()
>   "Move parsing results into right places for further usage."
>   ;; \newlist{<name>}{<type>}{<max-depth>}
>   ;; env=<name>, type=<type>, ignored=<max-depth>
>   (dolist (env-type LaTeX-enumitem-newlist-auto)
>     (let* ((env  (car env-type))
>          (type (cadr env-type)))
>       (add-to-list 'LaTeX-auto-environment
>                  (list env 'LaTeX-enumitem-env-with-opts))
>       (add-to-list 'LaTeX-enumitem-newlist-list
>                  (list env))
>       (when (or (string-equal type "description")
>               (string-equal type "description*"))
>       (add-to-list 'LaTeX-enumitem-newlist-list-item-arg
>                    (list env)))))
>   ;; \SetEnumitemKey{<key>}{<replacement>}
>   (dolist (key LaTeX-auto-enumitem-SetEnumitemKey)
>     (add-to-list 'LaTeX-enumitem-SetEnumitemKey-list
>                (list key)))
>   ;; \SetEnumitemValue{<key>}{<string>}{<replacement>}
>   (dolist (key-val LaTeX-auto-enumitem-SetEnumitemValue)
>     (let* ((key (car key-val))
>          (val (cdr key-val)))
>       (list key val))))

Oh, you don't add the contents of `LaTeX-auto-enumitem-SetEnumitemValue'
to `LaTeX-enumitem-SetEnumitemValue-list', and yet after closing and
finding the test file again, the value is correct.  So apparently the
call (LaTeX-add-enumitem-SetEnumitemValues ...) which is in the auto
testfile.el does that for you already.  So it seems you can drop the
\SetEnumitem* handling from your cleanup function altogether.

Another unrelated note: please name your auto-variables consistently,
e.g. `LaTeX-auto-enumitem-WHATEVER' or `LaTeX-enumitem-auto-WHATEVER'.
I prefer the latter style, but AFAICS we have both styles already, so
choose whatevery you like best but then stick to that style.  So, e.g.,
`LaTeX-enumitem-newlist-auto' should become
`LaTeX-enumitem-auto-newlist', etc.

Bye,
Tassilo




reply via email to

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