From: Eshel Yaron Date: Mon, 12 Sep 2022 15:42:24 +0000 (+0300) Subject: ADDED: sweep-colourise-buffer-on-idle user option, on by default X-Git-Tag: v0.2.1~3 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6e5c822fc8b1f08c2dae28c88c616ca0876f3bf3;p=dict.git ADDED: sweep-colourise-buffer-on-idle user option, on by default --- diff --git a/NEWS.org b/NEWS.org index d8d2628..0e459a1 100644 --- a/NEWS.org +++ b/NEWS.org @@ -2,14 +2,14 @@ #+author: Eshel Yaron #+email: me@eshelyaron.com #+language: en -#+options: ':t toc:nil num:nil +#+options: ':t toc:nil num:nil ^:{} #+startup: content indent #+MACRO: version (eval (mapconcat #'number-to-string (save-current-buffer (with-current-buffer (find-file (expand-file-name "sweep.el" (file-name-directory $1))) (package-desc-version (package-buffer-info)))) ".")) This file is about changes in =sweep= up to version {{{version({{{input-file}}})}}}. -* New commands available in sweep {{{version({{{input-file}}})}}} +* New commands available in =sweep= {{{version({{{input-file}}})}}} ** New command =sweep-load-buffer=. @@ -20,12 +20,31 @@ the current buffer by default. Follows file specifications in =sweep-mode= buffers. + * New keybindings in =sweep-mode= buffers ** =C-c C-l= is now bound to =sweep-load-buffer=. ** =C-c C-o= is now bound to =sweep-find-file-at-point=. +* New user options available in =sweep= {{{version({{{input-file}}})}}} + +** New user option =sweep-colourise-buffer-on-idle= + +This option is a boolean flag that determines whether to enable +automatic updating of semantic highlighting in =sweep-mode= buffers. + +** New user option =sweep-colourise-buffer-min-interval= + +This option determines the minimum number of idle seconds that =sweep= +will wait before updating semantic highlighting in a =sweep-mode= +buffer. + +** New user option =sweep-colourise-buffer-max-size= + +This option determines the maximum size of a =sweep-mode= buffer for +which =sweep= will periodically update semantic highlighting on idle. + * New keybindings in =sweep-prefix-map= diff --git a/README.org b/README.org index ac95947..58d396f 100644 --- a/README.org +++ b/README.org @@ -292,7 +292,8 @@ is performed on demand. When a buffer is first opened in =sweep-mode=, its entire contents are analyzed to collect and cache cross reference data, and the buffer is highlighted accordingly. In contrast, when editing and moving around the buffer, a faster, local analysis is -invoked to updated the semantic highlighting. +invoked to updated the semantic highlighting in response to changes in +the buffer. #+FINDEX: sweep-colourise-buffer At any point in a =sweep-mode= buffer, the command =C-c C-c= (or =M-x @@ -300,6 +301,18 @@ sweep-colourise-buffer=) can be used to update the cross reference cache and highlight the buffer accordingly. This may be useful e.g. after defining a new predicate. +#+VINDEX: sweep-colourise-buffer-on-idle +#+VINDEX: sweep-colourise-buffer-max-size +#+VINDEX: sweep-colourise-buffer-min-interval +If the user option =sweep-colourise-buffer-on-idle= is set to non-nil +(as it is by default), =sweep-mode= also updates semantic highlighting +in the buffer whenever Emacs is idle for a reasonable amount of time, +unless the buffer is larger than the value of the +=sweep-colourise-buffer-max-size= user option ( 100,000 by default). +The minimum idle time to wait before automatically updating semantic +highlighting can be set via the user option +=sweep-colourise-buffer-min-interval=. + #+CINDEX: sweep-faces =sweep= defines more than 60 different faces (named sets of properties that determine the appearance of a specific text in Emacs buffers, see diff --git a/sweep.el b/sweep.el index addc416..8a30ea6 100644 --- a/sweep.el +++ b/sweep.el @@ -32,6 +32,12 @@ "SWI-Prolog Embedded in Emacs." :group 'prolog) +(defcustom sweep-colourise-buffer-on-idle t + "If non-nil, update highlighting of `sweep-mode' buffers on idle." + :package-version '((sweep . "0.2.0")) + :type 'boolean + :group 'sweep) + (defcustom sweep-colourise-buffer-max-size 100000 "Maximum buffer size to recolourise on idle." :package-version '((sweep . "0.2.0")) @@ -1345,18 +1351,19 @@ Interactively, POINT is set to the current point." (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) - (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))))) + (when sweep-colourise-buffer-on-idle + (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: