Skip to content

Commit

Permalink
Prevent "Unbalanced parenthesis" error when aligning parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
smoeding committed Apr 6, 2021
1 parent 71bcd38 commit bb4c93d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions puppet-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,12 @@ Used as `syntax-propertize-function' in Puppet Mode."
"Align the current block."
(interactive)
(save-excursion
;; Move point after the end of the string if inside a string to
;; prevent "Unbalanced parentheses" error by `backward-up-list'.
(let ((region (puppet-string-region)))
(when region
(goto-char (nth 1 region))
(forward-char)))
(backward-up-list)
(let ((beg (point)))
(forward-list)
Expand Down
26 changes: 26 additions & 0 deletions test/puppet-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,32 @@ class foo {
}
}"))))

(ert-deftest puppet-align-block/point-in-string ()
:tags '(alignment)
(puppet-test-with-temp-buffer
"
class foo {
$x = {
'a'=>1,
'foo'=>{
'apples'=>1,
},
'metafalica'=>1,
}
}"
(search-forward "tafalica")
(puppet-align-block)
(should (string= (buffer-string) "
class foo {
$x = {
'a' => 1,
'foo' => {
'apples'=>1,
},
'metafalica' => 1,
}
}"))))


;;;; Imenu

Expand Down

0 comments on commit bb4c93d

Please sign in to comment.