[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/idle-highlight-mode 8b6e0dffd1 03/59: Implement idle highl
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/idle-highlight-mode 8b6e0dffd1 03/59: Implement idle highlighting as a minor mode. |
Date: |
Thu, 7 Jul 2022 12:00:28 -0400 (EDT) |
branch: elpa/idle-highlight-mode
commit 8b6e0dffd16df5ee1584ac79686f37911d87d192
Author: Cornelius Mika <cornelius.mika@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Implement idle highlighting as a minor mode.
This fixes the bug that a new highlighting timer is created for each
buffer in which idle-highlight becomes active.
After a long Emacs session one might end up with hundreds of timers
all sequentially executing the highlighting code.
---
idle-highlight.el | 53 ++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/idle-highlight.el b/idle-highlight.el
index 6f67fe7bbb..1272cbf46b 100755
--- a/idle-highlight.el
+++ b/idle-highlight.el
@@ -62,38 +62,41 @@
"Face used to highlight other occurrences of the word at point."
:group 'idle-highlight)
-(defvar idle-highlight-last-regexp nil "Last regexp to be idle-highlighted.")
+(defvar idle-highlight-regexp nil "Buffer-local regexp to be
idle-highlighted.")
-(defvar idle-highlight-timer nil "Timer to activate re-highlighting.")
+(defvar idle-highlight-global-timer nil "Timer to trigger highlighting.")
(defun idle-highlight-word-at-point ()
"Highlight the word under the point."
- (let*
- (
- (target-symbol (symbol-at-point))
- (target (symbol-name target-symbol)))
- (if idle-highlight-last-regexp
- (unhighlight-regexp idle-highlight-last-regexp))
- (when
- (and
- idle-highlight-timer target target-symbol
- ;; TODO: no need to highlight keywords like if
- (not (in-string-p)) (not (equal target "end")))
- (setq idle-highlight-last-regexp (concat "\\<" (regexp-quote target)
"\\>"))
- (highlight-regexp idle-highlight-last-regexp 'idle-highlight))))
+ (if idle-highlight-mode
+ (let*
+ (
+ (target-symbol (symbol-at-point))
+ (target (symbol-name target-symbol)))
+ (when
+ (and
+ target-symbol (not (in-string-p))
+ ;; TODO: no need to highlight keywords like if
+ (not (equal target "end")))
+ (idle-highlight-unhighlight)
+ (setq idle-highlight-regexp (concat "\\<" (regexp-quote target) "\\>"))
+ (highlight-regexp idle-highlight-regexp 'idle-highlight)))))
+
+(defsubst idle-highlight-unhighlight ()
+ (if idle-highlight-regexp
+ (unhighlight-regexp idle-highlight-regexp)))
;;;###autoload
-(defun idle-highlight (&optional arg)
- "Toggle idle-highlighting."
- (interactive "P")
- (if (and (boundp 'idle-highlight-timer) idle-highlight-timer)
+(define-minor-mode idle-highlight-mode
+ "Idle-Highlight Minor Mode"
+ :group 'idle-highlight
+ (if idle-highlight-mode
(progn
- (cancel-timer idle-highlight-timer)
- (setq idle-highlight-timer nil))
- (set (make-local-variable 'idle-highlight-last-regexp) nil)
- (set
- (make-local-variable 'idle-highlight-timer)
- (run-with-idle-timer 0.5 :repeat 'idle-highlight-word-at-point))))
+ (unless idle-highlight-global-timer
+ (setq idle-highlight-global-timer
+ (run-with-idle-timer 0.5 :repeat 'idle-highlight-word-at-point)))
+ (set (make-local-variable 'idle-highlight-regexp) nil))
+ (idle-highlight-unhighlight)))
(provide 'idle-highlight)
;;; idle-highlight.el ends here
- [nongnu] elpa/idle-highlight-mode bdc6cb06e0 37/59: Reduce the default idle time to 0.35 seconds, (continued)
- [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, 2022/07/07
- [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 <=
- [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
- [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