comparison src/elisp/urweb-mode.el @ 367:28d3d7210687

Improving indentation of XML after antiquote
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Oct 2008 13:30:40 -0400
parents 3004f8843e36
children b6be16792584
comparison
equal deleted inserted replaced
366:3004f8843e36 367:28d3d7210687
476 (if (not (save-excursion (backward-char 2) (looking-at "/"))) 476 (if (not (save-excursion (backward-char 2) (looking-at "/")))
477 (incf depth)) 477 (incf depth))
478 (setq done t)))) 478 (setq done t))))
479 (and (not done) (> depth 0))))) 479 (and (not done) (> depth 0)))))
480 480
481 (defun skip-matching-braces ()
482 "Skip backwards past matching brace pairs, to calculate XML indentation after quoted Ur code"
483 (beginning-of-line)
484 (let ((start-pos (point))
485 (depth 0))
486 (end-of-line)
487 (while (re-search-backward "[{}]" start-pos t)
488 (cond
489 ((looking-at "}")
490 (incf depth))
491 ((looking-at "{")
492 (decf depth))))
493 (while (and (> depth 0) (re-search-backward "[{}]" nil t)
494 (cond
495 ((looking-at "}")
496 (incf depth))
497 ((looking-at "{")
498 (decf depth)))))))
499
481 (defun urweb-tag-matching-indent () 500 (defun urweb-tag-matching-indent ()
482 "Seek back to a matching opener tag and get its line's indent" 501 "Seek back to a matching opener tag and get its line's indent"
483 (save-excursion 502 (save-excursion
484 (let ((depth 0) 503 (let ((depth 0)
485 (done nil)) 504 (done nil))
518 (and (looking-at "\\*") (urweb-find-comment-indent)) 537 (and (looking-at "\\*") (urweb-find-comment-indent))
519 538
520 (and (urweb-in-xml) 539 (and (urweb-in-xml)
521 (let ((prev-indent (save-excursion 540 (let ((prev-indent (save-excursion
522 (previous-line 1) 541 (previous-line 1)
523 (end-of-line 1) 542 (skip-matching-braces)
524 (re-search-backward "^[^\n]" nil t) 543 (re-search-backward "^[^\n]" nil t)
525 (current-indentation)))) 544 (current-indentation))))
526 (cond 545 (cond
527 ((looking-at "</") 546 ((looking-at "</")
528 (urweb-tag-matching-indent)) 547 (urweb-tag-matching-indent))