[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/idle-highlight-mode e8f724fec2 35/59: Use a local list of
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/idle-highlight-mode e8f724fec2 35/59: Use a local list of overlays for highlighting |
Date: |
Thu, 7 Jul 2022 12:00:31 -0400 (EDT) |
branch: elpa/idle-highlight-mode
commit e8f724fec25e04282ab2cb62086b29ab59f24ca4
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Use a local list of overlays for highlighting
Add idle-highlight-exclude-point option to exclude
the current word from highlighting.
---
idle-highlight-mode.el | 64 +++++++++++++++++++++++++++++++++++++++++++++-----
readme.rst | 2 ++
2 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index d736ece4dc..e1fa6c86ff 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -78,6 +78,11 @@
:group 'idle-highlight
:type '(repeat symbol))
+(defcustom idle-highlight-exclude-point nil
+ "Exclude the current symbol from highlighting."
+ :group 'idle-highlight
+ :type 'boolean)
+
(defcustom idle-highlight-idle-time 0.5
"Time after which to highlight the word at point."
:group 'idle-highlight
@@ -88,6 +93,9 @@
:type '(repeat symbol)
:group 'idle-highlight)
+(defvar idle-highlight-use-hi-lock-mode nil
+ "Use `hi-lock-mode' option, otherwise use a local list of overlays.")
+
(defvar-local global-idle-highlight-ignore-buffer nil
"When non-nil, the global mode will not be enabled for this buffer.
This variable can also be a predicate function, in which case
@@ -99,6 +107,7 @@ check this buffer.")
;; Internal Variables
(defvar-local idle-highlight--regexp nil "Buffer-local regexp to be
idle-highlighted.")
+(defvar-local idle-highlight--overlays nil "Buffer-local list of overlays.")
;; ---------------------------------------------------------------------------
;; Internal Functions
@@ -139,9 +148,52 @@ Argument POS return faces at this point."
(defun idle-highlight--unhighlight ()
"Clear current highlight."
- (when idle-highlight--regexp
- (unhighlight-regexp idle-highlight--regexp)
- (setq idle-highlight--regexp nil)))
+ (cond
+ (idle-highlight-use-hi-lock-mode
+ (when idle-highlight--regexp
+ (unhighlight-regexp idle-highlight--regexp)
+ (setq idle-highlight--regexp nil)))
+ (t
+ (when idle-highlight--overlays
+ (mapc 'delete-overlay idle-highlight--overlays)
+ (setq idle-highlight--overlays nil)))))
+
+(defsubst idle-highlight--highlight (target beg end)
+ "Highlight TARGET found between BEG and END.h."
+ (idle-highlight--unhighlight)
+ (setq idle-highlight--regexp (concat "\\<" (regexp-quote target) "\\>"))
+ (cond
+ (idle-highlight-use-hi-lock-mode
+ (highlight-regexp idle-highlight--regexp 'idle-highlight))
+ (t
+ (save-excursion
+ (let
+ (
+ (range-list nil)
+ (beg-ex
+ (progn
+ (goto-char (max (point-min) (min beg (window-start))))
+ (beginning-of-line)
+ (point)))
+ (end-ex
+ (progn
+ (goto-char (min (point-max) (max end (window-end))))
+ (beginning-of-line)
+ (end-of-line)
+ (point))))
+
+ (cond
+ (idle-highlight-exclude-point
+ (setq range-list (list (cons beg-ex beg) (cons end end-ex))))
+ (t
+ (setq range-list (cons beg-ex end-ex))))
+
+ (dolist (range range-list)
+ (goto-char (car range))
+ (while (re-search-forward idle-highlight--regexp (cdr range) t)
+ (let ((ov (make-overlay (match-beginning 0) (match-end 0))))
+ (overlay-put ov 'face 'idle-highlight)
+ (push ov idle-highlight--overlays)))))))))
(defun idle-highlight--word-at-point ()
"Highlight the word under the point."
@@ -155,8 +207,7 @@ Argument POS return faces at this point."
(pcase-let* ((`(,beg . ,end) target-range))
(let ((target (buffer-substring-no-properties beg end)))
(when (not (member target idle-highlight-exceptions))
- (setq idle-highlight--regexp (concat "\\<" (regexp-quote target)
"\\>"))
- (highlight-regexp idle-highlight--regexp 'idle-highlight)))))))
+ (idle-highlight--highlight target beg end)))))))
;; ---------------------------------------------------------------------------
@@ -275,7 +326,8 @@ Argument POS return faces at this point."
"Disable the buffer local minor mode."
(idle-highlight--time-buffer-local-disable)
(idle-highlight--unhighlight)
- (kill-local-variable 'idle-highlight--regexp))
+ (kill-local-variable 'idle-highlight--regexp)
+ (kill-local-variable 'idle-highlight--overlays))
(defun idle-highlight--turn-on ()
"Enable command `idle-highlight-mode'."
diff --git a/readme.rst b/readme.rst
index 96a3bcae5c..68208b232b 100644
--- a/readme.rst
+++ b/readme.rst
@@ -28,6 +28,8 @@ Global Settings
Words to exclude from highlighting.
``idle-highlight-exceptions-face`` '(font-lock-keyword-face
font-lock-string-face)
Faces to exclude from highlighting (defaults to ignore keywords & strings).
+``idle-highlight-exclude-point`` nil
+ When non-nil, don't highlight the symbol under the cursor.
``idle-highlight-idle-time``
Delay before highlighting (in seconds).
``global-idle-highlight-ignore-modes`` nil
- [nongnu] elpa/idle-highlight-mode 5418252a11 59/59: Change URL to codeberg, (continued)
- [nongnu] elpa/idle-highlight-mode 5418252a11 59/59: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 53b4e3c855 45/59: Add option idle-highlight-exceptions-syntax, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 459720cd2e 29/59: Add `global-idle-highlight-mode` (globalized minor mode), ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode defcfe2756 54/59: Fix #1 face exceptions interact badly with hl-line-mode, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 1f40f80921 30/59: Remove "end" from idle-highlight-exceptions, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 305e9d4aa0 26/59: Cleanup: remove intermediate symbol type variable, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode eaac86a1a2 49/59: Add idle-highlight-visible-buffers to apply to all buffers, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 7f81263388 11/59: Add configurations for excepted words and what idle time to use., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 7c43cc3d7a 09/59: [Refactor] Lose some weight., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 3d785f0f1d 44/59: Support *-exceptions & *-exceptions-face to be callback functions, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode e8f724fec2 35/59: Use a local list of overlays for highlighting,
ELPA Syncer <=
- [nongnu] elpa/idle-highlight-mode a801e7113f 43/59: Remove 'idle-highlight-use-hi-lock-mode', ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 97047f2574 33/59: Add Campbell Barton as an author, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 98d20252d6 42/59: readme: add "Motivation" & "Other Packages" section, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode d0fcf29c7d 46/59: Cleanup: unnecessary pcase-let* use, ELPA Syncer, 2022/07/07