[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode ec26ea4 155/468: Fix: Single-line conditionals ca
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode ec26ea4 155/468: Fix: Single-line conditionals can confuse indenting (#22) |
Date: |
Thu, 5 Aug 2021 04:58:27 -0400 (EDT) |
branch: elpa/lua-mode
commit ec26ea4a1a77db7293ddee58abfdfd88dfcf0cb4
Author: Vedat Hallac <vedathallac@gmail.com>
Commit: Vedat Hallac <vedathallac@gmail.com>
Fix: Single-line conditionals can confuse indenting (#22)
Instead of just fixing the problem, I've also modified the way
indentation info list is constructed. Instead of blindly constructing
the list and then cleaning it up, I process elements as they are added.
---
lua-mode.el | 58 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 3b6c6fc..8f37dbd 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -849,31 +849,30 @@ use standalone."
;; end of a block matched
(- lua-indent-level))))))
-(defun lua-cleanup-indentation-info (info)
- "Cleanup the list of indentation information.
-There are two tokens that cause list cleanup: remove-matching,
-and replace matching. These tokens are considered cleanup tokens.
-
-When a remove-matching token is found, the next non cleanup token
-is removed from list.
-
-When a replace-matching token is found, the next non-cleanup
-token is removed from the list, and the cdr of the
-replace-matching token is inserted in its place."
- (let (value
- (erase-count 0))
- (dolist (elt info value)
- (cond
- ( (eq 'remove-matching (car elt))
- (setq erase-count (1+ erase-count)))
- ( (eq 'replace-matching (car elt))
- (setq value (cons (cdr elt) value))
- (setq erase-count (1+ erase-count)))
- ( t
- (if (= erase-count 0)
- (setq value (cons elt value))
- (setq erase-count (1- erase-count))))))
- (reverse value)))
+(defun lua-add-indentation-info-pair (pair info)
+ "Add the given indentation info pair to the list of indentation information.
+This function has special case handling for two tokens: remove-matching,
+and replace-matching. These two tokens are cleanup tokens that remove or
+alter the effect of a previously recorded indentation info.
+
+When a remove-matching token is encountered, the last recorded info, i.e.
+the car of the list is removed. This is used to roll-back an indentation of a
+block opening statement when it is closed.
+
+When a replace-matching token is seen, the last recorded info is removed,
+and the cdr of the replace-matching info is added in its place. This is used
+when a middle-of the block (the only case is 'else') is seen on the same line
+the block is opened."
+ (cond
+ ( (eq 'remove-matching (car pair))
+ ; Remove head of list
+ (cdr info))
+ ( (eq 'replace-matching (car pair))
+ ; remove head of list, and add the cdr of pair instead
+ (cons (cdr pair) (cdr info)))
+ ( t
+ ; Just add the pair
+ (cons pair info))))
(defun lua-calculate-indentation-info (&optional parse-start parse-end)
"For each block token on the line, computes how it affects the indentation.
@@ -901,10 +900,11 @@ and relative each, and the shift/column to indent to."
(found-end (match-end 0))
(data (match-data)))
(setq indentation-info
- (cons (lua-make-indentation-info-pair found-token found-pos)
indentation-info))))
-
- (or (and indentation-info (lua-cleanup-indentation-info
indentation-info))
- (list (cons 'absolute start-indentation)))))))
+ (lua-add-indentation-info-pair
+ (lua-make-indentation-info-pair found-token found-pos)
+ indentation-info))))
+ (or indentation-info
+ (list (cons 'absolute start-indentation)))))))
(defun lua-accumulate-indentation-info (info)
"Accumulates the indentation information previously calculated by
- [nongnu] elpa/lua-mode 8c28ed5 095/468: Add utility funcs lua-inside-multiline-p and lua-get-multiline-start, (continued)
- [nongnu] elpa/lua-mode 8c28ed5 095/468: Add utility funcs lua-inside-multiline-p and lua-get-multiline-start, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 79ff5d0 110/468: lua-postprocess-output-buffer: replace save-excursion/set-buffer with with-current-buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9b929d4 115/468: Reorder operations in release target so that no pushing/sending is done if master differs from remotes/origin/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9c94413 118/468: lua-comment/-string-p funcs: wrap into save-excursion because syntax-ppss alters point position, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e470943 131/468: lua-mode-abbrev-table: mark abbreviations as :system so that they're not counted as user-defined and are not saved automatically (issue #8), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f4ab885 144/468: lua-cont-eol-regexp: add "return" keyword too, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 01d0f38 146/468: Bump thanks section, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ded7566 151/468: Add lua-with-silent-modifications macro, use it to fix the undo history issue (#21), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 37f51cb 152/468: Fix multiline literal highlighting for long strings (#20), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b33f255 154/468: Make lua-mode-hook customizable., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ec26ea4 155/468: Fix: Single-line conditionals can confuse indenting (#22),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode fa3470e 157/468: Merge pull request #28 from rrthomas/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ced5226 161/468: lua-with-silent-modifications: fix old style backquotes in fallback implementation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bba7fc0 163/468: Fix byte-compilation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d128a74 170/468: Add initial version of test/indentation/README.md, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4399254 177/468: Merge pull request #39, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08ff6ea 183/468: Merge remote-tracking branch 'origin/master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8aa98ae 185/468: Non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7605d2c 186/468: lua-font-lock-keywords: rewrite poorly written regexp (issue #47), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c24f16e 188/468: Put Lua reference resources into TODO file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5d81110 196/468: Wrap symbols required during compilation into (eval-when compile ...), Philip Kaludercic, 2021/08/05