From a5561959ebcdca49de518b7e8a40785bde5a52bf Mon Sep 17 00:00:00 2001 From: Jackson Ray Hamilton Date: Sun, 17 May 2015 13:37:28 -0700 Subject: [PATCH] Tweak iteration values, add logging. --- context-coloring.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 22097a53a..a51394712 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -406,11 +406,17 @@ generated by `js2-mode'." (defvar context-coloring-parse-interruptable-p t "Set this to nil to force parse to continue until finished.") -(defvar context-coloring-tokens-per-pause 25 - "Pause after this many statements to check for user input. +(defvar context-coloring-emacs-lisp-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. This appears to be -more or less how Eclipse, IntelliJ and other editors work.") +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.") + +(defvar context-coloring-verbose-parse t + "Log useful information pertaining to a parse.") (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." @@ -418,8 +424,9 @@ more or less how Eclipse, IntelliJ and other editors work.") (save-excursion ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) - (let* ((inhibit-point-motion-hooks t) - (token-count 0) + (let* ((start-time (float-time)) + (inhibit-point-motion-hooks t) + (iteration-count 0) (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) @@ -460,8 +467,8 @@ more or less how Eclipse, IntelliJ and other editors work.") (while (> end (progn (skip-syntax-forward "^()w_'" end) (point))) (and context-coloring-parse-interruptable-p - (zerop (% (setq token-count (1+ token-count)) - context-coloring-tokens-per-pause)) + (zerop (% (setq iteration-count (1+ iteration-count)) + context-coloring-emacs-lisp-iterations-per-pause)) (input-pending-p) (throw 'interrupted t)) (setq token-pos (point)) @@ -693,7 +700,10 @@ more or less how Eclipse, IntelliJ and other editors work.") (context-coloring-scope-add-variable (car scope-stack) (car popped-vars)) (setq popped-vars (cdr popped-vars)))) - )))) + )) + (when context-coloring-verbose-parse + (message "Elapsed: %s; iterations: %s" + (- (float-time) start-time) iteration-count)))) (context-coloring-maybe-colorize-comments-and-strings))) -- 2.39.2