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

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

[nongnu] elpa/spell-fu 143233734a 46/86: Allow global-spell-fu to be ign


From: ELPA Syncer
Subject: [nongnu] elpa/spell-fu 143233734a 46/86: Allow global-spell-fu to be ignored per mode or using a function
Date: Thu, 7 Jul 2022 12:03:42 -0400 (EDT)

branch: elpa/spell-fu
commit 143233734a695f46078198e10e2e4c4687a82c0f
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Allow global-spell-fu to be ignored per mode or using a function
    
    Resolves #2
---
 changelog.rst |  5 +++++
 readme.rst    | 18 ++++++++++++++++++
 spell-fu.el   | 25 ++++++++++++++++++++++---
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/changelog.rst b/changelog.rst
index 08f18f39b7..3b49e7244d 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -3,6 +3,11 @@
 Change Log
 ##########
 
+- In development.
+
+  - Support conditionally disabling ``global-spell-fu-mode`` via
+    ``global-spell-fu-ignore-buffer`` & ``global-spell-fu-ignore-modes``.
+
 - Version 0.3 (2021-03-28)
 
   - Support affix expansion when calling ``aspell`` (some non English 
dictionaries use this).
diff --git a/readme.rst b/readme.rst
index 931f407ff0..1d789e3cd9 100644
--- a/readme.rst
+++ b/readme.rst
@@ -69,6 +69,9 @@ Global Settings
 ``spell-fu-incorrect-face`` (red, underline)
    The font to use for the spell checking overlay.
 
+``global-spell-fu-ignore-modes`` nil
+   A list of modes that won't enable spell-checking from 
``global-spell-fu-mode``.
+
 
 Buffer Local Settings
 ^^^^^^^^^^^^^^^^^^^^^
@@ -90,6 +93,21 @@ You may wish to set these values differently based on the 
current major-mode.
 ``spell-fu-faces-exclude``
    When not ``nil``, text with faces in this list will be excluded.
 
+``global-spell-fu-ignore-buffer``
+   When not ``nil``, the buffer won't enable spell-checking from 
``global-spell-fu-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 spell-fu being disabled for ORG mode and for read-only 
buffers.
+
+   .. code-block:: elisp
+
+      (setq spell-fu-ignore-modes (list 'org-mode))
+      (setq global-spell-fu-ignore-buffer (lambda (buf) (buffer-local-value 
'buffer-read-only buf)))
+
+      (global-spell-fu-mode)
+
 
 Advanced Buffer Local Settings
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/spell-fu.el b/spell-fu.el
index e52da2a361..35ff139c31 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -80,6 +80,18 @@ Set to 0.0 to highlight immediately (as part of syntax 
highlighting)."
   :group 'spell-fu
   :type 'float)
 
+(defcustom spell-fu-ignore-modes nil
+  "List of major-modes to exclude when `spell-fu' has been enabled globally."
+  :type '(repeat symbol)
+  :group 'spell-fu)
+
+(defvar-local global-spell-fu-ignore-buffer nil
+  "When non-nil, Global `spell-fu' 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 `spell-fu' Mode not
+check this buffer.")
+
 (defface spell-fu-incorrect-face
   '
   ((((supports :underline (:style wave))) :underline (:style wave :color 
"red"))
@@ -1063,13 +1075,20 @@ Return t when the word is removed."
     (t
       (spell-fu-mode-disable))))
 
-(defun spell-fu-mode-turn-on ()
+(defun spell-fu-mode--turn-on ()
   "Enable the option `spell-fu-mode' where possible."
-  (when (and (not (minibufferp)) (not spell-fu-mode))
+  (when
+    (and
+      (not spell-fu-mode) (not (minibufferp)) (not (memq major-mode 
spell-fu-ignore-modes))
+      (or
+        (null global-spell-fu-ignore-buffer)
+        (if (functionp global-spell-fu-ignore-buffer)
+          (not (funcall global-spell-fu-ignore-buffer (current-buffer)))
+          nil)))
     (spell-fu-mode 1)))
 
 ;;;###autoload
-(define-globalized-minor-mode global-spell-fu-mode spell-fu-mode 
spell-fu-mode-turn-on)
+(define-globalized-minor-mode global-spell-fu-mode spell-fu-mode 
spell-fu-mode--turn-on)
 
 (provide 'spell-fu)
 ;;; spell-fu.el ends here



reply via email to

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