comparison src/elisp/urweb-mode.el @ 365:dda8f3c6ae7c

Special case indenting for <xml>...</xml>
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Oct 2008 13:01:24 -0400
parents 7c58dc323683
children 3004f8843e36
comparison
equal deleted inserted replaced
364:7c58dc323683 365:dda8f3c6ae7c
450 (setq depth -1))) 450 (setq depth -1)))
451 (if (= depth 0) 451 (if (= depth 0)
452 (1+ (current-column)) 452 (1+ (current-column))
453 nil)))) 453 nil))))
454 454
455 (defun urweb-begun-xml ()
456 "Check if this is the first new line in a new <xml>...</xml> section"
457 (save-excursion
458 (let ((start-pos (point)))
459 (previous-line 1)
460 (search-forward "<xml>" start-pos t))))
461
455 (defun urweb-new-tags () 462 (defun urweb-new-tags ()
456 "Decide if the previous line of XML introduced unclosed tags" 463 "Decide if the previous line of XML introduced unclosed tags"
457 (save-excursion 464 (save-excursion
458 (let ((start-pos (point)) 465 (let ((start-pos (point))
459 (depth 0) 466 (depth 0)
485 (incf depth) 492 (incf depth)
486 (if (= depth 0) 493 (if (= depth 0)
487 (setq done t) 494 (setq done t)
488 (decf depth))) 495 (decf depth)))
489 (setq done t)))) 496 (setq done t))))
490 (current-indentation)))) 497 (if (looking-at "<xml")
498 (+ (current-indentation) 2)
499 (current-indentation)))))
491 500
492 (defun urweb-calculate-indentation () 501 (defun urweb-calculate-indentation ()
493 (save-excursion 502 (save-excursion
494 (beginning-of-line) (skip-chars-forward "\t ") 503 (beginning-of-line) (skip-chars-forward "\t ")
495 (urweb-with-ist 504 (urweb-with-ist
515 (re-search-backward "^[^\n]" nil t) 524 (re-search-backward "^[^\n]" nil t)
516 (current-indentation)))) 525 (current-indentation))))
517 (cond 526 (cond
518 ((looking-at "</") 527 ((looking-at "</")
519 (urweb-tag-matching-indent)) 528 (urweb-tag-matching-indent))
529 ((urweb-begun-xml)
530 (+ prev-indent 4))
520 ((urweb-new-tags) 531 ((urweb-new-tags)
521 (+ prev-indent 2)) 532 (+ prev-indent 2))
522 (t 533 (t
523 prev-indent)))) 534 prev-indent))))
524 535