 ;;; Font-lock settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; The font lock regular expressions.
+
+(defun inXml (depth)
+  (and
+   (re-search-backward "[<>{}]" nil t)
+   (cond
+    ((looking-at "{")
+     (and (> depth 0)
+          (inXml (- depth 1))))
+    ((looking-at "}")
+     (inXml (+ depth 1)))
+    ((save-excursion (backward-char 1) (or (looking-at "=>") (looking-at "->")))
+     (inXml depth))
+    ((looking-at "<")
+     nil)
+    ((looking-at ">")
+     (if (> depth 0)
+         (and (re-search-backward "<" nil t)
+              (inXml depth))
+       (progn (backward-char 5) (not (looking-at "/html"))))))))
 
 (defconst urweb-font-lock-keywords
   `(;;(urweb-font-comments-and-strings)

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.s\\(ml\\|ig\\)\\'" . urweb-mode))

;;;###autoload
(define-derived-mode urweb-mode fundamental-mode "Ur/Web"
  "\\<urweb-mode-map>Major mode for editing Ur/Web code.
This mode runs `urweb-mode-hook' just before exiting.
\\{urweb-mode-map}"
  (set (make-local-variable 'font-lock-defaults) urweb-font-lock-defaults)
  (set (make-local-variable 'outline-regexp) urweb-outline-regexp)
  (set (make-local-variable 'imenu-create-index-function)
       'urweb-imenu-create-index)

;; Still under construction: History obscure, needs a biographer as
;; well as a M-x doctor. Change Log on request.

;; Hacked by Olin Shivers for comint from Lars Bo Nielsen's sml.el.

;; Hacked by Matthew Morley to incorporate Fritz Knabe's hilite and
;; font-lock patterns, some of Steven Gilmore's (reduced) easy-menus,
