diff options
author | Russ Allbery <rra@debian.org> | 2008-05-09 15:09:47 -0700 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-05-12 16:48:30 -0500 |
commit | 954aad4faa33ff9c4504eb5673c7dd122a914d4a (patch) | |
tree | 9311ba455c968bfa419ea5062fbb55ca6fb713ef | |
parent | f52e3433da9001f85722f9efcb90208e4bb2fd2b (diff) | |
download | puppet-954aad4faa33ff9c4504eb5673c7dd122a914d4a.tar.gz puppet-954aad4faa33ff9c4504eb5673c7dd122a914d4a.tar.xz puppet-954aad4faa33ff9c4504eb5673c7dd122a914d4a.zip |
Fix Emacs mode indentation of multiple nested blocks
Indentation of multiple nested blocks was broken; the closing braces
of all the outer blocks were put into column 0 because finding the
block indentation failed. Do normal indentation if finding a block
indentation fails, but more importantly, be smarter about searching
backwards to find the beginning of the current block, taking balanced
braces into account.
There is probably some less-ugly and more Emacs-native way of doing
this.
-rw-r--r-- | ext/emacs/puppet-mode.el | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/emacs/puppet-mode.el b/ext/emacs/puppet-mode.el index a6d47eea1..f3f4589aa 100644 --- a/ext/emacs/puppet-mode.el +++ b/ext/emacs/puppet-mode.el @@ -84,7 +84,14 @@ of the closing brace of a block." (when apoint ;; This is a bit of a hack and doesn't allow for strings. We really ;; want to parse by sexps at some point. - (if (= (puppet-count-matches "}" apoint opoint) 0) + (let ((close-braces (puppet-count-matches "}" apoint opoint)) + (open-braces 0)) + (while (and apoint (> close-braces open-braces)) + (setq apoint (search-backward "{" nil t)) + (when apoint + (setq close-braces (puppet-count-matches "}" apoint opoint)) + (setq open-braces (1+ open-braces))))) + (if apoint (current-indentation) nil)))))) @@ -172,12 +179,11 @@ of the initial include plus puppet-include-indent." (setq cur-indent (current-column)))) (include-start (setq cur-indent include-start)) - ((looking-at "^\\s-*}\\s-*$") - ;; This line contains only a closing brace, so we should indent it - ;; matching the indentation of the opening brace of the block. - (if block-indent - (setq cur-indent block-indent) - (setq cur-indent 0))) + ((and (looking-at "^\\s-*}\\s-*$") block-indent) + ;; This line contains only a closing brace and we're at the inner + ;; block, so we should indent it matching the indentation of the + ;; opening brace of the block. + (setq cur-indent block-indent)) (t ;; Otherwise, we did not start on a block-ending-only line. (save-excursion |