[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode af274e4 455/468: Merge pull request #184 from imm
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode af274e4 455/468: Merge pull request #184 from immerrr/fix-and-optimize-finding-matching-blocks |
Date: |
Thu, 5 Aug 2021 04:59:28 -0400 (EDT) |
branch: elpa/lua-mode
commit af274e419dde381d00f18f8c22e455f6e18e54fa
Merge: 08d83fc 3e89784
Author: immerrr again <immerrr@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #184 from
immerrr/fix-and-optimize-finding-matching-blocks
Fix and optimize finding matching blocks
---
lua-mode.el | 155 +++++++++++++++------
test/indentation-tests/assignment-indentation.lua | 8 +-
test/indentation-tests/function-call-arguments.lua | 109 +++++++++++++++
test/test-generic.el | 59 ++++++++
test/test-indentation.el | 148 ++++++++++----------
test/test-strings-and-comments.el | 59 ++++++--
test/utils.el | 7 +
7 files changed, 409 insertions(+), 136 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index ccdb1be..63223d2 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -957,23 +957,65 @@ Return the amount the indentation changed by."
0
lua-indent-level))))))
-(defun lua-find-regexp (direction regexp &optional limit ignore-p)
+
+(defun lua--ensure-point-within-limit (limit backward)
+ "Return non-nil if point is within LIMIT going forward.
+
+With BACKWARD non-nil, return non-nil if point is within LIMIT
+going backward.
+
+If point is beyond limit, move it onto limit."
+ (if (= (cl-signum (- (point) limit))
+ (if backward 1 -1))
+ t
+ (goto-char limit)
+ nil))
+
+
+(defun lua--escape-from-string (&optional backward)
+ "Move point outside of string if it is inside one.
+
+By default, point is placed after the string, with BACKWARD it is
+placed before the string."
+ (interactive)
+ (let ((parse-state (syntax-ppss)))
+ (when (nth 3 parse-state)
+ (if backward
+ (goto-char (nth 8 parse-state))
+ (parse-partial-sexp (point) (line-end-position) nil nil (syntax-ppss)
'syntax-table))
+ t)))
+
+
+(defun lua-find-regexp (direction regexp &optional limit)
"Searches for a regular expression in the direction specified.
+
Direction is one of 'forward and 'backward.
-By default, matches in comments and strings are ignored, but what to ignore is
-configurable by specifying ignore-p. If the regexp is found, returns point
-position, nil otherwise.
-ignore-p returns true if the match at the current point position should be
-ignored, nil otherwise."
- (let ((ignore-func (or ignore-p 'lua-comment-or-string-p))
- (search-func (if (eq direction 'forward)
+
+Matches in comments and strings are ignored. If the regexp is
+found, returns point position, nil otherwise."
+ (let ((search-func (if (eq direction 'forward)
're-search-forward 're-search-backward))
(case-fold-search nil))
- (catch 'found
- (while (funcall search-func regexp limit t)
- (if (and (not (funcall ignore-func (match-beginning 0)))
- (not (funcall ignore-func (match-end 0))))
- (throw 'found (point)))))))
+ (cl-loop
+ always (or (null limit)
+ (lua--ensure-point-within-limit limit (not (eq direction
'forward))))
+ always (funcall search-func regexp limit 'noerror)
+ for match-beg = (match-beginning 0)
+ for match-end = (match-end 0)
+ while (or (lua-comment-or-string-p match-beg)
+ (lua-comment-or-string-p match-end))
+ do (let ((parse-state (syntax-ppss)))
+ (cond
+ ;; Inside a string
+ ((nth 3 parse-state)
+ (lua--escape-from-string (not (eq direction 'forward))))
+ ;; Inside a comment
+ ((nth 4 parse-state)
+ (goto-char (nth 8 parse-state))
+ (when (eq direction 'forward)
+ (forward-comment 1)))))
+ finally return (point))))
+
(defconst lua-block-regexp
(eval-when-compile
@@ -1148,8 +1190,9 @@ If optional NOREPORT is non-nil, it won't flag an error
if there
is no block open/close open."
(interactive)
;; search backward to the beginning of the keyword if necessary
- (if (eq (char-syntax (following-char)) ?w)
- (re-search-backward "\\_<" nil t))
+ (when (and (eq (char-syntax (following-char)) ?w)
+ (not (looking-at "\\_<")))
+ (re-search-backward "\\_<" nil t))
(let ((position (lua-goto-matching-block-token)))
(if (and (not position)
(not noreport))
@@ -1246,7 +1289,7 @@ an optional whitespace till the end of the line.")
(concat
"\\=\\s *"
"\\(?:\\(?1:\\_<"
- (regexp-opt '("and" "or" "not") t)
+ (regexp-opt '("and" "or" "not" "in") t)
"\\_>\\)\\|\\(?2:"
(regexp-opt '("," "+" "-" "*" "/" "%" "^" ".." "=="
"=" "<" ">" "<=" ">=" "~=" "." ":"
@@ -1264,16 +1307,10 @@ previous one even though it looked like an
end-of-statement.")
(defun lua-last-token-continues-p ()
"Return non-nil if the last token on this line is a continuation token."
(let ((line-begin (line-beginning-position))
- (line-end (line-end-position))
return-value)
(save-excursion
(end-of-line)
- ;; we need to check whether the line ends in a comment and
- ;; skip that one.
- (while (lua-find-regexp 'backward "-" line-begin 'lua-string-p)
- (if (looking-at "--")
- (setq line-end (point))))
- (goto-char line-end)
+ (lua-skip-ws-and-comments-backward line-begin)
(setq return-value (and (re-search-backward lua-cont-eol-regexp
line-begin t)
(or (match-beginning 1)
(match-beginning 2))))
@@ -1304,6 +1341,7 @@ previous one even though it looked like an
end-of-statement.")
(let ((line-end (line-end-position)))
(save-excursion
(beginning-of-line)
+ (lua-skip-ws-and-comments-forward line-end)
;; 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
@@ -1352,6 +1390,16 @@ previous one even though it looked like an
end-of-statement.")
(if (eql start-pos end-pos) start-pos (match-beginning 0))
(if (eql start-pos end-pos) start-pos (match-end 0))))))))
+(defun lua--continuation-breaking-line-p ()
+ "Return non-nil if looking at token(-s) that forbid continued line."
+ (save-excursion
+ (lua-skip-ws-and-comments-forward (line-end-position))
+ (looking-at (lua-rx (or (symbol "do" "while" "repeat" "until"
+ "if" "then" "elseif" "else"
+ "for" "local")
+ lua-funcheader)))))
+
+
(defun lua-is-continuing-statement-p-1 ()
"Return non-nil if current lined continues a statement.
@@ -1365,9 +1413,10 @@ The criteria for a continuing statement are:
(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.
- (save-excursion
+ (not (lua--continuation-breaking-line-p))
+ (save-excursion
+ (or
+ ;; Binary operator or keyword that implies continuation.
(and (setq continuation-pos
(or (lua-first-token-continues-p)
(save-excursion (and (goto-char prev-line)
@@ -1383,11 +1432,7 @@ The criteria for a continuing statement are:
;; - 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))))))
-
+ continuation-pos))))))
(defun lua-is-continuing-statement-p (&optional parse-start)
@@ -1420,11 +1465,15 @@ This true is when the line :
;; opener line, ") + long_function_name2({", which in its turn is decided
;; by the "long_function_name(" line, which is a continuation line
;; because the line before it ends with a binary operator.
- (while (and (lua--goto-line-beginning-rightmost-closer)
- (lua--backward-up-list-noerror)
- (lua-is-continuing-statement-p-1)))
- (lua-is-continuing-statement-p-1)))
-
+ (cl-loop
+ ;; Go to opener line
+ while (and (lua--goto-line-beginning-rightmost-closer)
+ (lua--backward-up-list-noerror))
+ ;; If opener line is continuing, repeat. If opener line is not
+ ;; continuing, return nil.
+ always (lua-is-continuing-statement-p-1)
+ ;; We get here if there was no opener to go to: check current line.
+ finally return (lua-is-continuing-statement-p-1))))
(defun lua-make-indentation-info-pair (found-token found-pos)
"Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.
@@ -1492,10 +1541,23 @@ Don't use standalone."
(save-excursion
(let* ((line-beginning (line-beginning-position))
(same-line (and (lua-goto-matching-block-token found-pos
'backward)
- (<= line-beginning (point)))))
- (if (not same-line)
- (lua-calculate-indentation-info (point))
- (cons 'remove-matching 0)))))
+ (<= line-beginning (point))))
+ (opener-pos (point))
+ opener-continuation-offset)
+ (if same-line
+ (cons 'remove-matching 0)
+ (back-to-indentation)
+ (setq opener-continuation-offset
+ (if (lua-is-continuing-statement-p-1) lua-indent-level 0))
+
+ ;; Accumulate indentation up to opener, including indentation. If
+ ;; there were no other indentation modifiers until said opener,
+ ;; ensure there is no continuation after the closer.
+ `(multiple . ((absolute . ,(- (current-indentation)
opener-continuation-offset))
+ ,@(when (/= opener-continuation-offset 0)
+ (list (cons 'continued-line
opener-continuation-offset)))
+ ,@(delete nil (list (lua-calculate-indentation-info-1
nil opener-pos)))
+ (cancel-continued-line . nil)))))))
((member found-token '("do" "then"))
`(multiple . ((cancel-continued-line . nil) (relative .
,lua-indent-level))))
@@ -1769,12 +1831,13 @@ If not, return nil."
;; hello_world()
;; end
(setq opener-pos (point))
- (unless (or
- (and (string-equal (car opener-info) "do")
- (member (car (lua--backward-up-list-noerror)) '("while"
"for")))
- (and (string-equal (car opener-info) "then")
- (member (car (lua--backward-up-list-noerror)) '("if"
"elseif"))))
- (goto-char opener-pos))
+ (when (/= (- opener-pos (line-beginning-position))
(current-indentation))
+ (unless (or
+ (and (string-equal (car opener-info) "do")
+ (member (car (lua--backward-up-list-noerror))
'("while" "for")))
+ (and (string-equal (car opener-info) "then")
+ (member (car (lua--backward-up-list-noerror)) '("if"
"elseif"))))
+ (goto-char opener-pos)))
;; (let (cont-stmt-pos)
;; (while (setq cont-stmt-pos (lua-is-continuing-statement-p))
diff --git a/test/indentation-tests/assignment-indentation.lua
b/test/indentation-tests/assignment-indentation.lua
index 10adb60..4d0f7ee 100644
--- a/test/indentation-tests/assignment-indentation.lua
+++ b/test/indentation-tests/assignment-indentation.lua
@@ -175,14 +175,14 @@ x = t[very_very_very_long_name()
-- does not indent binary operators inside brackets: indentation 1
-x = [
+x = foo[
very_very_very_long_name() +
another_very_very_very_long_name()
- ]
+ ]
-- does not indent binary operators inside brackets: indentation 2
-x = [
+x = foo[
very_very_very_long_name()
+ another_very_very_very_long_name()
- ]
+ ]
diff --git a/test/indentation-tests/function-call-arguments.lua
b/test/indentation-tests/function-call-arguments.lua
new file mode 100644
index 0000000..e4a520a
--- /dev/null
+++ b/test/indentation-tests/function-call-arguments.lua
@@ -0,0 +1,109 @@
+-- THINGS TO TEST:
+-- parentheses vs braces (table ctor)
+-- close paren/brace: attached/detached
+-- alignment/indentation
+-- args in horizontal line vs args in column vs mixed
+-- one of params is a table/function literal/function call/single-line
table/single-line function
+
+-- it works for single line case
+
+foobar(a, b, c)
+
+a = 0
+
+-- it works for indenting all args on one line: close paren on separate line
+
+foobar(
+ a, b, c
+)
+
+a = 0
+
+-- it works for indenting all args in a column: close paren on separate line
+
+foobar(
+ a,
+ b,
+ c
+)
+
+a = 0
+
+-- it works for mixed arg indentation: close paren on separate line
+
+foobar(
+ a, b,
+ c, d
+)
+
+a = 0
+
+-- it works with table ctorfor single line case
+
+foobar{a, b, c}
+
+a = 0
+
+-- it works with table ctor for indenting all args on one line: close paren on
separate line
+
+foobar{
+ a, b, c
+}
+
+a = 0
+
+-- it works with table ctor for indenting all args in a column: close paren on
separate line
+
+foobar{
+ a,
+ b,
+ c
+}
+
+a = 0
+
+-- it works with table ctor for mixed arg indentation: close paren on separate
line
+
+foobar{
+ a, b,
+ c, d
+}
+
+a = 0
+
+-- it works for mixed arg indentation with table in the middle: close paren on
separate line
+
+foobar(
+ a, b,
+ {
+ foo = bar,
+ qux = quux
+ }, d
+)
+
+a = 0
+
+-- it works for mixed arg indentation with table first: close paren on
separate line
+
+foobar(
+ {
+ foo = bar,
+ qux = quux
+ }, b,
+ c, d
+)
+
+a = 0
+
+-- it works for mixed arg indentation with table last: close paren on separate
line
+
+foobar(
+ a, b,
+ c, {
+ foo = bar,
+ qux = quux
+ }
+)
+
+a = 0
+
diff --git a/test/test-generic.el b/test/test-generic.el
index 1afcadc..796db3b 100644
--- a/test/test-generic.el
+++ b/test/test-generic.el
@@ -195,3 +195,62 @@ local foo = <2>{
:with-point-at "<1>"
:after-executing (lua-backward-up-list)
:to-end-up-at "<2>")))
+
+
+(describe "lua-goto-matching-block"
+ (it "works for do...end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end <1>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end e<1>nd")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end en<1>d")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>do if true then print(123) end <2>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "d<1>o if true then print(123) end <2>end"))
+
+ (it "works for repeat...until block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>repeat if true then print(123) end <2>until true")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>repeat if true then print(123) end <1>until true"))
+
+ (it "works for while...do...end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>while foo() do if true then print(123) end <2>end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>while foo() do if true then print(123) end <1>end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "while foo() <1>do if true then print(123) end <2>end")
+ ;; The next line is a valid statement that ensures
+ ;; "lua-goto-matching-block" can distinguish between "while..do" and
+ ;; "do..end"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>while false do print(123) <2>end do print(123) end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "while false do print(123) end <1>do print(123) <2>end"))
+
+ (it "works for if..elseif..else..end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>if true then foo() elseif false then bar() else baz() <2>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false then bar() else baz() <1>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false then bar() <1>else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false <1>then bar() else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() <1>elseif false then bar() else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true <1>then foo() elseif false then bar() else baz()
end")))
diff --git a/test/test-indentation.el b/test/test-indentation.el
index 7cc6d12..d581504 100644
--- a/test/test-indentation.el
+++ b/test/test-indentation.el
@@ -59,163 +59,167 @@
indentation-tests))
(describe "Continuation lines"
- (it "are indented before/after binary operators"
- (let ((binops '("+" "-" "*" "/" "^" "%" ".."
- "<" "<=" ">" ">=" "==" "~="
- "and" "or")))
- (cl-dolist (binop binops)
- (lua--reindent-like (replace-regexp-in-string "BINOP" binop "\
+ (lua--parametrize-tests
+ (binop)
+ (("+") ("-") ("*") ("/") ("^") ("%") ("..")
+ ("<") ("<=") (">") (">=") ("==") ("~=") ("and") ("or"))
+
+ :it (format "are indented before/after binary operators: %s" binop)
+ (expect (replace-regexp-in-string "BINOP" binop "\
a = foo BINOP
- bar" 'fixedcase))
- (lua--reindent-like (replace-regexp-in-string "BINOP" binop "\
+ bar" 'fixedcase)
+ :to-be-reindented-the-same-way)
+ (expect (replace-regexp-in-string "BINOP" binop "\
a = foo
- BINOP bar" 'fixedcase)))))
-
-
-
- (xit "are indented before/after unary operators"
- (expect (lua--reindent-like "\
-foo = bar
- -#some_str"))
-
- (cl-dolist (unop '("-" "#" "not "))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-foobar(qux,
- <>quux)")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-foobar(qux, xyzzy
- <>quux)")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-foobar(
- <>quux)")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-x = {qux,
- <>quux}")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-x = {qux;
- <>quux}")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-x = {qux, xyzzy
- <>quux}")))
- (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
-x = {
- <>quux
-}"))))))
+ BINOP bar" 'fixedcase)
+ :to-be-reindented-the-same-way))
+) ;; (
+
+
+
+;; (xit "are indented before/after unary operators"
+;; (expect (lua--reindent-like "\
+;; foo = bar
+;; -#some_str"))
+
+;; (cl-dolist (unop '("-" "#" "not "))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; foobar(qux,
+;; <>quux)")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; foobar(qux, xyzzy
+;; <>quux)")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; foobar(
+;; <>quux)")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; x = {qux,
+;; <>quux}")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; x = {qux;
+;; <>quux}")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; x = {qux, xyzzy
+;; <>quux}")))
+;; (expect (lua--reindent-like (replace-regexp-in-string "<>" unop "\
+;; x = {
+;; <>quux
+;; }"))))))
(describe "Function indentation"
(it "indents function call arguments"
- (expect (lua--reindent-like "\
+ (expect "\
foobar(
- a, b, c)"))
- (expect (lua--reindent-like "\
+ a, b, c)" :to-be-reindented-the-same-way)
+ (expect "\
foobar(
a,
- b, c)"))
+ b, c)" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(
a, b, c
-)"))
+)" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(a,
b,
- c)"))
+ c)" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar{
a, b, c
-}")))
+}" :to-be-reindented-the-same-way))
(it "indent blocks with lua-indent-nested-block-content-align"
(let ((lua-indent-nested-block-content-align nil))
- (expect (lua--reindent-like "\
+ (expect "\
call_some_fn( something, {
val = 5,
another = 6,
-} )"))
- (expect (lua--reindent-like "\
+} )" :to-be-reindented-the-same-way)
+ (expect "\
local def = {
some_very_long_name = { fn =
function()
return true
end
}
-}"))
+}" :to-be-reindented-the-same-way)
))
(it "indent blocks with lua-indent-close-paren-align"
(let ((lua-indent-close-paren-align nil))
- (expect (lua--reindent-like "\
+ (expect "\
local foo = setmetatable( {
a = 4,
b = 5,
}, {
__index = some_func,
-} )"))
+} )" :to-be-reindented-the-same-way)
))
(it "indents nested tables with alternative block indenting"
(let ((lua-indent-nested-block-content-align nil)
(lua-indent-close-paren-align nil))
- (expect (lua--reindent-like "\
+ (expect "\
foobar({
a, b, c
-})"))
+})" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(a, {
b,
c
-})"))
+})" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(
a,
{
b,
c
-})"))
+})" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(
a,
{
b,
c
}
-)"))
+)" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(a,
{
b,
c
-})"))
+})" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(a,
{
b,
c
}
-)"))
+)" :to-be-reindented-the-same-way)
- (expect (lua--reindent-like "\
+ (expect "\
foobar(
{
a,
b
},
c, d
-)"))
+)" :to-be-reindented-the-same-way)
)))
(ert-deftest lua-indentation-keywords-with-special-characters ()
- (expect (lua--reindent-like "\
+ (expect "\
do
foobar = _do
-end")))
+end" :to-be-reindented-the-same-way))
diff --git a/test/test-strings-and-comments.el
b/test/test-strings-and-comments.el
index da20308..cf928eb 100644
--- a/test/test-strings-and-comments.el
+++ b/test/test-strings-and-comments.el
@@ -450,24 +450,55 @@
(describe "respects limit"
(lua--parametrize-tests
(limit navigation-spec test-name)
- ((6 " <1> <2> " "respect limit in whitespace")
+ ((6 " <1> <2> " "in whitespace")
(1 " <2><1> " "don't move if limit is before point")
- (8 "-- <1> <2> \n" "respect limit when escaping single-line comment
1")
- (8 "-- <1> \n<2> " "respect limit when escaping single-line comment
2")
- (8 "-- <1> <2>\n " "respect limit when escaping single-line comment
3")
- (8 "--[[<1> <2> ]] \n" "respect limit when escaping multi-line comment
1")
- (8 "--[[<1> ]<2>] \n" "respect limit when escaping multi-line comment
1")
- (8 "--[[<1> <2> ]] \n" "respect limit when escaping multi-line comment
1")
-
- (7 "-- <1>@s<2>ee x " "respect limit when escaping single-line luadoc
comment")
- (8 "-- <1>@se<2>e x " "respect limit when escaping single-line luadoc
comment")
- (9 "-- <1>@see<2> x " "respect limit when escaping single-line luadoc
comment")
- (7 "--[[<1>@s<2>ee x]] " "respect limit when escaping single-line luadoc
comment")
- (8 "--[[<1>@se<2>e x]] " "respect limit when escaping single-line luadoc
comment")
- (9 "--[[<1>@see<2> x]] " "respect limit when escaping single-line luadoc
comment")
+ (8 "-- <1> <2> \n" "when escaping single-line comment 1")
+ (8 "-- <1> \n<2> " "when escaping single-line comment 2")
+ (8 "-- <1> <2>\n " "when escaping single-line comment 3")
+ (8 "--[[<1> <2> ]] \n" "when escaping multi-line comment 1")
+ (8 "--[[<1> ]<2>] \n" "when escaping multi-line comment 1")
+ (8 "--[[<1> <2> ]] \n" "when escaping multi-line comment 1")
+
+ (7 "-- <1>@s<2>ee x " "when escaping single-line luadoc comment")
+ (8 "-- <1>@se<2>e x " "when escaping single-line luadoc comment")
+ (9 "-- <1>@see<2> x " "when escaping single-line luadoc comment")
+ (7 "--[[<1>@s<2>ee x]] " "when escaping multi-line luadoc comment")
+ (8 "--[[<1>@se<2>e x]] " "when escaping multi-line luadoc comment")
+ (9 "--[[<1>@see<2> x]] " "when escaping multi-line luadoc comment")
)
:it (replace-regexp-in-string "\n" "\\\\n" (format "%s: limit=%S %S"
test-name limit navigation-spec))
(expect navigation-spec
:with-point-at "<1>"
:after-executing (lua-skip-ws-and-comments-forward limit)
:to-end-up-at "<2>"))))
+
+(describe "lua-find-regexp"
+ (it "does not match open-bracket that is part of multiline string opener:
forward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("<>foo = [[ bar ]]"))
+ (expect (lua-find-regexp 'forward "\\[") :not :to-be-truthy)))
+
+ (it "does not match open-bracket that is part of multiline string opener:
backward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("foo = [[ bar ]]<>"))
+ (expect (lua-find-regexp 'backward "\\[") :not :to-be-truthy)))
+
+ (it "does not match close-bracket that is part of multiline string closer:
forward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("<>foo = [[ bar ]]"))
+ (expect (lua-find-regexp 'forward "]") :not :to-be-truthy)))
+
+ (it "does not match close-bracket that is part of multiline string closer:
backward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("<>foo = [[ bar ]]"))
+ (expect (lua-find-regexp 'backward "]") :not :to-be-truthy)))
+
+ (it "does not match minus that is part of comment starter: forward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("<>foo = [[ bar ]] -- baz"))
+ (expect (lua-find-regexp 'forward "-") :not :to-be-truthy)))
+
+ (it "does not match minus that is part of comment starter: backward"
+ (with-lua-buffer
+ (lua-insert-goto-<> '("<>foo = [[ bar ]] -- baz"))
+ (expect (lua-find-regexp 'backward "-") :not :to-be-truthy))))
diff --git a/test/utils.el b/test/utils.el
index fb588ad..6fc7912 100644
--- a/test/utils.el
+++ b/test/utils.el
@@ -231,6 +231,13 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(buttercup-define-matcher :with-point-at (&rest args)
(apply #'with-point-at-matcher `(:lua-code ,(car args) :with-point-at ,@(cdr
args))))
+;;; Shortcut for with-point-at with <1> and <2> placeholders
+(buttercup-define-matcher :to-move-point-from-1-to-2 (code-block lua-code)
+ (with-point-at-matcher
+ :lua-code lua-code
+ :with-point-at (lambda () "<1>")
+ :after-executing code-block
+ :to-end-up-at (lambda () "<2>")))
(defun lua--string-trim (string &optional trim-left trim-right)
;; Backport of string-trim for Emacs 24 that doesn't have subr-x lib.
- [nongnu] elpa/lua-mode 724bfa5 409/468: Fix support for file-local vars in indentation tests, add tests for blocks, (continued)
- [nongnu] elpa/lua-mode 724bfa5 409/468: Fix support for file-local vars in indentation tests, add tests for blocks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1365ba0 412/468: Enable XFAIL-ing tests for continuation in block intros, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 51a32ef 417/468: Merge pull request #176 from immerrr/improve-indentation-for-continuation-lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b37710e 418/468: Enable fontification of variable names in "for" and function parameters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9c275cd 419/468: Add regression test for issue #157, fix lua-get-line-faces, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5fe5f57 422/468: Fix wait-for-prompt to take lua-prompt-regexp into account, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 83ec53d 430/468: `lua-funcname-at-point': be more strict, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 70b9384 448/468: Don't evaluate lua-is-continuing-statement-p-1 twice, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 350acce 450/468: Don't do lua-backward-up-list calculation for overrides if not necessary, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3e89784 454/468: Fix test suite names, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode af274e4 455/468: Merge pull request #184 from immerrr/fix-and-optimize-finding-matching-blocks,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode d81c700 466/468: Bump version tag, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b9a476c 467/468: Merge pull request #194 from phikal/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 28155ba 241/468: Update README.md, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 45a881d 243/468: lua-search-documentation: fix 'foo.bar' lookups broken when making '.' punctuation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f8a41b8 246/468: Fix cl-lib dependency for Emacs23 tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9e200e8 247/468: Fix font-locking of functions with underscores (issue #63), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bbab5a6 253/468: Don't anchor arglist continuation to block openers, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d86a22 254/468: Fix indentation error raised if 'else' is on the same line as 'if', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2ad2ac8 256/468: lua-imenu-generic-expression add support for local function, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8ff3427 257/468: Merge pull request #65 from guoxx/master, Philip Kaludercic, 2021/08/05