emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]