[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/idle-highlight-mode 4f41607fa1 31/59: Add idle-highlight-e
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/idle-highlight-mode 4f41607fa1 31/59: Add idle-highlight-exceptions-face |
Date: |
Thu, 7 Jul 2022 12:00:31 -0400 (EDT) |
branch: elpa/idle-highlight-mode
commit 4f41607fa11eab935262b8dc8c8d684c8cd82b08
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add idle-highlight-exceptions-face
Support excluding words by face, this allows including words
in strings which was previously not possible as strings
were always excluded.
---
idle-highlight-mode.el | 44 +++++++++++++++++++++++++++++++++++++++-----
readme.rst | 4 +++-
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index 17f4ee289a..2abc0a4e1b 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -73,6 +73,11 @@
:group 'idle-highlight
:type '(repeat string))
+(defcustom idle-highlight-exceptions-face '(font-lock-keyword-face
font-lock-string-face)
+ "List of exception faces."
+ :group 'idle-highlight
+ :type '(repeat symbol))
+
(defcustom idle-highlight-idle-time 0.5
"Time after which to highlight the word at point."
:group 'idle-highlight
@@ -98,10 +103,39 @@ check this buffer.")
;; ---------------------------------------------------------------------------
;; Internal Functions
-(defsubst idle-highlight--ignore-context ()
- "Return non-nil when in a context that should be ignored."
- ;; In a string.
- (nth 3 (syntax-ppss)))
+(defun idle-highlight--faces-at-point (pos)
+ "Add the named faces that the `read-face-name' or `face' property use.
+Argument POS return faces at this point."
+ (let
+ ( ;; List of faces to return.
+ (faces nil)
+ (faceprop (or (get-char-property pos 'read-face-name) (get-char-property
pos 'face))))
+ (cond
+ ((facep faceprop)
+ (push faceprop faces))
+ ((face-list-p faceprop)
+ (dolist (face faceprop)
+ (when (facep face)
+ (push face faces)))))
+ faces))
+
+(defun idle-highlight--check-faces-at-point (pos)
+ "Check if the position POS has faces that match the exclude argument."
+ (cond
+ (idle-highlight-exceptions-face
+ (let
+ (
+ (result t)
+ (faces-at-pos (idle-highlight--faces-at-point pos)))
+ (while faces-at-pos
+ (let ((face (pop faces-at-pos)))
+ (when (memq face idle-highlight-exceptions-face)
+ (setq result nil)
+ ;; Break.
+ (setq faces-at-pos nil))))
+ result))
+ (t ;; Default to true, if there are no exceptions.
+ t)))
(defsubst idle-highlight--unhighlight ()
"Clear current highlight."
@@ -115,7 +149,7 @@ check this buffer.")
(let ((target-range (bounds-of-thing-at-point 'symbol)))
(when
(and
- target-range (not (idle-highlight--ignore-context))
+ target-range (idle-highlight--check-faces-at-point (point))
;; Symbol characters.
(looking-at-p "\\s_\\|\\sw"))
(pcase-let* ((`(,beg . ,end) target-range))
diff --git a/readme.rst b/readme.rst
index 0b2e03f5ff..b0966bbb7d 100644
--- a/readme.rst
+++ b/readme.rst
@@ -24,7 +24,7 @@ Global Settings
``idle-highlight``
Face used for highlighting the symbol.
-``idle-highlight-exceptions``
+``idle-highlight-exceptions`` nil
Words to exclude from highlighting.
You may wish to set this to a different value for each mode, e.g:
@@ -33,6 +33,8 @@ Global Settings
(setq-local idle-highlight-exceptions '("end" "begin"))
+``idle-highlight-exceptions-face`` '(font-lock-keyword-face
font-lock-string-face)
+ Faces to exclude from highlighting (defaults to ignore keywords & strings).
``idle-highlight-idle-time``
Delay before highlighting (in seconds).
``global-idle-highlight-ignore-modes`` nil
- [nongnu] elpa/idle-highlight-mode 59f5c6ce37 23/59: Add readme, (continued)
- [nongnu] elpa/idle-highlight-mode 59f5c6ce37 23/59: Add readme, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 2bc509cc28 20/59: Cleanup: byte code compiler warnings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 93a498516e 19/59: Cleanup: slightly more efficient checks, postpone calling symbol-name, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 8be1b197d6 39/59: Add changelog, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 94790ca395 47/59: Cleanup: variable names, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode bdc6cb06e0 37/59: Reduce the default idle time to 0.35 seconds, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode f47a2cc796 50/59: Cleanup: replace 'if' with 'cond', ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 7d6eba737d 52/59: Cleanup: remove redundant groups, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 05db87d2a5 32/59: Cleanup: replace defsubst with defun, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 21b63d0502 25/59: Cleanup: simplify coding hook example, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 4f41607fa1 31/59: Add idle-highlight-exceptions-face,
ELPA Syncer <=
- [nongnu] elpa/idle-highlight-mode 0a24f8e402 58/59: Cleanup: use brief SPDX license, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 03b5de12a6 56/59: changelog: correct syntax, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode f6ea983df9 06/59: Remove previous highlights if there's nothing to highlight at point., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 83df5da535 05/59: Header, footer, usage comments, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 8b6e0dffd1 03/59: Implement idle highlighting as a minor mode., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode ee5381764c 51/59: Add docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 9cbb9f2fde 04/59: Rename file to idle-highlight-mode.el, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 1f3620ba70 14/59: Enable lexical binding., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode f71e575540 13/59: Version 1.1.3, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 9435c1f3ca 41/59: readme: correct references to idle-time, ELPA Syncer, 2022/07/07