branch: master
commit aaf48357875c366c652eb842229e0c284e98566b
Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>

    Remove let-varlist data structure. Cleanup.
---
 context-coloring.el |  147 ++++++++++++++-------------------------------------
 1 files changed, 40 insertions(+), 107 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 674d669..174edde 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -276,36 +276,24 @@ generated by `js2-mode'."
 
 ;;; Emacs Lisp colorization
 
-(defsubst context-coloring-forward-sws ()
-  "Move forward through whitespace and comments."
-  (while (forward-comment 1)))
-
-(defsubst context-coloring-forward-sexp-position ()
-  "Like vanilla `forward-sexp', but just return the position."
-  (scan-sexps (point) 1))
-
-(defsubst context-coloring-elisp-identifier-syntax-p (syntax-code)
-  (or (= 2 syntax-code)
-      (= 3 syntax-code)))
-
-(defsubst context-coloring-open-parenthesis-p (syntax-code)
-  (= 4 syntax-code))
-
-(defsubst context-coloring-close-parenthesis-p (syntax-code)
-  (= 5 syntax-code))
+(defvar context-coloring-parse-interruptable-p t
+  "Set this to nil to force parse to continue until finished.")
 
-(defsubst context-coloring-expression-prefix-p (syntax-code)
-  (= 6 syntax-code))
+(defconst context-coloring-elisp-iterations-per-pause 1000
+  "Pause after this many iterations to check for user input.
+If user input is pending, stop the parse.  This makes for a
+smoother user experience for large files.
 
-(defsubst context-coloring-at-open-parenthesis-p ()
-  (= 4 (logand #xFFFF (car (syntax-after (point))))))
+As of this writing, emacs lisp colorization seems to run at about
+60,000 iterations per second.  A default value of 1000 should
+provide visually \"instant\" updates at 60 frames per second.")
 
-(defsubst context-coloring-ppss-depth (ppss)
-  ;; Same as (nth 0 ppss).
-  (car ppss))
+(defsubst context-coloring-forward-sws ()
+  "Move forward through whitespace and comments."
+  (while (forward-comment 1)))
 
-(defsubst context-coloring-at-stack-depth-p (stack depth)
-  (= (plist-get (car stack) :depth) depth))
+(defsubst context-coloring-get-syntax-code ()
+  (syntax-class (syntax-after (point))))
 
 (defsubst context-coloring-exact-regexp (word)
   "Create a regexp that matches exactly WORD."
@@ -351,36 +339,21 @@ generated by `js2-mode'."
 (defconst context-coloring-COMMA-CHAR (string-to-char ","))
 (defconst context-coloring-BACKTICK-CHAR (string-to-char "`"))
 
-(defvar context-coloring-parse-interruptable-p t
-  "Set this to nil to force parse to continue until finished.")
-
-(defconst context-coloring-elisp-iterations-per-pause 1000
-  "Pause after this many iterations to check for user input.
-If user input is pending, stop the parse.  This makes for a
-smoother user experience for large files.
-
-As of this writing, emacs lisp colorization seems to run at about
-60,000 iterations per second.  A default value of 1000 should
-provide visually \"instant\" updates at 60 frames per second.")
-
-(defun context-coloring-get-syntax-code ()
-  (syntax-class (syntax-after (point))))
-
 (defvar context-coloring-elisp-scope-stack '())
 
 (defsubst context-coloring-elisp-make-scope (level)
   (list
    :level level
-   :variables (make-hash-table :test 'equal)))
+   :variables '()))
 
 (defsubst context-coloring-elisp-scope-get-level (scope)
   (plist-get scope :level))
 
 (defsubst context-coloring-elisp-scope-add-variable (scope variable)
-  (puthash variable t (plist-get scope :variables)))
+  (plist-put scope :variables (cons variable (plist-get scope :variables))))
 
-(defsubst context-coloring-elisp-scope-get-variable (scope variable)
-  (gethash variable (plist-get scope :variables)))
+(defsubst context-coloring-elisp-scope-has-variable (scope variable)
+  (member variable (plist-get scope :variables)))
 
 (defsubst context-coloring-elisp-get-variable-level (variable)
   (let* ((scope-stack context-coloring-elisp-scope-stack)
@@ -389,69 +362,32 @@ provide visually \"instant\" updates at 60 frames per 
second.")
     (while (and scope-stack (not level))
       (setq scope (car scope-stack))
       (cond
-       ((context-coloring-elisp-scope-get-variable scope variable)
+       ((context-coloring-elisp-scope-has-variable scope variable)
         (setq level (context-coloring-elisp-scope-get-level scope)))
        (t
         (setq scope-stack (cdr scope-stack)))))
     ;; Assume a global variable.
     (or level 0)))
 
-(defun context-coloring-elisp-push-scope ()
+(defsubst context-coloring-elisp-current-scope-level ()
+  (cond
+   ((car context-coloring-elisp-scope-stack)
+    (context-coloring-elisp-scope-get-level (car 
context-coloring-elisp-scope-stack)))
+   (t
+    0)))
+
+(defsubst context-coloring-elisp-push-scope ()
   (push (context-coloring-elisp-make-scope
          (1+ (context-coloring-elisp-current-scope-level)))
         context-coloring-elisp-scope-stack))
 
-(defun context-coloring-elisp-pop-scope ()
+(defsubst context-coloring-elisp-pop-scope ()
   (pop context-coloring-elisp-scope-stack))
 
-(defun context-coloring-elisp-add-variable (variable)
-  (let ((current-scope (car context-coloring-elisp-scope-stack)))
-    (context-coloring-elisp-scope-add-variable current-scope variable)))
-
-(defun context-coloring-elisp-current-scope-level ()
-  (let ((current-scope (car context-coloring-elisp-scope-stack)))
-    (cond
-     (current-scope
-      (context-coloring-elisp-scope-get-level current-scope))
-     (t
-      0))))
-
-(defsubst context-coloring-elisp-make-let-varlist (type)
-  (list
-   :type type
-   :vars '()))
-
-(defsubst context-coloring-elisp-let-varlist-get-type (let-varlist)
-  (plist-get let-varlist :type))
-
-(defsubst context-coloring-elisp-let-varlist-get-vars (let-varlist)
-  (plist-get let-varlist :vars))
-
-(defsubst context-coloring-elisp-let-varlist-set-vars (let-varlist vars)
-  (plist-put let-varlist :vars vars))
-
-(defsubst context-coloring-elisp-let-varlist-add-var (let-varlist var)
-  (plist-put let-varlist :vars (cons var (plist-get let-varlist :vars))))
-
-(defsubst context-coloring-elisp-let-varlist-pop-vars (let-varlist)
-  (let* ((type (context-coloring-elisp-let-varlist-get-type let-varlist))
-         (vars (context-coloring-elisp-let-varlist-get-vars let-varlist))
-         (popped (cond
-                  ;; `let' binds all at once at the end.
-                  ((eq type 'let)
-                   (prog1
-                       vars
-                     (context-coloring-elisp-let-varlist-set-vars
-                      let-varlist '())))
-                  ;; `let*' binds incrementally.
-                  ((eq type 'let*)
-                   (prog1
-                       (list (car vars))
-                     (context-coloring-elisp-let-varlist-set-vars
-                      let-varlist (cdr vars)))))))
-    (while popped
-      (context-coloring-elisp-add-variable (car popped))
-      (setq popped (cdr popped)))))
+(defsubst context-coloring-elisp-add-variable (variable)
+  (context-coloring-elisp-scope-add-variable
+   (car context-coloring-elisp-scope-stack)
+   variable))
 
 (defun context-coloring-elisp-parse-arg (callback)
   (let (arg-pos
@@ -469,13 +405,11 @@ provide visually \"instant\" updates at 60 frames per 
second.")
       (funcall callback arg-string))))
 
 (defun context-coloring-elisp-parse-let-varlist (type)
-  (let ((let-varlist (context-coloring-elisp-make-let-varlist type))
+  (let ((varlist '())
         syntax-code)
     ;; Enter.
     (forward-char)
-    (while (/= (progn
-                 (setq syntax-code (context-coloring-get-syntax-code))
-                 syntax-code)
+    (while (/= (setq syntax-code (context-coloring-get-syntax-code))
                context-coloring-CLOSE-PARENTHESIS-CODE)
       (cond
        ((= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
@@ -486,7 +420,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
                   (= syntax-code context-coloring-SYMBOL-CODE))
           (context-coloring-elisp-parse-arg
            (lambda (var)
-             (context-coloring-elisp-let-varlist-add-var let-varlist var)))
+             (push var varlist)))
           (context-coloring-forward-sws)
           (setq syntax-code (context-coloring-get-syntax-code))
           (when (/= syntax-code context-coloring-CLOSE-PARENTHESIS-CODE)
@@ -498,12 +432,13 @@ provide visually \"instant\" updates at 60 frames per 
second.")
             (= syntax-code context-coloring-SYMBOL-CODE))
         (context-coloring-elisp-parse-arg
          (lambda (var)
-           (context-coloring-elisp-let-varlist-add-var let-varlist var)))))
+           (push var varlist)))))
       (when (eq type 'let*)
-        (context-coloring-elisp-let-varlist-pop-vars let-varlist))
+        (context-coloring-elisp-add-variable (pop varlist)))
       (context-coloring-forward-sws))
     (when (eq type 'let)
-      (context-coloring-elisp-let-varlist-pop-vars let-varlist))
+      (while varlist
+        (context-coloring-elisp-add-variable (pop varlist))))
     ;; Exit.
     (forward-char)))
 
@@ -511,9 +446,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
   (let (syntax-code)
     ;; Enter.
     (forward-char)
-    (while (/= (progn
-                 (setq syntax-code (context-coloring-get-syntax-code))
-                 syntax-code)
+    (while (/= (setq syntax-code (context-coloring-get-syntax-code))
                context-coloring-CLOSE-PARENTHESIS-CODE)
       (cond
        ((or (= syntax-code context-coloring-WORD-CODE)

Reply via email to