branch: elpa/lua-mode
commit 4a45c6d40d927f6272b01c9f38b0fc411a7c2220
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
lua-make-indentation-info-pair: optimize "same-line" checks
---
lua-mode.el | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index a60bc4c..8a327db 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1430,9 +1430,10 @@ Don't use standalone."
;; nullify a previous then if on the same line.
((member found-token (list "until" "elseif"))
(save-excursion
- (let ((line (line-number-at-pos)))
- (if (and (lua-goto-matching-block-token found-pos 'backward)
- (= line (line-number-at-pos)))
+ (let* ((line-beginning (line-beginning-position))
+ (same-line (and (lua-goto-matching-block-token found-pos
'backward)
+ (<= line-beginning (point)))))
+ (if same-line
(cons 'remove-matching 0)
(cons 'relative 0)))))
@@ -1442,9 +1443,10 @@ Don't use standalone."
;; line will remove the effect of the else.
((string-equal found-token "else")
(save-excursion
- (let ((line (line-number-at-pos)))
- (if (and (lua-goto-matching-block-token found-pos 'backward)
- (= line (line-number-at-pos)))
+ (let* ((line-beginning (line-beginning-position))
+ (same-line (and (lua-goto-matching-block-token found-pos
'backward)
+ (<= line-beginning (point)))))
+ (if same-line
(cons 'replace-matching (cons 'relative lua-indent-level))
(cons 'relative lua-indent-level)))))
@@ -1453,9 +1455,10 @@ Don't use standalone."
;; indentation back to the matching block opener.
((member found-token (list ")" "}" "]" "end"))
(save-excursion
- (let ((line (line-number-at-pos)))
- (lua-goto-matching-block-token found-pos 'backward)
- (if (/= line (line-number-at-pos))
+ (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)))))