From 0608a7abedf738215560865e43d50909c1652c18 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 16 Oct 2008 13:30:40 -0400 Subject: Improving indentation of XML after antiquote --- src/elisp/urweb-mode.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/elisp/urweb-mode.el') diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index c8186182..308bd1af 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -478,6 +478,25 @@ If anyone has a good algorithm for this..." (setq done t)))) (and (not done) (> depth 0))))) +(defun skip-matching-braces () + "Skip backwards past matching brace pairs, to calculate XML indentation after quoted Ur code" + (beginning-of-line) + (let ((start-pos (point)) + (depth 0)) + (end-of-line) + (while (re-search-backward "[{}]" start-pos t) + (cond + ((looking-at "}") + (incf depth)) + ((looking-at "{") + (decf depth)))) + (while (and (> depth 0) (re-search-backward "[{}]" nil t) + (cond + ((looking-at "}") + (incf depth)) + ((looking-at "{") + (decf depth))))))) + (defun urweb-tag-matching-indent () "Seek back to a matching opener tag and get its line's indent" (save-excursion @@ -520,7 +539,7 @@ If anyone has a good algorithm for this..." (and (urweb-in-xml) (let ((prev-indent (save-excursion (previous-line 1) - (end-of-line 1) + (skip-matching-braces) (re-search-backward "^[^\n]" nil t) (current-indentation)))) (cond -- cgit v1.2.3