[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``
- [nongnu] elpa/idle-highlight-mode 1f3620ba70 14/59: Enable lexical binding., (continued)
- [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
- [nongnu] elpa/idle-highlight-mode 768745ef1c 21/59: Cleanup: add code sections, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 0916be7075 53/59: Cleanup: docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 5881f796ad 57/59: Minor tweaks to code-comments, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode e6239e06fd 22/59: Add license file., ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode ac31f75fd0 28/59: Remove local variable when the mode is disabled, ELPA Syncer, 2022/07/07
- [nongnu] elpa/idle-highlight-mode c7af42119a 38/59: Cleanup: remove unnecessary variable, ELPA Syncer, 2022/07/07
- [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 <=
- [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, 2022/07/07
- [nongnu] elpa/idle-highlight-mode a801e7113f 43/59: Remove 'idle-highlight-use-hi-lock-mode', ELPA Syncer, 2022/07/07