From: Adam Chlipala Date: Sun, 11 Nov 2007 16:23:48 +0000 (+0000) Subject: Proper nested indentation X-Git-Tag: release_2010-11-19~161 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/1cbe917465857acd366e4058d1f71c5653720b17 Proper nested indentation --- diff --git a/elisp/domtool-mode.el b/elisp/domtool-mode.el index 3f8d193..a35a895 100644 --- a/elisp/domtool-mode.el +++ b/elisp/domtool-mode.el @@ -110,12 +110,26 @@ (savep (save-excursion (indent-line-to indent))) (t (indent-line-to indent))))) +(defun until-closed (level) + (if + (re-search-backward "\\_<\\(with\\|where\\|begin\\|end\\)\\_>" + nil t) + (cond + ((string= (match-string 0) "end") + (until-closed (+ level 1))) + ((= level 0) + (current-indentation)) + (t + (until-closed (- level 1)))) + + nil)) + (defun domtool-calculate-indent () (save-excursion (back-to-indentation) (multiple-value-bind (previous-keyword base-indent) (save-excursion - (if (re-search-backward "\\_<\\(with\\|where\\|end\\)\\_>" + (if (re-search-backward "\\_<\\(with\\|where\\|begin\\|end\\)\\_>" nil t) (values (match-string 0) (current-indentation)) (values nil 0))) @@ -125,11 +139,8 @@ 'noindent) ((nth 4 state) (domtool-calculate-comment-indent state)) - ((and (looking-at "\\_") - (string= previous-keyword "end")) - (- base-indent domtool-indent)) ((looking-at "\\_<\\(with\\|end\\)\\_>") - base-indent) + (until-closed 0)) ((not previous-keyword) base-indent) ((string= previous-keyword "end")