From: Eshel Yaron Date: Mon, 12 Sep 2022 09:53:40 +0000 (+0300) Subject: ENHANCED: Update semantic highlighting on idle timer in sweep-mode X-Git-Tag: v0.2.1~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d1a2913f75385914c880ea3533108e6a77085494;p=dict.git ENHANCED: Update semantic highlighting on idle timer in sweep-mode (sweep-colourise-buffer-max-size): new user option (sweep-colourise-buffer-min-interval): new user option (sweep-mode): setup highlighting on idle timer --- diff --git a/sweep.el b/sweep.el index f3b1929..addc416 100644 --- a/sweep.el +++ b/sweep.el @@ -32,6 +32,18 @@ "SWI-Prolog Embedded in Emacs." :group 'prolog) +(defcustom sweep-colourise-buffer-max-size 100000 + "Maximum buffer size to recolourise on idle." + :package-version '((sweep . "0.2.0")) + :type 'integer + :group 'sweep) + +(defcustom sweep-colourise-buffer-min-interval 2 + "Minimum idle time to wait before recolourising the buffer." + :package-version '((sweep . "0.2.0")) + :type 'float + :group 'sweep) + (defcustom sweep-swipl-path nil "Path to the swipl executable. When non-nil, this is used by the embedded SWI-Prolog runtime to @@ -961,9 +973,9 @@ Interactively, a prefix arg means to prompt for BUFFER." comint-delimiter-argument-list '(?,) comment-start "%") (add-hook 'post-self-insert-hook #'sweep-top-level--post-self-insert-function nil t) - (setq sweep-top-level-timer (run-with-idle-timer 0.2 t #'sweep-colourise-query (current-buffer))) - (add-hook 'completion-at-point-functions #'sweep-completion-at-point-function nil t) (setq sweep-buffer-module "user") + (add-hook 'completion-at-point-functions #'sweep-completion-at-point-function nil t) + (setq sweep-top-level-timer (run-with-idle-timer 0.2 t #'sweep-colourise-query (current-buffer))) (add-hook 'kill-buffer-hook (lambda () (when (timerp sweep-top-level-timer) @@ -1305,6 +1317,9 @@ Interactively, POINT is set to the current point." (xref-make-file-location path line 0)))) matches))) +(defvar-local sweep--timer nil) +(defvar-local sweep--colourise-buffer-duration 0.2) + ;;;###autoload (define-derived-mode sweep-mode prog-mode "sweep" "Major mode for reading and editing Prolog code." @@ -1323,11 +1338,25 @@ Interactively, POINT is set to the current point." nil nil (font-lock-fontify-region-function . sweep-colourise-some-terms))) - (sweep-colourise-buffer) + (let ((time (current-time))) + (sweep-colourise-buffer) + (setq sweep--colourise-buffer-duration (float-time (time-since time)))) (sweep--set-buffer-module) (add-hook 'xref-backend-functions #'sweep--xref-backend nil t) (add-hook 'file-name-at-point-functions #'sweep-file-at-point nil t) - (add-hook 'completion-at-point-functions #'sweep-completion-at-point-function nil t)) + (add-hook 'completion-at-point-functions #'sweep-completion-at-point-function nil t) + (setq sweep--timer (run-with-idle-timer (max sweep-colourise-buffer-min-interval + (* 10 sweep--colourise-buffer-duration)) + t + (let ((buffer (current-buffer))) + (lambda () + (unless (< sweep-colourise-buffer-max-size + (buffer-size buffer)) + (sweep-colourise-buffer buffer)))))) + (add-hook 'kill-buffer-hook + (lambda () + (when (timerp sweep--timer) + (cancel-timer sweep--timer))))) ;;;; Testing: