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

[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
 ============



reply via email to

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