[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode acbcdc9 407/468: Don't prevent "block starter" to
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode acbcdc9 407/468: Don't prevent "block starter" tokens from starting continuation lines |
Date: |
Thu, 5 Aug 2021 04:59:18 -0400 (EDT) |
branch: elpa/lua-mode
commit acbcdc979f0bc3beceb2f721469fb6a6af85f3fd
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Don't prevent "block starter" tokens from starting continuation lines
---
lua-mode.el | 50 ++++++++------
test/indentation-tests/continuation-lines.lua | 94 +++++++++++++++++++++++++++
2 files changed, 123 insertions(+), 21 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index e659aae..a638ed2 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -134,9 +134,10 @@
(lua-assignment-op (seq "=" (or buffer-end (not (any "=")))))
(lua-operator (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">="
"<"
">" "=" ";" ":" "," "." ".." "..."))
+ (lua-keyword-operator (symbol "and" "not" "or"))
(lua-keyword
- (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
- "goto" "if" "in" "local" "not" "or" "repeat" "return"
+ (symbol "break" "do" "else" "elseif" "end" "for" "function"
+ "goto" "if" "in" "local" "repeat" "return"
"then" "until" "while"))))
(defmacro lua-rx (&rest regexps)
@@ -217,9 +218,11 @@ element is itself expanded with `lua-rx-to-string'. "
(lua-operator
:rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
">" "=" ";" ":" "," "." ".." "..."))
+ (lua-keyword-operator
+ :rx (symbol "and" "not" "or"))
(lua-keyword
- :rx (symbol "and" "break" "do" "else" "elseif" "end" "for"
"function"
- "goto" "if" "in" "local" "not" "or" "repeat"
"return"
+ :rx (symbol "break" "do" "else" "elseif" "end" "for" "function"
+ "goto" "if" "in" "local" "repeat" "return"
"then" "until" "while")))))))
@@ -618,7 +621,7 @@ Groups 6-9 can be used in any of argument regexps."
. font-lock-constant-face)
;; Keywords
- (,(lua-rx lua-keyword)
+ (, (lua-rx (or lua-keyword lua-keyword-operator))
. font-lock-keyword-face)
;; Labels used by the "goto" statement
@@ -1261,7 +1264,27 @@ previous one even though it looked like an
end-of-statement.")
(if (looking-at "--")
(setq line-end (point))))
(goto-char line-end)
- (re-search-backward lua-cont-eol-regexp line-begin t))))
+ (when (re-search-backward lua-cont-eol-regexp line-begin t)
+ (cond
+ ;; "return" keyword is ambiguous and depends on next token
+ ((string-equal (match-string-no-properties 0) "return")
+ (save-excursion
+ (goto-char (match-end 0))
+ (forward-comment (point-max))
+ (and
+ ;; Not continuing: at end of file
+ (not (eobp))
+ (or
+ ;; "function" keyword: it is a continuation, e.g.
+ ;;
+ ;; return
+ ;; function() return 123 end
+ ;;
+ (looking-at (lua-rx (symbol "function")))
+ ;; Looking at semicolon or any other keyword: not continuation
+ (not (looking-at (lua-rx (or ";" lua-keyword))))))))
+ (t t))))))
+
(defun lua-first-token-continues-p ()
"Return non-nil if the first token on this line is a continuation token."
@@ -1273,20 +1296,6 @@ previous one even though it looked like an
end-of-statement.")
;; the control inside this function
(re-search-forward lua-cont-bol-regexp line-end t))))
-(defconst lua-block-starter-regexp
- (eval-when-compile
- (concat
- "\\(\\_<"
- (regexp-opt '("do" "while" "repeat" "until" "if" "then"
- "else" "elseif" "end" "for" "local") t)
- "\\_>\\)")))
-
-(defun lua-first-token-starts-block-p ()
- "Return non-nil if the first token on this line is a block starter token."
- (let ((line-end (line-end-position)))
- (save-excursion
- (beginning-of-line)
- (re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end
t))))
(defun lua-backward-up-list ()
"Goto starter/opener of the block that contains point."
@@ -1334,7 +1343,6 @@ The criteria for a continuing statement are:
(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))
(and (or (lua-first-token-continues-p)
(save-excursion (and (goto-char prev-line)
;; check last token of previous
nonblank line
diff --git a/test/indentation-tests/continuation-lines.lua
b/test/indentation-tests/continuation-lines.lua
index 66e26a0..bf3a4e0 100644
--- a/test/indentation-tests/continuation-lines.lua
+++ b/test/indentation-tests/continuation-lines.lua
@@ -143,6 +143,16 @@ end
a = 0
+-- indentation in block-intros: while 2
+
+while
+ foo
+do
+ a = a + 1
+end
+
+a = 0
+
-- XFAIL: indentation in block-intros: for1
for k, v
@@ -158,3 +168,87 @@ for k, v
in pairs(bar) do a = a + 1 end
a = 0
+
+
+-- indents expressions after return: basic
+
+function myfunc()
+ return
+ 123
+end
+
+-- indents expressions after return: function literal
+
+function myfunc()
+ return
+ function() return 123 end
+end
+
+-- indents expressions after return: ellipsis
+
+function myfunc(...)
+ return
+ ...
+end
+
+-- does not indents keywords after return: end
+
+function myfunc()
+ return
+end
+
+-- does not indents keywords after return: if/end
+
+function myfunc()
+ if true then
+ return
+ end
+end
+
+-- does not indents keywords after return: if/else
+
+function myfunc()
+ if true then
+ return
+ else
+ print(123)
+ end
+end
+
+-- does not indents keywords after return: if/elseif
+
+function myfunc()
+ if true then
+ return
+ elseif false then
+ print(123)
+ end
+end
+
+-- does not indents keywords after return: repeat/until
+
+function myfunc()
+ repeat
+ return
+ until true
+end
+
+-- does not indents keywords after return: semicolon 1
+
+function myfunc()
+ if true then
+ return;
+ end
+end
+
+-- does not indents keywords after return: semicolon 1
+
+function myfunc()
+ if true then
+ return;
+ hello_world() -- this is incorrect syntax, but it's fine
+ else
+ return
+ hello_world()
+ end
+end
- [nongnu] elpa/lua-mode 99312b8 365/468: Merge pull request #134 from velkyel/master, (continued)
- [nongnu] elpa/lua-mode 99312b8 365/468: Merge pull request #134 from velkyel/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4342dd1 372/468: Fix compatibility with new rx package from Emacs 27, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 50d94a4 373/468: tests: silence "Indenting region..." messages, Philip Kaludercic, 2021/08/05
- [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 <=
- [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, 2021/08/05
- [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