From 1cbe917465857acd366e4058d1f71c5653720b17 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 11 Nov 2007 16:23:48 +0000 Subject: [PATCH] Proper nested indentation --- elisp/domtool-mode.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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") -- 2.20.1