auctex-devel
[Top][All Lists]
Advanced

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

[AUCTeX-devel] Management of package options [Was: Re: Add `unit' type f


From: Mosè Giordano
Subject: [AUCTeX-devel] Management of package options [Was: Re: Add `unit' type for the parser in siunitx.el]
Date: Sun, 24 Feb 2013 19:00:02 +0100

Hi all,

as you know, management of LaTeX package options in AUCTeX isn't
really good.  They are treated as style files and until some weeks ago
they were added to `TeX-active-styles' after corresponding style so
that they were inaccessible to style files and quite useless (except
for babel languages).

2013/2/13 Mosè Giordano <address@hidden>:
> My idea (just an idea, no code for now) was to create a variable,
> `LaTeX-<package>-provided-package-options' as you suggested, and write
> it to parsed file using `TeX-auto-store-pre-string'.  Maybe, a proof
> of concept by me can make it clearer.

Now I've written some code.  This is how I would modify
`LaTeX-auto-cleanup' function in latex.el (just a snippet, the rest of
the function is unchanged)
----------------------------------------------------------------------------------
        ;; Next document style.
        (setq LaTeX-auto-style (cdr LaTeX-auto-style))

        ;; Treat documentclass/documentstyle specially.
        (if (or (string-equal "package" class)
                (string-equal "Package" class))
            (dolist (elt (TeX-split-string
                          "\\([ \t\r\n]\\|%[^\n\r]*[\n\r]\\|,\\)+" style))
              ;; If `options' is not an empty string, set a variable called
              ;; `LaTeX-<package>-provided-package-options' equal to the list of
              ;; options provided to the package at load time.
              (unless (zerop (length options))
                (let ((varname (concat "LaTeX-" elt 
"-provided-package-options")))
                  (make-variable-buffer-local (intern varname))
                  (set (intern varname)
                       (LaTeX-listify-package-options options)))
                ;; Append style to the style list.
                (add-to-list 'TeX-auto-file elt t))
              ;; And a special "art10" style file combining style and size.
              (add-to-list 'TeX-auto-file style t)
              (add-to-list 'TeX-auto-file
----------------------------------------------------------------------------------
As explained in the comment, a new (buffer local) variable called
`LaTeX-<package>-provided-package-options' is created when options
string is non empty (otherwise, parsing of packages will stop),
instead of adding options to `TeX-active-style'.  Style files would be
able to run different code depending on the value of options.  This
will also avoid clash between same options for different packages or
between options with the same name of packages.

So far so good.  Actually, there is a problem: how to store this
variables in parsed file?  Here it is my clumsy attempt to solve this
issue.  In tex.el (snippet)
---------------------------------------------------------------------------------
(defvar TeX-auto-store-pre-code nil
  "List of code to be written at the beginning of parsed file.")
(make-variable-buffer-local 'TeX-auto-store-pre-code)

(defun TeX-auto-store (file)
  "Extract information for AUCTeX from current buffer and store it in FILE."
  (TeX-auto-parse)

  (if (member nil (mapcar 'TeX-auto-entry-clear-p TeX-auto-parser))
      (let ((style (TeX-strip-extension nil TeX-all-extensions t))
            (pre-code (mapconcat 'prin1-to-string TeX-auto-store-pre-code 
"\n")))
        (TeX-unload-style style)
        (save-excursion
          (set-buffer (generate-new-buffer file))
          (erase-buffer)
          (unless (zerop (length pre-code))
            (insert pre-code "\n\n"))
          (insert "(TeX-add-style-hook\n \""
                  style "\"\n (lambda ()")
---------------------------------------------------------------------------------
It's similar to my previous suggestion, the only difference is that
`TeX-auto-store-pre-code' is a list of code (sorry, can't explain
better) instead of strings.  It's converted to string writable to file
using `prin1-to-string' function.  Lines like
------------------------------------------------------------------------
  (make-variable-buffer-local 'LaTeX-<package>-provided-package-options)
  (setq LaTeX-<package>-provided-package-options (quote (<options>)))
------------------------------------------------------------------------
should be written at the beginning of parsed file,
`LaTeX-auto-cleanup' function can be modified in the following way to
do this:
-------------------------------------------------------------------------------
        ;; Next document style.
        (setq LaTeX-auto-style (cdr LaTeX-auto-style))

        ;; Treat documentclass/documentstyle specially.
        (if (or (string-equal "package" class)
                (string-equal "Package" class))
            (dolist (elt (TeX-split-string
                          "\\([ \t\r\n]\\|%[^\n\r]*[\n\r]\\|,\\)+" style))
              ;; If `options' is not an empty string, set a variable called
              ;; `LaTeX-<package>-provided-package-options' equal to the list of
              ;; options provided to the package at load time.
              (unless (zerop (length options))
                (let ((varname (concat "LaTeX-" elt 
"-provided-package-options")))
                  (make-variable-buffer-local (intern varname))
                  (set (intern varname)
                       (LaTeX-listify-package-options options))
                  ;; Add setq'ing of `LaTeX-<package>-provided-package-options'
                  ;; to `TeX-auto-store-pre-code' in order to store it in parsed
                  ;; file.
                  (add-to-list 'TeX-auto-store-pre-code
                               `(make-variable-buffer-local ',(intern varname)) 
t)
                  (add-to-list 'TeX-auto-store-pre-code
                               `(setq ,(intern varname)
                                      ',(symbol-value (intern varname)))
                               t)))
              ;; Append style to the style list.
              (add-to-list 'TeX-auto-file elt t))
          ;; And a special "art10" style file combining style and size.
          (add-to-list 'TeX-auto-file style t)
          (add-to-list 'TeX-auto-file
-------------------------------------------------------------------------------
I know it's not the cleanest way to fix the issue, it's at least an
idea which can be improved.  For instance, to make parsed file more
readable, a function called something `LaTeX-add-package-options' can
be defined which takes as argument the name of the package and the
list of options and which makes
`LaTeX-<package>-provided-package-options' buffer local and sets
`LaTeX-<package>-provided-package-options' equal to the list of
options:
--------------------------------------------------
  (defun LaTeX-add-package-options package options
    (make-variable-buffer-local LaTeX-<package>-provided-package-options)
    (setq LaTeX-<package>-provided-package-options '(<options>)))
--------------------------------------------------

Any comments?

Bye,
Mosè Giordano



reply via email to

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