Function: LaTeX-xparse-macro-parse

LaTeX-xparse-macro-parse is a byte-compiled function defined in latex.el.

Signature

(LaTeX-xparse-macro-parse TYPE)

Documentation

Process parsed macro and environment definitions.

TYPE is one of the symbols mac or env.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-xparse-macro-parse (type)
  "Process parsed macro and environment definitions.
TYPE is one of the symbols mac or env."
  (dolist (xcmd (if (eq type 'mac)
                    LaTeX-auto-xparse-macro
                  LaTeX-auto-xparse-environment))
    (let ((name (string-trim (nth 1 xcmd) "[ \t\r\n%]+" "[ \t\r\n%]+"))
          (spec (nth 2 xcmd))
          (what (nth 3 xcmd))
          (case-fold-search nil)
          (syntax (TeX-search-syntax-table ?\{ ?\}))
          args opt-star opt-token)
      (with-temp-buffer
        (set-syntax-table LaTeX-mode-syntax-table)
        (insert (replace-regexp-in-string "[ \t\r\n%]" "" spec))
        (goto-char (point-min))
        (while (looking-at-p "[+!>=bcmrRvodODsteE]")
          (cond ((looking-at-p "[+!bc]")
                 ;; + or !: Long argument or space aware: Move over
                 ;; them.  b is special; only available for
                 ;; enviroments as well as c.
                 (forward-char 1))
                ;; Argument processors and key-val modifier: Move
                ;; over [>=] and a balanced {}
                ((looking-at-p "[>=]")
                 (forward-char 1)
                 (with-syntax-table syntax (forward-sexp)))
                ;; Mandatory arguments:
                ;; m: Ask for input with "Text" as prompt
                ((looking-at-p "m")
                 (forward-char 1)
                 (push "Text" args))
                ;; r<token1><token2>
                ((looking-at-p "r")
                 (re-search-forward "r\\(.\\)\\(.\\)" (+ (point) 3) t)
                 (push `(TeX-arg-string nil nil nil nil
                                        ,(match-string-no-properties 1)
                                        ,(match-string-no-properties 2))
                       args))
                ;; R<token1><token2>{default}
                ((looking-at-p "R")
                 (re-search-forward "R\\(.\\)\\(.\\)" (+ (point) 3) t)
                 (with-syntax-table syntax (forward-sexp))
                 (push `(TeX-arg-string nil nil nil nil
                                        ,(match-string-no-properties 1)
                                        ,(match-string-no-properties 2))
                       args))
                ;; v: Use `TeX-arg-verb-delim-or-brace'
                ((looking-at-p "v")
                 (forward-char 1)
                 (push #'TeX-arg-verb-delim-or-brace args))
                ;; Optional arguments:
                ;; o standard LaTeX optional in square brackets
                ((looking-at-p "o")
                 (forward-char 1)
                 (push (vector "Text") args))
                ;; d<token1><token2>
                ((looking-at-p "d")
                 (re-search-forward "d\\(.\\)\\(.\\)" (+ (point) 3) t)
                 (push (vector #'TeX-arg-string nil nil nil nil
                               (match-string-no-properties 1)
                               (match-string-no-properties 2))
                       args))
                ;; O{default}
                ((looking-at-p "O")
                 (forward-char 1)
                 (with-syntax-table syntax (forward-sexp))
                 (push (vector "Text") args))
                ;; D<token1><token2>{default}
                ((looking-at-p "D")
                 (re-search-forward "D\\(.\\)\\(.\\)" (+ (point) 3) t)
                 (with-syntax-table syntax (forward-sexp))
                 (push (vector #'TeX-arg-string nil nil nil nil
                               (match-string-no-properties 1)
                               (match-string-no-properties 2))
                       args))
                ;; s: optional star
                ((looking-at-p "s")
                 (forward-char 1)
                 (setq opt-star t))
                ;; t: optional <token>
                ((looking-at-p "t")
                 (re-search-forward "t\\(.\\)" (+ (point) 2) t)
                 (setq opt-token (match-string-no-properties 1)))
                ;; e{tokes} a set of optional embellishments
                ((looking-at-p "e")
                 (forward-char)
                 (if (looking-at-p TeX-grop)
                     (re-search-forward "{\\([^}]+\\)}" nil t)
                   (re-search-forward "\\(.\\)" (1+ (point)) t))
                 (push `(LaTeX-arg-xparse-embellishment
                         ,(match-string-no-properties 1))
                       args))
                ;; E{tokes}{defaults}
                ((looking-at-p "E")
                 (forward-char)
                 (if (looking-at-p TeX-grop)
                     (re-search-forward "{\\([^}]+\\)}" nil t)
                   (re-search-forward "\\(.\\)" (1+ (point)) t))
                 (push `(LaTeX-arg-xparse-embellishment
                         ,(match-string-no-properties 1))
                       args)
                 (when (looking-at-p TeX-grop)
                   (with-syntax-table syntax (forward-sexp))))
                ;; Finished:
                (t nil))))
      (if (eq type 'env)
          ;; Parsed enviroments: If we are Renew'ing or Delare'ing, we
          ;; delete the enviroment first from `LaTeX-auto-environment'
          ;; before adding the new one:
          (progn
            (when (member what '("Renew" "Declare"))
              (setq LaTeX-auto-environment
                    (assq-delete-all (car (assoc name LaTeX-auto-environment))
                                     LaTeX-auto-environment)))
            (add-to-list 'LaTeX-auto-environment
                         (if args
                             `(,name LaTeX-env-args ,@(reverse args))
                           (list name))))
        ;; Parsed macros: If we are Renew'ing or Delare'ing, we delete
        ;; the macros first from `TeX-auto-symbol' before adding the new
        ;; ones:
        (when (member what '("Renew" "Declare"))
          (setq TeX-auto-symbol
                (assq-delete-all (car (assoc name TeX-auto-symbol))
                                 TeX-auto-symbol))
          (when opt-star
            (setq TeX-auto-symbol
                  (assq-delete-all (car (assoc (concat name "*")
                                               TeX-auto-symbol))
                                   TeX-auto-symbol)))
          (when opt-token
            (setq TeX-auto-symbol
                  (assq-delete-all (car (assoc (concat name opt-token)
                                               TeX-auto-symbol))
                                   TeX-auto-symbol))))
        (add-to-list 'TeX-auto-symbol (cons name (reverse args)))
        (when opt-star
          (add-to-list 'TeX-auto-symbol (cons (concat name "*")
                                              (reverse args))))
        (when opt-token
          (add-to-list 'TeX-auto-symbol (cons (concat name opt-token)
                                              (reverse args))))))))