From db08876a6942aea26ef0d798a0951fc559e2c624 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 11 Feb 2015 13:12:59 -0500 Subject: An Emacs urweb-mode optimization contributed by John Wiegley --- src/elisp/urweb-mode.el | 75 ++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index edbff1b0..fb9d18b5 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -171,42 +171,47 @@ See doc for the variable `urweb-mode-info'." (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)) - - ((looking-at "-") - (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))) - - ((= depth 0) - ;; previous thing was a tag like, but not tag - ;; seems we are in usual code or comment - (setq finished t)) - )) + (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)) + + ((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))) + + ((= 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) -- cgit v1.2.3