[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode bf80b7e 414/468: Enable continuation after comma
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode bf80b7e 414/468: Enable continuation after comma outside of parens/braces/brackets |
Date: |
Thu, 5 Aug 2021 04:59:20 -0400 (EDT) |
branch: elpa/lua-mode
commit bf80b7ec53cb89f6efee8fbe9412a36d26f2c629
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Enable continuation after comma outside of parens/braces/brackets
---
lua-mode.el | 57 ++++++++++++++---------
test/indentation-tests/assignment-indentation.lua | 12 ++---
test/indentation-tests/issue-33.lua | 3 +-
3 files changed, 42 insertions(+), 30 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index e280535..f1640b9 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1217,17 +1217,17 @@ Returns final value of point as integer or nil if
operation failed."
(defconst lua-cont-eol-regexp
(eval-when-compile
(concat
- "\\(\\_<"
+ "\\(?:\\(?1:\\_<"
(regexp-opt '("and" "or" "not" "in" "for" "while"
"local" "function" "if" "until" "elseif" "return")
t)
- "\\_>\\|"
- "\\(^\\|[^" lua-operator-class "]\\)"
+ "\\_>\\)\\|"
+ "\\(?:^\\|[^" lua-operator-class "]\\)\\(?2:"
(regexp-opt '("+" "-" "*" "/" "%" "^" ".." "=="
"=" "<" ">" "<=" ">=" "~=" "." ":"
- "&" "|" "~" ">>" "<<" "~")
+ "&" "|" "~" ">>" "<<" "~" ",")
t)
- "\\)"
+ "\\)\\)"
"\\s *\\="))
"Regexp that matches the ending of a line that needs continuation.
@@ -1239,14 +1239,14 @@ an optional whitespace till the end of the line.")
(eval-when-compile
(concat
"\\=\\s *"
- "\\(\\_<"
+ "\\(?:\\(?1:\\_<"
(regexp-opt '("and" "or" "not") t)
- "\\_>\\|"
- (regexp-opt '("+" "-" "*" "/" "%" "^" ".." "=="
+ "\\_>\\)\\|\\(?2:"
+ (regexp-opt '("," "+" "-" "*" "/" "%" "^" ".." "=="
"=" "<" ">" "<=" ">=" "~=" "." ":"
"&" "|" "~" ">>" "<<" "~")
t)
- "\\($\\|[^" lua-operator-class "]\\)"
+ "\\)\\(?:$\\|[^" lua-operator-class "]\\)"
"\\)"))
"Regexp that matches a line that continues previous one.
@@ -1268,7 +1268,9 @@ previous one even though it looked like an
end-of-statement.")
(if (looking-at "--")
(setq line-end (point))))
(goto-char line-end)
- (setq return-value (re-search-backward lua-cont-eol-regexp line-begin t))
+ (setq return-value (and (re-search-backward lua-cont-eol-regexp
line-begin t)
+ (or (match-beginning 1)
+ (match-beginning 2))))
(if (and return-value
(string-equal (match-string-no-properties 0) "return"))
;; "return" keyword is ambiguous and depends on next token
@@ -1299,7 +1301,10 @@ previous one even though it looked like an
end-of-statement.")
;; if first character of the line is inside string, it's a continuation
;; if strings aren't supposed to be indented,
`lua-calculate-indentation' won't even let
;; the control inside this function
- (re-search-forward lua-cont-bol-regexp line-end t))))
+ (and
+ (re-search-forward lua-cont-bol-regexp line-end t)
+ (or (match-beginning 1)
+ (match-beginning 2))))))
(defun lua--backward-up-list-noerror ()
@@ -1350,21 +1355,29 @@ 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 return-value)
+* the expression is not enclosed by a parentheses/braces/brackets"
+ (let (prev-line continuation-pos parent-block-opener)
(save-excursion (setq prev-line (lua-forward-line-skip-blanks 'back)))
(and prev-line
(or
;; Binary operator or keyword that implies continuation.
- (and (setq return-value
- (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 (lua--backward-up-list-noerror))
- ;; XXX: can we also add "{" here?
- '("(" "[")))
- return-value)
+ (save-excursion
+ (and (setq continuation-pos
+ (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
+ ;; Operators/keywords does not create continuation inside
some blocks:
+ (and
+ (setq parent-block-opener (car-safe
(lua--backward-up-list-noerror)))
+ (or
+ ;; - inside parens/brackets
+ (member parent-block-opener '("(" "["))
+ ;; - inside braces if it is a comma
+ (and (eq (char-after continuation-pos) ?,)
+ (equal parent-block-opener "{")))))
+ continuation-pos))
;; "for" expressions (until the next do) imply continuation.
(when (string-equal (car-safe (lua--backward-up-list-noerror)) "for")
(point))))))
diff --git a/test/indentation-tests/assignment-indentation.lua
b/test/indentation-tests/assignment-indentation.lua
index 6373c0c..10adb60 100644
--- a/test/indentation-tests/assignment-indentation.lua
+++ b/test/indentation-tests/assignment-indentation.lua
@@ -17,7 +17,7 @@ foo =
10
bar = 20
--- XFAIL: continuation after comma: 1
+-- continuation after comma: 1
foo,
baz = 10, 20
@@ -30,20 +30,20 @@ foo, baz
bar = 20
--- XFAIL: continuation after comma: 3
+-- continuation after comma: 3
foo, baz = 10,
20
bar = 20
--- XFAIL: continuation after comma: 4
+-- continuation after comma: 4
foo,
baz =
10, 20
--- XFAIL: continuation after comma: 5
+-- continuation after comma: 5
foo, baz =
10,
@@ -56,13 +56,13 @@ bar = 20
local
x = 5
--- XFAIL: continuation after "local": 2
+-- continuation after "local": 2
local
x,
y = 10, 20
--- XFAIL: continuation after "local": 3
+-- continuation after "local": 3
local
x,
diff --git a/test/indentation-tests/issue-33.lua
b/test/indentation-tests/issue-33.lua
index 14014b2..72efbfa 100644
--- a/test/indentation-tests/issue-33.lua
+++ b/test/indentation-tests/issue-33.lua
@@ -5,8 +5,7 @@ a =
b =
{
- },
-
+ }
a = {
table_elt_indented
- [nongnu] elpa/lua-mode d746b7e 381/468: Fix typos, (continued)
- [nongnu] elpa/lua-mode d746b7e 381/468: Fix typos, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dc30240 384/468: Merge pull request #160 from tarsiiformes/typo, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4db05e8 389/468: Use cl-lib instead of cl, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3f67365 394/468: Renamed word “Result” to “Actual” in matcher's message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 658bf8f 397/468: Merge pull request #166 from veprbl/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6436a45 398/468: Index "require" as imenu items, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0e6813a 405/468: Refactor indentation tests to use test cases defined in *.lua files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode acbcdc9 407/468: Don't prevent "block starter" tokens from starting continuation lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a45c6d 410/468: lua-make-indentation-info-pair: optimize "same-line" checks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8270df5 411/468: lua-is-continuing-statement-p: remove N^2 complexity on openers/closers, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bf80b7e 414/468: Enable continuation after comma outside of parens/braces/brackets,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode afd5aa3 415/468: test-indentation: remove unused subr-x dependency, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b170500 416/468: Add backport of string-trim not available in Emacs 24, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5bfdea5 420/468: Merge pull request #177 from immerrr/refactor-variable-list-fontification, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0546418 423/468: Extend lua-default-application doc a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d46ad3 424/468: Update readme, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 345ebfc 425/468: Merge pull request #174 from immerrr/assorted-fixes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 85d01e9 429/468: `lua-funcname-at-point': fix regexes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b647537 428/468: `lua-start-proces': don't hang if already running, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 853b040 432/468: `lua-start-process': start a new process sometimes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fbdbf05 439/468: Merge pull request #181 from immerrr/treat-comment-delimiters-as-comments-too, Philip Kaludercic, 2021/08/05