Skip to content

Commit

Permalink
Fix indentation after comments ending with a colon
Browse files Browse the repository at this point in the history
  • Loading branch information
Pär Lindfors authored and bbatsov committed Mar 15, 2017
1 parent 8e5c8b6 commit d7f25ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion puppet-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,12 @@ of the initial include plus puppet-include-indent."
(setq not-indented nil))

;; Indent an extra level after : since it introduces a resource.
;; Unless the : is in a comment
((looking-at "^.*:\\s-*$")
(setq cur-indent (+ (current-indentation) puppet-indent-level))
(end-of-line)
(if (eq (puppet-syntax-context) 'comment)
(setq cur-indent (current-indentation))
(setq cur-indent (+ (current-indentation) puppet-indent-level)))
(setq not-indented nil))

;; Start of buffer.
Expand Down
22 changes: 22 additions & 0 deletions test/puppet-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,28 @@ $bar = 'hello'
}"
))))

(ert-deftest puppet-indent-line/extra-indent-after-colon ()
(puppet-test-with-temp-buffer
"
class foo {
# no extra indent after this:
bar {
'extra indent after this':
foo => 'bar';
}
}"
(indent-region (point-min) (point-max))
(should (string= (buffer-string)
"
class foo {
# no extra indent after this:
bar {
'extra indent after this':
foo => 'bar';
}
}"
))))


;;;; Major mode definition

Expand Down

0 comments on commit d7f25ad

Please sign in to comment.