[Top][All Lists]

[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: Tue, 24 Feb 2015 21:30:59 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Arash Esbati <address@hidden> writes:

> Tassilo Horn <tsdh <at>> writes:
> Hi Tassilo,
>> I haven't looked at your complete code again but isn't the problem with
>> the buffer-local variable that it's, well, buffer-local whereas it
>> actually should be document-local.  That is, in a multi-file document
>> using enumitem, the new key-vals are only available in the buffer of the
>> file containing the new key-val definition but not in other buffers of
>> the same document?
> The buffer-local variable is set by the function
> `LaTeX-enumitem-update-key-val-options' which relies on
> `LaTeX-enumitem-SetEnumitem(Key|Value)-list' controlled by AUCTeX
> auto-parser.  My presumption was that it should work this way.

Ah, yes.  But I still have some question about that function.

--8<---------------cut here---------------start------------->8---
(defun LaTeX-enumitem-update-key-val-options ()
  "Update the buffer-local key-val options before offering them
in `enumitem'-completions."
  (unless (null LaTeX-enumitem-SetEnumitemKey-list)
    (dolist (key (apply 'append LaTeX-enumitem-SetEnumitemKey-list))
      (add-to-list 'LaTeX-enumitem-key-val-options-local (list key))))
  (unless (null LaTeX-enumitem-SetEnumitemValue-list)
    (dolist (keyvals (apply 'append LaTeX-enumitem-SetEnumitemValue-list))
      (let* ((key (car keyvals))
             (val (cadr keyvals))
             ;; (key-match (car (assoc key 
             (val-match (cdr (assoc key LaTeX-enumitem-key-val-options-local)))
             (temp  (copy-alist LaTeX-enumitem-key-val-options-local))
             (opts (assq-delete-all (car (assoc key temp)) temp)))
        (if (null val-match)
            (add-to-list 'opts (list key (list val)))
          (add-to-list 'opts
                       (list key (delete-dups (apply 'append (list val) 
        (setq LaTeX-enumitem-key-val-options-local (copy-alist opts))))))
--8<---------------cut here---------------end--------------->8---

Why the (unless (null ...) ...) checks?  That's the same as (when ...)
but doubly negated, no?  And why do you need that anyhow?  The (dolist
...) doesn't need it.

Oh, and I guess the (apply 'append ...) is for flattening the *-list
vars.  Instead, please use the functions of the same name which return
the keys/key-vals in a uniform format so you don't need those hacks.

And please don't use `add-to-list' on local variables.  Instead, use
`pushnew' (with :test #'string= in case its a list of strings), e.g.,

  (pushnew opts (list key (list val)) :test #'string=)

instead of

  (add-to-list 'opts (list key (list val)))

And lastly, in general I prefer the test expression of (if test ...) to
be positively defined, at least when both then and else are just one
single form.  So (if val-match ...) instead (if (null val-match) ...)

Could you please adapt your function above and the rest of the code
accordingly and then submit a complete patch?  I guess we're good to go
then. :-)

>> So could you please validate that it works as expected with
>> multi-file documents?
> A 2 files test-case is attached below and it seems to me that it works.
> One thing occured to me though: When I close the files and re-open
> `master.tex', I get with C-h v:
> LaTeX-enumitem-SetEnumitemValue-list is a variable defined in `enumitem.el'.
> Its value is ((("label" "numeric")) nil)
> Local in buffer master.tex; global value is nil

Hm, I think it's supposed to be there instantly, i.e., without C-c C-n.
But we can sort that out once your style is committed.


reply via email to

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