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

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

[nongnu] elpa/idle-highlight-mode 53b4e3c855 45/59: Add option idle-high


From: ELPA Syncer
Subject: [nongnu] elpa/idle-highlight-mode 53b4e3c855 45/59: Add option idle-highlight-exceptions-syntax
Date: Thu, 7 Jul 2022 12:00:32 -0400 (EDT)

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

    Add option idle-highlight-exceptions-syntax
    
    This allows configuring the kinds of syntax that are skipped.
    
    Using skip-syntax-forward should be slightly faster than looking-at-p
    as well.
---
 changelog.rst          |  1 +
 idle-highlight-mode.el | 54 ++++++++++++++++++++++++++++++++++++--------------
 readme.rst             |  4 ++++
 3 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/changelog.rst b/changelog.rst
index bfbe7a616f..108db8963f 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -1,5 +1,6 @@
 - In development (2021-08-29)
 
+  - Add ``idle-highlight-exceptions-syntax`` so the characters used in the 
syntax-table used can be customized.
   - 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.
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index ca7827f3a9..5bd0deab2d 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -86,6 +86,13 @@
     (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-exceptions-syntax "^w_"
+  "Syntax table to to skip.
+
+See documentation for `skip-syntax-forward', nil to ignore."
+  :group 'idle-highlight
+  :type '(choice (const nil) string))
+
 (defcustom idle-highlight-exclude-point nil
   "Exclude the current symbol from highlighting."
   :group 'idle-highlight
@@ -132,6 +139,18 @@ Argument POS return faces at this point."
             (push face faces)))))
     faces))
 
+
+;; ---------------------------------------------------------------------------
+;; Internal Context Checking Functions
+
+(defun idle-highlight--check-symbol-at-point (pos)
+  "Return non-nil if the symbol at POS can be used."
+  (cond
+    (idle-highlight-exceptions-syntax
+      (save-excursion (zerop (skip-syntax-forward 
idle-highlight-exceptions-syntax (1+ pos)))))
+    (t
+      t)))
+
 (defun idle-highlight--check-faces-at-point (pos)
   "Check if the position POS has faces that match the exclude argument."
   (cond
@@ -154,6 +173,19 @@ Argument POS return faces at this point."
     (t ;; Default to true, if there are no exceptions.
       t)))
 
+(defun idle-highlight--check-word (target)
+  "Return non-nil when TARGET should not be excluded."
+  (not
+    (cond
+      ((functionp idle-highlight-exceptions)
+        (funcall idle-highlight-exceptions target))
+      (t
+        (member target idle-highlight-exceptions)))))
+
+
+;; ---------------------------------------------------------------------------
+;; Internal Highlight Functions
+
 (defun idle-highlight--unhighlight ()
   "Clear current highlight."
   (when idle-highlight--overlays
@@ -194,21 +226,13 @@ Argument POS return faces at this point."
 (defun idle-highlight--word-at-point ()
   "Highlight the word under the point."
   (idle-highlight--unhighlight)
-  (let ((target-range (bounds-of-thing-at-point 'symbol)))
-    (when
-      (and
-        target-range (idle-highlight--check-faces-at-point (point))
-        ;; Symbol characters.
-        (looking-at-p "\\s_\\|\\sw"))
-      (pcase-let* ((`(,beg . ,end) target-range))
-        (let ((target (buffer-substring-no-properties beg end)))
-          (unless
-            (cond
-              ((functionp idle-highlight-exceptions)
-                (funcall idle-highlight-exceptions target))
-              (t
-                (member target idle-highlight-exceptions)))
-            (idle-highlight--highlight target beg end)))))))
+  (when (idle-highlight--check-symbol-at-point (point))
+    (let ((target-range (bounds-of-thing-at-point 'symbol)))
+      (when (and target-range (idle-highlight--check-faces-at-point (point)))
+        (pcase-let* ((`(,beg . ,end) target-range))
+          (let ((target (buffer-substring-no-properties beg end)))
+            (when (idle-highlight--check-word target)
+              (idle-highlight--highlight target beg end))))))))
 
 
 ;; ---------------------------------------------------------------------------
diff --git a/readme.rst b/readme.rst
index 16544ff0ab..f04b9c7dba 100644
--- a/readme.rst
+++ b/readme.rst
@@ -54,6 +54,10 @@ Global Settings
 
    This may also be set to a function that takes a list of faces,
    returning non-nil to exclude the word.
+``idle-highlight-exceptions-syntax``: ``^w_``
+   Syntax table to ignore.
+
+   see documentation for ``skip-syntax-forward``, use ``nil`` to skip this 
check.
 ``idle-highlight-exclude-point``: ``nil``
    When non-nil, don't highlight the symbol under the cursor.
 ``idle-highlight-idle-time``: ``0.35``



reply via email to

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