[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode bda4fbd 075/468: lua-calculate-unindentation: upd
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode bda4fbd 075/468: lua-calculate-unindentation: update docs, remove extraneous catch |
Date: |
Thu, 5 Aug 2021 04:58:11 -0400 (EDT) |
branch: elpa/lua-mode
commit bda4fbd54fb64ee37a357b5ea8b74f5ef2f8d36b
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>
lua-calculate-unindentation: update docs, remove extraneous catch
---
lua-mode.el | 47 +++++++++++++++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 4c011a3..9e69ff7 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -780,30 +780,49 @@ one."
(if (lua-is-continuing-statement-p) (- lua-indent-level) 0)))))
(defconst lua-unindentation-regexp
+ ;; Compare the following situations:
+ ;; { {
+ ;; a, a,
+ ;; b, b,
+ ;; } c}
+ ;;
+ ;; Basically, if close-token is prepended with some expression, such
+ ;; expression should still be indented and thus any close-tokens
+ ;; after an expression doesn't unindent the line.
+ ;;
+ ;; Whitespace and semicolons aren't an expression and may be skipped
+ ;; (technically, multiline comment --[[ ]] ending on the same line
+ ;; might also be skipped, but it's not handled properly right now).
+ ;;
+ ;; skip whitespaces and semicolons, closing keywords/parentheses
(concat "[\\s ;]*"
"\\(?1:\\_<" (regexp-opt '("else" "elseif" "until" "end")) "\\_>"
"\\|" (regexp-opt '("]" "}" ")")) "\\)"))
(defun lua-calculate-unindentation (&optional parse-start)
- "Return amount, by which this line should be shifted left.
-Look for an uninterrupted sequence of block-closing tokens that starts
-at the beginning of the line. For each of these tokens, shift indentation
-to the left by the amount specified in lua-indent-level."
- (let ((indentation-modifier 0)
+ "Return amount, by which this line should be unindented.
+
+Starting from the beginning of the line, look for an sequence of
+block-closing tokens with only whitespace/semicolons in between them.
+For each of these tokens, shift indentation to the left by the amount
+specified in lua-indent-level.
+
+If PARSE-START is not nil, start from the beginning of the line that
+contains position PARSE-START."
+ (let ((unindentation-accumulator 0)
(case-fold-search nil)
(block-token nil))
(save-excursion
(if parse-start (goto-char parse-start))
(back-to-indentation)
- ;; Look for the block-closing token sequence
- (catch 'stop
- (while (and (looking-at lua-unindentation-regexp)
- (not (lua-comment-or-string-p)))
- (let ((last-token (match-string 1)))
- (setq indentation-modifier (+ indentation-modifier
- lua-indent-level))
- (forward-char (length (match-string 0))))))
- indentation-modifier)))
+
+ (while (and (looking-at lua-unindentation-regexp)
+ (not (lua-comment-or-string-p)))
+ (let ((last-token (match-string 1)))
+ (setq unindentation-accumulator (+ unindentation-accumulator
+ lua-indent-level))
+ (forward-char (length (match-string 0)))))
+ unindentation-accumulator)))
(defun lua-calculate-indentation (&optional parse-start)
"Return appropriate indentation for current line as Lua code.
- [nongnu] elpa/lua-mode 3ba5bf1 059/468: Redo lua-toggle-electric-state, remove extra function lua-calculate-state, (continued)
- [nongnu] elpa/lua-mode 3ba5bf1 059/468: Redo lua-toggle-electric-state, remove extra function lua-calculate-state, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e610db4 060/468: lua-make-indentation-info-pair: readability refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cc46763 061/468: Add some comments, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b2860f1 062/468: lua-setup-keymap: improve readability, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7935b5f 064/468: Fix previous commit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 85d26f8 065/468: lua-mode-map: initialize as soon as lua-mode is loaded (previously waited for call to lua-mode), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3339da6 067/468: lua-prefix-key: auto-convert from/to character, update bindings automagically, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5842703 068/468: Add TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8165775 069/468: Fix lua-set-prefix message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6b1d389 074/468: lua-calculate-unindentation: skip semicolons as well, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bda4fbd 075/468: lua-calculate-unindentation: update docs, remove extraneous catch,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode a20b08e 078/468: lua-indent-line: remove extra variable shift-amt, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c0d6f80 079/468: Add markdown README, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08cff6e 081/468: Implement basic multiline-aware functionality, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dfc3b78 083/468: Preserve buffer-modified-p state when (un-)marking multiline delimiters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7920d17 087/468: lua-mark-all-multiline-literals: if region is active, limit to region boundaries, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a22b3c 100/468: Allow lua-start-process to be called interactively., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3ed448 106/468: Make dist with git-archive, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 742180e 125/468: lua-automark-multiline: add lua-automark-multiline-maxsize variable to prevent long waits on big files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0b3df35 135/468: Fix string content indentation: it's now indented by indent-level relative to indentation of the line where string/comment literal starts (issue #6), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5aa6f9e 042/468: Patch from Reuben: fix long string colouring problem, Philip Kaludercic, 2021/08/05