Loading or saving a large file with a few thousand \index entries
takes up about 10 minutes here, which is quite intolerable. Things
get quite more acceptable with the following:
--- tex.el 05 Jun 2005 19:07:23 +0200 5.524
+++ tex.el 07 Jun 2005 04:51:13 +0200
@@ -2669,28 +2669,72 @@
:group 'TeX-parse)
(make-variable-buffer-local 'TeX-auto-x-regexp-list)
+(defun TeX-regexp-group-count (regexp)
+ "Return number of groups in a regexp. This assumes the following
+heuristic: Any occurrence of the pattern `\\\\([^?]' is an opening group,
+so if you want to have something like `\\\\\\\\(', write it as `\\\\\\\\[(]'."
+ (let (start (n 0))
+ (while (string-match "\\\\([^?]" regexp start)
+ (setq start (1- (match-end 0))
+ n (1+ n)))
+ n))
+
(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 ((regexp (concat "\\("
- (mapconcat 'car regexp-list "\\)\\|\\(")
- "\\)")))
+ (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 "\\)\\|\\(")
+ "\\)"))
+ (hash (make-hash-table :test 'equal))
+ syms
+ lst)
+ (setq count 0)
(goto-char (if end (min end (point-max)) (point-max)))
(while (re-search-backward regexp beg t)
- (unless (TeX-in-comment)
- (let* ((entry (TeX-member nil regexp-list
- (lambda (a b)
- (looking-at (nth 0 b)))))
- (symbol (nth 2 entry))
- (match (nth 1 entry)))
+ (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)
- (add-to-list symbol (if (listp match)
- (mapcar 'TeX-match-buffer match)
- (TeX-match-buffer match))))))))))
+ (add-to-list 'syms symbol)
+ (puthash (cons symbol (if (listp match)
+ (mapcar 'TeX-match-buffer match)
+ (TeX-match-buffer match)))
+ (setq count (1- count))
+ hash)))))
+ (setq count 0)
+ (dolist (symbol syms)
+ (setq lst (symbol-value symbol))
+ (set symbol nil)
+ (while lst
+ (puthash (cons symbol
+ (pop lst))
+ (setq count (1+ count))
+ hash)))
+ (maphash #'(lambda (key value)
+ (set (car key) (cons (cons value (cdr key))
+ (symbol-value (car key)))))
+ hash)
+ (clrhash hash)
+ (dolist (symbol syms)
+ (set symbol (mapcar #'cdr (sort (symbol-value symbol)
+ #'car-less-than-car)))))))
(defun TeX-auto-parse ()
"Parse TeX information in current buffer.
The question is whether I am going actually overboard here with trying
to keep the order of the lists more or less in-sequence like it was
previously the case.
Does anybody have enough of a clue to tell whether the order is
important here? If not, one can leave off the sequencing stuff using
`count', maybe making this more efficient.
The best thing would probably be to just have all of those variables
be hash tables in the first place. If order is not an issue.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
_______________________________________________
auctex-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex-devel