Skip to content

Commit bb4c93d

Browse files
committed
Prevent "Unbalanced parenthesis" error when aligning parameters
1 parent 71bcd38 commit bb4c93d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

puppet-mode.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,12 @@ Used as `syntax-propertize-function' in Puppet Mode."
10411041
"Align the current block."
10421042
(interactive)
10431043
(save-excursion
1044+
;; Move point after the end of the string if inside a string to
1045+
;; prevent "Unbalanced parentheses" error by `backward-up-list'.
1046+
(let ((region (puppet-string-region)))
1047+
(when region
1048+
(goto-char (nth 1 region))
1049+
(forward-char)))
10441050
(backward-up-list)
10451051
(let ((beg (point)))
10461052
(forward-list)

test/puppet-mode-test.el

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,32 @@ class foo {
615615
}
616616
}"))))
617617

618+
(ert-deftest puppet-align-block/point-in-string ()
619+
:tags '(alignment)
620+
(puppet-test-with-temp-buffer
621+
"
622+
class foo {
623+
$x = {
624+
'a'=>1,
625+
'foo'=>{
626+
'apples'=>1,
627+
},
628+
'metafalica'=>1,
629+
}
630+
}"
631+
(search-forward "tafalica")
632+
(puppet-align-block)
633+
(should (string= (buffer-string) "
634+
class foo {
635+
$x = {
636+
'a' => 1,
637+
'foo' => {
638+
'apples'=>1,
639+
},
640+
'metafalica' => 1,
641+
}
642+
}"))))
643+
618644

619645
;;;; Imenu
620646

0 commit comments

Comments
 (0)