# HG changeset patch # User Stefan Monnier # Date 1145275540 0 # Node ID 80049d479c75faa365073465fb3e98b5f14f905c # Parent 97f9c95377f459d0afc85930d0dbc813d203c455 (tex-font-lock-match-suscript): New function. (tex-font-lock-keywords-3): Use it. diff -r 97f9c95377f4 -r 80049d479c75 lisp/ChangeLog --- a/lisp/ChangeLog Mon Apr 17 09:10:40 2006 +0000 +++ b/lisp/ChangeLog Mon Apr 17 12:05:40 2006 +0000 @@ -1,3 +1,8 @@ +2006-04-17 Ralf Angeli + + * textmodes/tex-mode.el (tex-font-lock-match-suscript): New function. + (tex-font-lock-keywords-3): Use it. + 2006-04-16 Stefan Monnier * newcomment.el (comment-add): New function. diff -r 97f9c95377f4 -r 80049d479c75 lisp/textmodes/tex-mode.el --- a/lisp/textmodes/tex-mode.el Mon Apr 17 09:10:40 2006 +0000 +++ b/lisp/textmodes/tex-mode.el Mon Apr 17 12:05:40 2006 +0000 @@ -594,20 +594,24 @@ '(face subscript display (raise -0.3)) '(face superscript display (raise +0.3))))) +(defun tex-font-lock-match-suscript (limit) + "Match subscript and superscript patterns up to LIMIT." + (when (re-search-forward "[_^] *\\([^\n\\{}]\\|\ +\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|{[^\\{]*}\\|\\({\\)\\)" limit t) + (when (match-end 3) + (let ((beg (match-beginning 3)) + (end (save-restriction + (narrow-to-region (point-min) limit) + (condition-case nil (scan-lists (point) 1 1) (error nil))))) + (store-match-data (if end + (list (match-beginning 0) end beg end)) + (list beg beg beg beg)))) + t)) + (defconst tex-font-lock-keywords-3 (append tex-font-lock-keywords-2 - (eval-when-compile - (let ((general "\\([a-zA-Z@]+\\|[^ \t\n]\\)") - (slash "\\\\") - ;; This is not the same regexp as before: it has a `+' removed. - ;; The + makes the matching faster in the above cases (where we can - ;; exit as soon as the match fails) but would make this matching - ;; degenerate to nasty complexity (because we try to match the - ;; closing brace, which forces trying all matching combinations). - (arg "{\\(?:[^{}\\]\\|\\\\.\\|{[^}]*}\\)*")) - `((,(concat "[_^] *\\([^\n\\{}#]\\|" slash general "\\|#[0-9]\\|" arg "}\\)") - (1 (tex-font-lock-suscript (match-beginning 0)) - append)))))) + '((tex-font-lock-match-suscript + (1 (tex-font-lock-suscript (match-beginning 0)) append)))) "Experimental expressions to highlight in TeX modes.") (defvar tex-font-lock-keywords tex-font-lock-keywords-1