[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/idle-highlight-mode 459720cd2e 29/59: Add `global-idle-hig
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/idle-highlight-mode 459720cd2e 29/59: Add `global-idle-highlight-mode` (globalized minor mode) |
Date: |
Thu, 7 Jul 2022 12:00:30 -0400 (EDT) |
branch: elpa/idle-highlight-mode
commit 459720cd2e2851501e9dce4ecb3c8b8f5bb32d3c
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add `global-idle-highlight-mode` (globalized minor mode)
---
idle-highlight-mode.el | 60 ++++++++++++++++++++++++++++++++++++++++++++++----
readme.rst | 33 +++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index 64a06287a8..f132f61af0 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -78,6 +78,17 @@
:group 'idle-highlight
:type 'float)
+(defcustom idle-highlight-ignore-modes nil
+ "List of major-modes to exclude when `idle-highlight' has been enabled
globally."
+ :type '(repeat symbol)
+ :group 'idle-highlight)
+
+(defvar-local global-idle-highlight-ignore-buffer nil
+ "When non-nil, the global mode will not be enabled for this buffer.
+This variable can also be a predicate function, in which case
+it'll be called with one parameter (the buffer in question), and
+it should return non-nil to make Global `idle-highlight' Mode not
+check this buffer.")
;; ---------------------------------------------------------------------------
;; Internal Variables
@@ -218,6 +229,42 @@
(idle-highlight--time-ensure nil)
(remove-hook 'window-state-change-hook #'idle-highlight--time-reset t))
+
+;; ---------------------------------------------------------------------------
+;; Internal Mode Management
+
+(defun idle-highlight--enable ()
+ "Enable the buffer local minor mode."
+ (idle-highlight--time-buffer-local-enable))
+
+(defun idle-highlight--disable ()
+ "Disable the buffer local minor mode."
+ (idle-highlight--time-buffer-local-disable)
+ (idle-highlight--unhighlight)
+ (kill-local-variable 'idle-highlight--regexp))
+
+(defun idle-highlight--turn-on ()
+ "Enable command `idle-highlight-mode'."
+ (when
+ (and
+ ;; Not already enabled.
+ (not (bound-and-true-p idle-highlight-mode))
+ ;; Not in the mini-buffer.
+ (not (minibufferp))
+ ;; Not a special mode (package list, tabulated data ... etc)
+ ;; Instead the buffer is likely derived from `text-mode' or `prog-mode'.
+ (not (derived-mode-p 'special-mode))
+ ;; Not explicitly ignored.
+ (not (memq major-mode idle-highlight-ignore-modes))
+ ;; Optionally check if a function is used.
+ (or
+ (null global-idle-highlight-ignore-buffer)
+ (if (functionp global-idle-highlight-ignore-buffer)
+ (not (funcall global-idle-highlight-ignore-buffer (current-buffer)))
+ nil)))
+ (idle-highlight-mode 1)))
+
+
;; ---------------------------------------------------------------------------
;; Public Functions
@@ -229,11 +276,16 @@
(cond
(idle-highlight-mode
- (idle-highlight--time-buffer-local-enable))
+ (idle-highlight--enable))
(t
- (idle-highlight--time-buffer-local-disable)
- (idle-highlight--unhighlight)
- (kill-local-variable 'idle-highlight--regexp))))
+ (idle-highlight--disable))))
+
+;;;###autoload
+(define-globalized-minor-mode
+ global-idle-highlight-mode
+
+ idle-highlight-mode idle-highlight--turn-on
+ :group 'idle-highlight)
(provide 'idle-highlight-mode)
;;; idle-highlight-mode.el ends here
diff --git a/readme.rst b/readme.rst
index 6a25ef64c4..e26f84b55c 100644
--- a/readme.rst
+++ b/readme.rst
@@ -7,15 +7,48 @@ Simple highlighting package for Emacs.
Usage
=====
+Commands
+--------
+
+``idle-highlight-mode``
+ Enable idle highlight mode for this buffer.
+``global-idle-highlight-mode``
+ Enable idle highlight mode for all buffers.
+
+
Customization
-------------
+Global Settings
+^^^^^^^^^^^^^^^
+
``idle-highlight``
Face used for highlighting the symbol.
``idle-highlight-exceptions``
Words to exclude from highlighting.
``idle-highlight-idle-time``
Delay before highlighting (in seconds).
+``global-idle-highlight-ignore-modes`` nil
+ A list of modes that won't enable spell-checking from
``global-idle-highlight-mode``.
+
+Buffer Local Settings
+^^^^^^^^^^^^^^^^^^^^^
+
+``global-idle-highlight-ignore-buffer``
+ When not ``nil``, the buffer won't enable spell-checking from
``global-idle-highlight-mode``.
+
+ This may also be a function that takes a single buffer argument,
+ where returning ``nil`` will enable spell-checking, anything else will not.
+
+ This example shows idle-highlight being disabled for ORG mode and for
read-only buffers.
+
+ .. code-block:: elisp
+
+ (setq idle-highlight-ignore-modes (list 'org-mode))
+ (setq global-idle-highlight-ignore-buffer (lambda (buf)
(buffer-local-value 'buffer-read-only buf)))
+
+ (global-idle-highlight-mode)
+
Installation
============
- [nongnu] elpa/idle-highlight-mode f71e575540 13/59: Version 1.1.3, (continued)
- [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, 2022/07/07
- [nongnu] elpa/idle-highlight-mode 459720cd2e 29/59: Add `global-idle-highlight-mode` (globalized minor mode),
ELPA Syncer <=
- [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
- [nongnu] elpa/idle-highlight-mode 97047f2574 33/59: Add Campbell Barton as an author, ELPA Syncer, 2022/07/07