emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]