[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 8270df5 411/468: lua-is-continuing-statement-p: r
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 8270df5 411/468: lua-is-continuing-statement-p: remove N^2 complexity on openers/closers |
Date: |
Thu, 5 Aug 2021 04:59:19 -0400 (EDT) |
branch: elpa/lua-mode
commit 8270df5280b3f4ee4b9bdac22cc711405970fe0c
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
lua-is-continuing-statement-p: remove N^2 complexity on openers/closers
---
lua-mode.el | 89 ++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 50 insertions(+), 39 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 8a327db..ef86c98 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1341,8 +1341,8 @@ 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-is-continuing-statement-p (&optional parse-start)
- "Return non-nil if the line at PARSE-START continues a statement.
+(defun lua-is-continuing-statement-p-1 ()
+ "Return non-nil if current lined continues a statement.
More specifically, return the point in the line that is continued.
The criteria for a continuing statement are:
@@ -1351,44 +1351,55 @@ The criteria for a continuing statement are:
OR the first token of the current line is a continuing op
* the expression is not enclosed by a parenthesis"
- (let (return-value (prev-line nil))
- (save-excursion
- (if parse-start (goto-char parse-start))
+ (let (prev-line return-value)
+ (save-excursion (setq prev-line (lua-forward-line-skip-blanks 'back)))
+ (and prev-line
+ ;; 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))))
- ;; If line starts with a series of closer tokens, whether or not the line
- ;; is a continuation line is decided by the opener line, e.g.
- ;;
- ;; x = foo +
- ;; long_function_name(
- ;; long_parameter_1,
- ;; long_parameter_2,
- ;; long_parameter_3,
- ;; ) + long_function_name2({
- ;; long_parameter_1,
- ;; long_parameter_2,
- ;; long_parameter_3,
- ;; })
- ;;
- ;; Final line, "})" is a continuation line, but it is decided by the
- ;; 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)))
-
- (save-excursion (setq prev-line (lua-forward-line-skip-blanks 'back)))
- (and prev-line
- ;; 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)))))
+
+(defun lua-is-continuing-statement-p (&optional parse-start)
+ "Returns non-nil if the line at PARSE-START should be indented as
continuation line.
+
+This true is when the line :
+
+* is continuing a statement itself
+
+* starts with a 1+ block-closer tokens, an top-most block opener is on a
continuation line
+"
+ (save-excursion
+ (if parse-start (goto-char parse-start))
+
+ ;; If line starts with a series of closer tokens, whether or not the line
+ ;; is a continuation line is decided by the opener line, e.g.
+ ;;
+ ;; x = foo +
+ ;; long_function_name(
+ ;; long_parameter_1,
+ ;; long_parameter_2,
+ ;; long_parameter_3,
+ ;; ) + long_function_name2({
+ ;; long_parameter_1,
+ ;; long_parameter_2,
+ ;; long_parameter_3,
+ ;; })
+ ;;
+ ;; Final line, "})" is a continuation line, but it is decided by the
+ ;; 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)))
(defun lua-make-indentation-info-pair (found-token found-pos)
- [nongnu] elpa/lua-mode 50d94a4 373/468: tests: silence "Indenting region..." messages, (continued)
- [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, 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 <=
- [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
- [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