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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/idle-highlight-mode 3d785f0f1d 44/59: Support *-exceptions


From: ELPA Syncer
Subject: [nongnu] elpa/idle-highlight-mode 3d785f0f1d 44/59: Support *-exceptions & *-exceptions-face to be callback functions
Date: Thu, 7 Jul 2022 12:00:32 -0400 (EDT)

branch: elpa/idle-highlight-mode
commit 3d785f0f1d5a41ec70453c3000ba3a3e5f0f7dbb
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Support *-exceptions & *-exceptions-face to be callback functions
    
    This allows flexible user defined functionality when filtering
    symbols to highlight.
---
 changelog.rst          |  4 +++-
 idle-highlight-mode.el | 43 ++++++++++++++++++++++++++++++-------------
 readme.rst             |  9 ++++++++-
 3 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/changelog.rst b/changelog.rst
index 6f02aafccc..bfbe7a616f 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -1,5 +1,7 @@
-- In development (2021-08-27)
+- In development (2021-08-29)
 
+  - Support setting ``idle-highlight-exceptions`` to a function that takes the 
word as an argument.
+  - Support setting ``idle-highlight-exceptions-face`` to a function that 
takes list of faces as an argument.
   - Add ``idle-highlight-exclude-point`` option to exclude the current word 
from highlighting.
   - Add ``idle-highlight-exceptions-face`` to support excluding words by face.
   - Add ``global-idle-highlight-mode`` (globalized minor mode).
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index 3d86713e33..ca7827f3a9 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -71,12 +71,20 @@
 (defcustom idle-highlight-exceptions nil
   "List of words to be excepted from highlighting."
   :group 'idle-highlight
-  :type '(repeat string))
+  :type
+  '
+  (choice
+    (repeat :tag "A list of string literals that will be excluded." string)
+    (function :tag "A function taking a string, non-nil result excludes.")))
 
 (defcustom idle-highlight-exceptions-face '(font-lock-keyword-face 
font-lock-string-face)
   "List of exception faces."
   :group 'idle-highlight
-  :type '(repeat symbol))
+  :type
+  '
+  (choice
+    (repeat :tag "A list of face symbols that will be ignored." symbol)
+    (function :tag "A function that takes a list of faces, non-nil result 
excludes.")))
 
 (defcustom idle-highlight-exclude-point nil
   "Exclude the current symbol from highlighting."
@@ -128,16 +136,20 @@ Argument POS return faces at this point."
   "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))))
+      (let ((result t))
+        (let ((faces-at-pos (idle-highlight--faces-at-point pos)))
+          (when faces-at-pos
+            (cond
+              ((functionp idle-highlight-exceptions-face)
+                (when (funcall idle-highlight-exceptions-face faces-at-pos)
+                  (setq result nil)))
+              (t
+                (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)))
@@ -190,7 +202,12 @@ Argument POS return faces at this point."
         (looking-at-p "\\s_\\|\\sw"))
       (pcase-let* ((`(,beg . ,end) target-range))
         (let ((target (buffer-substring-no-properties beg end)))
-          (when (not (member target idle-highlight-exceptions))
+          (unless
+            (cond
+              ((functionp idle-highlight-exceptions)
+                (funcall idle-highlight-exceptions target))
+              (t
+                (member target idle-highlight-exceptions)))
             (idle-highlight--highlight target beg end)))))))
 
 
diff --git a/readme.rst b/readme.rst
index 91b511b2e9..16544ff0ab 100644
--- a/readme.rst
+++ b/readme.rst
@@ -45,9 +45,15 @@ Global Settings
 ``idle-highlight``
    Face used for highlighting the symbol.
 ``idle-highlight-exceptions``: ``nil``
-   Words to exclude from highlighting.
+   A list of words to exclude from highlighting.
+
+   This may also be set to a function that takes the word as an argument,
+   returning non-nil to exclude the word.
 ``idle-highlight-exceptions-face``: ``'(font-lock-keyword-face 
font-lock-string-face)``
    Faces to exclude from highlighting (defaults to ignore keywords & strings).
+
+   This may also be set to a function that takes a list of faces,
+   returning non-nil to exclude the word.
 ``idle-highlight-exclude-point``: ``nil``
    When non-nil, don't highlight the symbol under the cursor.
 ``idle-highlight-idle-time``: ``0.35``
@@ -55,6 +61,7 @@ Global Settings
 ``global-idle-highlight-ignore-modes``: ``nil``
    A list of modes that won't enable idle-highlight from 
``global-idle-highlight-mode``.
 
+
 Buffer Local Settings
 ^^^^^^^^^^^^^^^^^^^^^
 



reply via email to

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