branch: elpa/lua-mode
commit d6dc6fbb9c64ba8e0b1bf6cdb47de28dc77fe465
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
Don't add "continuation line" indentation inside parentheses/brackets
Continuation lines are required in
x = foo_bar() +
baz_qux()
to clarify that the statement continues after the end of line implicitly. In
the case when the expression is parenthesized
x = (foo_bar() +
baz_qux())
It is not necessary, because parentheses show the boundaries explicitly.
---
lua-mode.el | 14 +++++---
test/indentation-tests/continuation-lines.lua | 49 +++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index e275cdb..e659aae 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1328,17 +1328,21 @@ The criteria for a continuing statement are:
* the last token of the previous line is a continuing op,
OR the first token of the current line is a continuing op
-"
+* the expression is not enclosed by a parenthesis"
(let ((prev-line nil))
(save-excursion
(if parse-start (goto-char parse-start))
(save-excursion (setq prev-line (lua-forward-line-skip-blanks 'back)))
(and prev-line
(not (lua-first-token-starts-block-p))
- (or (lua-first-token-continues-p)
- (and (goto-char prev-line)
- ;; check last token of previous nonblank line
- (lua-last-token-continues-p)))))))
+ (and (or (lua-first-token-continues-p)
+ (save-excursion (and (goto-char prev-line)
+ ;; check last token of previous
nonblank line
+ (lua-last-token-continues-p))))
+ (not (member (car-safe (condition-case nil
(lua-backward-up-list)
+ (scan-error nil)))
+ ;; XXX: can we also add "{" here?
+ '("(" "["))))))))
(defun lua-make-indentation-info-pair (found-token found-pos)
"Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.
diff --git a/test/indentation-tests/continuation-lines.lua
b/test/indentation-tests/continuation-lines.lua
index e329d36..66e26a0 100644
--- a/test/indentation-tests/continuation-lines.lua
+++ b/test/indentation-tests/continuation-lines.lua
@@ -86,7 +86,56 @@ x = foo(123,
qux,
quux)
+-- does not indent binary operators inside parentheses: alignment 1
+
+x = (very_very_very_long_name() +
+ another_very_very_very_long_name())
+
+-- does not indent binary operators inside parentheses: alignment 2
+
+x = (very_very_very_long_name()
+ + another_very_very_very_long_name())
+
+-- does not indent binary operators inside parentheses: indentation 1
+
+x = (
+ very_very_very_long_name() +
+ another_very_very_very_long_name()
+ )
+
+-- does not indent binary operators inside parentheses: indentation 2
+
+x = (
+ very_very_very_long_name()
+ + another_very_very_very_long_name()
+ )
+
+-- does not indent binary operators inside brackets: alignment 1
+
+x = t[very_very_very_long_name() +
+ another_very_very_very_long_name()]
+
+-- does not indent binary operators inside brackets: alignment 2
+
+x = t[very_very_very_long_name()
+ + another_very_very_very_long_name()]
+
+-- does not indent binary operators inside brackets: indentation 1
+
+x = [
+ very_very_very_long_name() +
+ another_very_very_very_long_name()
+ ]
+
+-- does not indent binary operators inside brackets: indentation 2
+
+x = [
+ very_very_very_long_name()
+ + another_very_very_very_long_name()
+ ]
+
-- XFAIL: indentation in block-intros: while
+
while
foo do
a = a + 1