# HG changeset patch # User Adam Chlipala # Date 1423678379 18000 # Node ID 3dc020fb2aa1e1a669d8edb83ec86b3a3e0ce797 # Parent dca8d91b4170318faca7955447ef79943be3733c An Emacs urweb-mode optimization contributed by John Wiegley diff -r dca8d91b4170 -r 3dc020fb2aa1 src/elisp/urweb-mode.el --- a/src/elisp/urweb-mode.el Tue Feb 10 09:58:35 2015 -0500 +++ b/src/elisp/urweb-mode.el Wed Feb 11 13:12:59 2015 -0500 @@ -171,42 +171,47 @@ (depth 0) (finished nil) (answer nil) + (bound (max 0 (- (point) 1024))) ) - (while (and (not finished) (re-search-backward "[-<{}]" nil t)) - (cond - ((looking-at "{") - (if (> depth 0) - (decf depth) - (setq finished t))) - ((looking-at "}") - (incf depth)) - ((looking-at "") - (if (> depth 0) - (decf depth) - (progn - (setq answer t) - (setq finished t)))) - ((looking-at "") - (incf depth)) + (while (and (not finished) + (re-search-backward "\\(\\([-{}]\\)\\|<\\(/?xml\\)?\\)" + bound t)) + (let ((xml-tag (length (or (match-string 3) ""))) + (ch (match-string 2))) + (cond + ((equal ch ?\{) + (if (> depth 0) + (decf depth) + (setq finished t))) + ((equal ch ?\}) + (incf depth)) + ((= xml-tag 3) + (if (> depth 0) + (decf depth) + (progn + (setq answer t) + (setq finished t)))) + ((= xml-tag 4) + (incf depth)) - ((looking-at "-") - (if (looking-at "->") - (setq finished (= depth 0)))) + ((equal ch ?-) + (if (looking-at "->") + (setq finished (= depth 0)))) - ((and (= depth 0) - (not (looking-at " - (eq font-lock-tag-face - (get-text-property (point) 'face))) - ;; previous code was highlighted as tag, seems we are in xml - (progn - (setq answer t) - (setq finished t))) + ((and (= depth 0) + (not (looking-at " + (eq font-lock-tag-face + (get-text-property (point) 'face))) + ;; previous code was highlighted as tag, seems we are in xml + (progn + (setq answer t) + (setq finished t))) - ((= depth 0) - ;; previous thing was a tag like, but not tag - ;; seems we are in usual code or comment - (setq finished t)) - )) + ((= depth 0) + ;; previous thing was a tag like, but not tag + ;; seems we are in usual code or comment + (setq finished t)) + ))) answer))) (defun amAttribute (face)