[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 8d28342 187/468: Revisit block-close unindentatio
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 8d28342 187/468: Revisit block-close unindentation logic (issue #26) |
Date: |
Thu, 5 Aug 2021 04:58:33 -0400 (EDT) |
branch: elpa/lua-mode
commit 8d28342675f6f7a258a142b4b8856ff0700906f8
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Revisit block-close unindentation logic (issue #26)
- completely rewritten left-shifter expression regexp
- reduced extra parsing work in cases when block-start token is already
at (current-indentation).
---
lua-mode.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 67 insertions(+), 12 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index acd11be..38a1f65 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1140,24 +1140,79 @@ one."
(- (cdr indentation-info) (current-indentation))
(cdr indentation-info))))
-(defun lua-point-is-after-left-shifter-p ()
- "Check if point is at a left-shifter.
-A left-shifter is a partial lua expression which should be ignored for line up
purposes when closing a block. An example of this is:
+
+(eval-when-compile
+ (defconst lua--function-name-rx
+ '(seq symbol-start
+ (+ (any alnum "_"))
+ (* "." (+ (any alnum "_")))
+ (? ":" (+ (any alnum "_")))
+ symbol-end)
+ "Lua function name regexp in `rx'-SEXP format."))
+
+
+(defconst lua--left-shifter-regexp
+ (eval-when-compile
+ (rx
+ ;; All matches are returned via same group 1, even those that can match
+ ;; simultaneously. This is correct as long as, according to the manual
[1]:
+ ;;
+ ;; There is no particular restriction on the numbering, e.g., you can
+ ;; have several groups with the same number in which case the last one
+ ;; to match (i.e., the rightmost match) will win.
+ ;;
+ ;; 1. C-h i m "elisp" T f "regexp backslash" // i really need to stop
+ ;; forgetting things.
+ (or (seq (group-n 1 symbol-start "local" (+ blank)) "function" symbol-end)
+ (seq (group-n 1 (eval lua--function-name-rx) (* blank)) (any "{("))
+ (seq (group-n 1 (or
+ ;; assignment statement prefix
+ (seq (* nonl) (not (any "<=>~")) "=" (* blank))
+ ;; return statement prefix
+ (seq word-start "return" word-end (* blank))))
+ ;; right hand side
+ (or "{"
+ "function"
+ (seq (group-n 1 (eval lua--function-name-rx) (* blank))
+ (any "({")))))))
+
+ "Regular expression that matches left-shifter expression.
+
+Left-shifter expression is defined as follows. If a block
+follows a left-shifter expression, its contents & block-close
+token should be indented relative to left-shifter expression
+indentation rather then to block-open token.
+
+For example:
+ -- 'local a = ' is a left-shifter expression
+ -- 'function' is a block-open token
local a = function()
- ....
+ -- block contents is indented relative to left-shifter
+ foobarbaz()
+ -- block-end token is unindented to left-shifter indentation
end
- ^ ^
- | +- not here
- +- Close here"
+
+The following left-shifter expressions are currently handled:
+1. local function definition with function block, begin-end
+2. function call with arguments block, () or {}
+3. assignment/return statement with
+ - table constructor block, {}
+ - function call arguments block, () or {} block
+ - function expression a.k.a. lambda, begin-end block.")
+
+
+(defun lua-point-is-after-left-shifter-p ()
+ "Check if point is right after a left-shifter expression.
+
+See `lua--left-shifter-regexp' for description & example of
+left-shifter expression. "
(save-excursion
(let ((old-point (point)))
(back-to-indentation)
(and
- (or (looking-at "local\\s +\\(?:\\(?:\\sw\\|\\s_\\)+\\s *\\(,\\s
*\\(?:\\sw\\|\\s_\\)+\\s *\\)*=\\s *\\)?")
- ;; This is too generic, and will screw up a lot of indentations.
Will need
- ;; a better regexp for assignments
- (looking-at "[^=]*=\\s *"))
- (= old-point (match-end 0))))))
+ (/= (point) old-point)
+ (looking-at lua--left-shifter-regexp)
+ (= old-point (match-end 1))))))
(defun lua-calculate-indentation-override (&optional parse-start)
"Return overriding indentation amount for special cases.
- [nongnu] elpa/lua-mode 993e042 113/468: Merge branch 'multiline_literals', (continued)
- [nongnu] elpa/lua-mode 993e042 113/468: Merge branch 'multiline_literals', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d742cae 116/468: lua-mark-all-multiline-literals: comment out debug message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5542927 122/468: lua-automark-multiline: add function to enable automatical multiline construct marking when emacs is idle, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6beb586 123/468: Add customizable lua-automark-multiline-interval variable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode eab8fc0 136/468: Move docstrings to the end of constants., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a5cc71f 149/468: Bump version & URL, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode caa3d0c 162/468: lua-jump-to-traceback: fix compilation warning about goto-line func, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fb53190 164/468: First part of the fix for #34, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 086736c 168/468: #36 Don't continue lines on some keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b9541ce 173/468: lua-send-proc is now an alias to lua-send-defun, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8d28342 187/468: Revisit block-close unindentation logic (issue #26),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode b1ac542 191/468: Major refactoring of font-lock-keywords:, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 57c696c 192/468: Add var name highlighting in "for x, y in ..." construct, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 97ce427 198/468: Restore compatibility with Emacs23 broken by commit 8d28342, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ff3f5e1 199/468: lua-font-lock-keywords: don't eval-when-compile initial value, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2a0314b 200/468: Improve multiline highlighting via font-lock-syntactic-keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cd5c071 201/468: Clean up lua-mode start-up function a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b195cdc 205/468: Bump TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cee511c 206/468: for/local varname highlighting: match '=' at EOL properly, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a1dc850 207/468: Post-refactoring fix: evaluate string variables in font-lock-defaults value, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8ffd075 208/468: lua-calculate-indentation-info: non-functional refactoring, Philip Kaludercic, 2021/08/05