Function: TeX-auto-parse-region

TeX-auto-parse-region is a byte-compiled function defined in tex.el.

Signature

(TeX-auto-parse-region REGEXP-LIST BEG END)

Documentation

Parse TeX information according to REGEXP-LIST between BEG and END.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-auto-parse-region (regexp-list beg end)
  "Parse TeX information according to REGEXP-LIST between BEG and END."
  (if (symbolp regexp-list)
      (setq regexp-list (and (boundp regexp-list) (symbol-value regexp-list))))
  (if regexp-list
      ;; Extract the information.
      (let* (groups
             (count 1)
             (regexp (concat "\\("
                             (mapconcat
                              (lambda(x)
                                (push (cons count x) groups)
                                (setq count
                                      (+ 1 count
                                         (TeX-regexp-group-count (car x))))
                                (car x))
                              regexp-list "\\)\\|\\(")
                             "\\)"))
             syms
             lst)
        ;; TODO: Emacs allows at most 255 groups in a regexp, see the
        ;; "#define MAX_REGNUM 255" in regex-emacs.c.  If our regex
        ;; has more groups, bad things may happen, e.g.,
        ;; (match-beginning 271) returns nil although the regexp that
        ;; matched contains group number 271.  Sadly, MAX_REGNUM is
        ;; not exposed to Lisp, so we need to hard-code it here (and
        ;; sometimes check if it increased in newer Emacs versions).
        (when (> count 255)
          (error "The TeX auto-parser's regexp has too many groups (%d)" count))
        (setq count 0)
        (goto-char (if end (min end (point-max)) (point-max)))
        (while (re-search-backward regexp beg t)
          (let* ((entry (cdr (TeX-member nil groups
                                         (lambda (_a b)
                                           (match-beginning (car b))))))
                 (symbol (nth 2 entry))
                 (match (nth 1 entry)))
            (unless (TeX-in-comment)
              (looking-at (nth 0 entry))
              (if (fboundp symbol)
                  (funcall symbol match)
                (puthash (if (listp match)
                             (mapcar #'TeX-match-buffer match)
                           (TeX-match-buffer match))
                         (setq count (1- count))
                         (cdr (or (assq symbol syms)
                                  (car (push
                                        (cons symbol
                                              (make-hash-table :test #'equal))
                                        syms)))))))))
        (setq count 0)
        (dolist (symbol syms)
          (setq lst (symbol-value (car symbol)))
          (while lst
            (puthash (pop lst)
                     (setq count (1+ count))
                     (cdr symbol)))
          (maphash (lambda (key value)
                     (push (cons value key) lst))
                   (cdr symbol))
          (clrhash (cdr symbol))
          (set (car symbol) (mapcar #'cdr (sort lst #'car-less-than-car)))))))