emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/lua-mode a52e6b1 070/468: lua-left-shift-regexp: optimize


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode a52e6b1 070/468: lua-left-shift-regexp: optimize and greatly reduce size
Date: Thu, 5 Aug 2021 04:58:10 -0400 (EDT)

branch: elpa/lua-mode
commit a52e6b1cb70b0ece1d1b7302aff189e9587c061d
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>

    lua-left-shift-regexp: optimize and greatly reduce size
---
 lua-mode.el | 40 +++++-----------------------------------
 1 file changed, 5 insertions(+), 35 deletions(-)

diff --git a/lua-mode.el b/lua-mode.el
index 0de813b..834f737 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -784,38 +784,10 @@ one."
          (cdr indentation-info)
          (if (lua-is-continuing-statement-p) (- lua-indent-level) 0)))))
 
-(defconst lua-left-shift-regexp-1
-  (concat "\\("
-          "\\(\\_<" (regexp-opt '("else" "elseif" "until") t)
-          "\\_>\\)\\($\\|\\s +\\)"
-          "\\)"))
-
-(defconst lua-left-shift-regexp-2
-  (concat "\\(\\_<"
-          (regexp-opt '("end") t)
-          "\\_>\\)"))
-
-(defconst lua-left-shift-regexp
-  ;; "else", "elseif", "until" followed by whitespace, or "end"/closing
-  ;; brackets followed by
-  ;; whitespace, punctuation, or closing parentheses
-  (concat lua-left-shift-regexp-1
-          "\\|\\(\\("
-          lua-left-shift-regexp-2
-          "\\|\\("
-          (regexp-opt '("]" "}" ")"))
-          "\\)\\)\\($\\|\\(\\s \\|\\s.\\)*\\)"
-          "\\)"))
-
-(defconst lua-left-shift-pos-1
-  2)
-
-(defconst lua-left-shift-pos-2
-  (+ 3 (regexp-opt-depth lua-left-shift-regexp-1)))
-
-(defconst lua-left-shift-pos-3
-  (+ lua-left-shift-pos-2
-     (regexp-opt-depth lua-left-shift-regexp-2)))
+(defconst lua-unindentation-regexp
+  (concat "\\s *" ;; else/elseif/until/end/"]"/"}"/")"
+          "\\(?1:\\_<" (regexp-opt '("else" "elseif" "until" "end")) "\\_>"
+          "\\|" (regexp-opt '("]" "}" ")")) "\\)"))
 
 (defun lua-calculate-indentation-left-shift (&optional parse-start)
   "Return amount, by which this line should be shifted left.
@@ -833,9 +805,7 @@ to the left by the amount specified in lua-indent-level."
       (catch 'stop
         (while (and (looking-at lua-left-shift-regexp)
                     (not (lua-comment-or-string-p)))
-          (let ((last-token (or (match-string lua-left-shift-pos-1)
-                                (match-string lua-left-shift-pos-2)
-                                (match-string lua-left-shift-pos-3))))
+          (let ((last-token (or (match-string 1) (match-string 2))))
             (if (not block-token) (setq block-token last-token))
             (if (not (string-equal block-token last-token)) (throw 'stop nil))
             (setq indentation-modifier (+ indentation-modifier



reply via email to

[Prev in Thread] Current Thread [Next in Thread]