[Top][All Lists]

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

Re: [AUCTeX-devel] Add `unit' type for the parser in siunitx.el

From: Mosè Giordano
Subject: Re: [AUCTeX-devel] Add `unit' type for the parser in siunitx.el
Date: Sun, 10 Feb 2013 12:42:46 +0100

It seems I didn't tested my patch in enough situations.  Consider the
following (`TeX-auto-save' `TeX-parse-self' are set to non-nil, of
1) You open a LaTeX source in which is loaded `siunitx' package and
some new units are defined with `\DeclareSIUnit' macro.
2) After some changes, you save the source.  AUCTeX parses the buffer
and writes to parsed file all gathered information, in particular it
will add `siunitx' hook and write `(LaTeX-add-siunitx-units <new
3) For some reason, you decide you don't need `siunitx' package
anymore in your source and you remove it.  Then you save the buffer.
AUCTeX re-parses the buffer and writes the parsed file, but with
`(LaTeX-add-siunitx-units <new units>)' and without `siunitx' hook.
4) You close Emacs.
5) You reopen the LaTeX source.  AUCTeX finds the the parsed file and
evaluate it, when it finds `LaTeX-add-siunitx-units' function it don't
know what it is (`siunitx' hook has not been run) and returns error
    Symbol's function definition is void: LaTeX-add-siunitx-units

I suggest the following solution: create a variable containing strings
of code to be written at the beginning of parsed file.  In
`siunitx.el' I can add the string
    (TeX-auto-add-type "siunitx-unit" "LaTeX")
to this variable, so at step 5 of the above situation AUCTeX won't
complain about the unknown `LaTeX-add-siunitx-units' function.  When
you save the buffer after step 5, the string
    (TeX-auto-add-type "siunitx-unit" "LaTeX")
and `(LaTeX-add-siunitx-units <new units>)' won't be written to parsed
file and AUCTeX can forget forever about `siunitx-unit' type.

I'm sending a patch for `tex.el' implementing this, and the complete
patch for `siunitx.el'.  I remind you that the patch for `siunitx.el'
requires the patches for `tex.el' and `latex.el' I already sent to the
list.  Here is the full ChangeLog

2013-02-10  Mosè Giordano  <address@hidden>

        * tex.el (TeX-auto-store-pre-string): New variable.
        (TeX-auto-store): Use it.

        * style/siunitx.el ("siunitx-unit"): New type for the parser.
        (TeX-auto-store-pre-string): Add definition of `siunitx-unit' type.
        (LaTeX-siunitx-regexp): New variable.
        (LaTeX-auto-siunitx-unit): New variable.
        (LaTeX-siunitx-prepare): New function.
        (LaTeX-siunitx-cleanup): New function.
        (TeX-auto-prepare-hook): Add `LaTeX-siunitx-prepare' function.
        (TeX-auto-cleanup-hook): Add `LaTeX-siunitx-cleanup' function.
        (TeX-arg-siunitx-unit): New function.
        (TeX-arg-define-siunitx-unit): New function.
        ("siunitx"): Add `LaTeX-siunitx-regexp' to list of regexps used for
        ("siunitx"): Use `TeX-arg-siunitx-unit' and
        `TeX-arg-define-siunitx-unit' functions.
        ("siunitx"): Use `LaTeX-add-siunitx-units' for adding siunitx unit
        macros to the list of known units.

Sorry for the mess,
Mosè Giordano

Attachment: tex.el.patch
Description: Binary data

Attachment: siunitx.el.patch
Description: Binary data

reply via email to

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