auctex-devel
[Top][All Lists]
Advanced

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

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


From: Arash Esbati
Subject: [AUCTeX-devel] Adding key/vals to predefined ones
Date: Sat, 07 Feb 2015 21:08:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4

Hi,

some packages like enumitem.sty oder caption.sty (something I'd like to
see supported by AUCTeX BTW) have the infastructure to define new
key/vals by user in addition to the predefined ones.  E.g., enumitem.sty
offers `\SetEnumitemKey' and `\SetEnumitemValue' for this purpose
(cf. section 9 Generic keys and values of the documentation).

Is there any blueprint how this can be implemented on AUCTeX side?  The
following excerpt for an `enumitem.el' works for commands mentioned
above, but I have still no clear idea about how to build a bridge
between AUCTeX auto-parser and key-vals defined when a file is loaded,
i.e. how to add items from `LaTeX-enumitem-SetEnumitem*-list' to
`LaTeX-enumitem-key-val-options'.

--8<---------------cut here---------------start------------->8---
;; Example for predefined key/vals
(defvar LaTeX-enumitem-key-val-options
  '(("align" ("left" "right" "parleft"))
    ("style" ("standard" "multiline" "nextline" "sameline" "unboxed"))
    ("mode" ("boxed" "unboxed")))
  "Key=value options for enumitem macros and environments.")

;; Standard auto-parsing procedure
(defun LaTeX-enumitem-auto-cleanup ()
  "Move parsing results into right places for further usage."
  ;; \SetEnumitemKey{<key>}{<replacement>}
  (dolist (key LaTeX-auto-enumitem-SetEnumitemKey)
    (add-to-list 'LaTeX-enumitem-SetEnumitemKey-list
                 (list key)))
  ;; \SetEnumitemValue{<key>}{<val>}{<replacement>}
  (dolist (key-val LaTeX-auto-enumitem-SetEnumitemValue)
    (let* ((key (car key-val))
           (val (cdr key-val)))
      (list key val))))

;; Functions to be called
(defun LaTeX-arg-SetEnumitemKey (optional &optional prompt)
  "Ask for a new key to be defined and add it to
`LaTeX-enumitem-key-val-options'."
  (let ((key     (read-string "New Key: "))
        (replace (TeX-read-key-val optional
                                   LaTeX-enumitem-key-val-options 
"Replacement")))
    (TeX-argument-insert key     optional)
    (TeX-argument-insert replace optional)
    (add-to-list 'LaTeX-enumitem-key-val-options (list key))
    (LaTeX-add-enumitem-SetEnumitemKeys key)))

(defun LaTeX-arg-SetEnumitemValue (optional &optional prompt)
  "Ask for a new value added to an existing key incl. the final
replacement of value."
  (let* ((key (TeX-read-key-val optional LaTeX-enumitem-key-val-options "Key"))
         (val (read-string "String value: "))
         (key-match (car (assoc key LaTeX-enumitem-key-val-options)))
         (val-match (cdr (assoc key LaTeX-enumitem-key-val-options))))
    (setq LaTeX-enumitem-key-val-options
          (assq-delete-all (car (assoc key LaTeX-enumitem-key-val-options))
                           LaTeX-enumitem-key-val-options))
    (if (null val-match)
        (add-to-list 'LaTeX-enumitem-key-val-options (list key (list val)))
      (add-to-list 'LaTeX-enumitem-key-val-options
                   (list key (delete-dups (cons val val-match)))))
    (TeX-argument-insert key optional)
    (TeX-argument-insert val optional)))

(TeX-add-style-hook
 "enumitem"
 (lambda ()

    ;; "Key" will be added to key-val list.
    '("SetEnumitemKey" LaTeX-arg-SetEnumitemKey)

    ;; "Key" and "Value" are added to the key-val list
    '("SetEnumitemValue" LaTeX-arg-SetEnumitemValue "Replacement"))
--8<---------------cut here---------------end--------------->8---

Best, Arash



reply via email to

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