Skip to content

Commit 16549e2

Browse files
committed
Prevent "Unbalanced parenthesis" error when aligning parameters
1 parent 9f4fef6 commit 16549e2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

puppet-mode.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,11 @@ Used as `syntax-propertize-function' in Puppet Mode."
10361036
"Align the current block."
10371037
(interactive)
10381038
(save-excursion
1039+
;; Move point to beginning of string if inside a string to
1040+
;; prevent "Unbalanced parentheses" error by `backward-up-list'.
1041+
(let ((region (puppet-string-region)))
1042+
(if region
1043+
(goto-char (car region))))
10391044
(backward-up-list)
10401045
(let ((beg (point)))
10411046
(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)