From bb4c93d511c10eb87db74b27e6ef596f14cf9ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Mo=CC=88ding?= Date: Tue, 2 Mar 2021 20:55:53 +0100 Subject: [PATCH] Prevent "Unbalanced parenthesis" error when aligning parameters --- puppet-mode.el | 6 ++++++ test/puppet-mode-test.el | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/puppet-mode.el b/puppet-mode.el index a7b503b..3c4d029 100644 --- a/puppet-mode.el +++ b/puppet-mode.el @@ -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) diff --git a/test/puppet-mode-test.el b/test/puppet-mode-test.el index b3e9875..c63957e 100644 --- a/test/puppet-mode-test.el +++ b/test/puppet-mode-test.el @@ -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