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

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

[elpa] externals/jit-spell 2a34f68726 2/2: Reorganization and small refa


From: ELPA Syncer
Subject: [elpa] externals/jit-spell 2a34f68726 2/2: Reorganization and small refactorings
Date: Wed, 22 Mar 2023 14:58:35 -0400 (EDT)

branch: externals/jit-spell
commit 2a34f68726807d17292da906be5943bbd6d2e496
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>

    Reorganization and small refactorings
---
 jit-spell.el | 86 +++++++++++++++++++++++++++---------------------------------
 1 file changed, 38 insertions(+), 48 deletions(-)

diff --git a/jit-spell.el b/jit-spell.el
index a79c7a2594..6caa5dc569 100644
--- a/jit-spell.el
+++ b/jit-spell.el
@@ -138,27 +138,6 @@ move the point with impunity.")
 (defvar-local jit-spell--local-words nil
   "A list of words accepted temporarily in this buffer.")
 
-;;; Mode-specific support
-
-(defun jit-spell--default-ignored-p (start end)
-  "Return non-nil if word between START and END should not be spell-checked."
-  (or (get-text-property start 'jit-spell-ignored)
-      (let ((face (get-text-property start 'face)))
-        (if (listp face)
-            (seq-some (lambda (f) (memq f jit-spell-ignored-faces))
-                      face)
-          (memq face jit-spell-ignored-faces)))
-      (member (buffer-substring-no-properties start end)
-              jit-spell--local-words)))
-
-(defun jit-spell--prog-ignored-p (start _end)
-  "Additional ignore predicate for `prog-mode'."
-  (let ((face (get-text-property start 'face)))
-    (not (if (listp face)
-             (seq-some (lambda (f) (memq f jit-spell-prog-mode-faces))
-                       face)
-           (memq face jit-spell-prog-mode-faces)))))
-
 ;;; Overlays
 
 (put 'jit-spell 'evaporate t)
@@ -235,30 +214,6 @@ to END coming first."
     (delete-region (point) (overlay-end ov))
     (insert-before-markers text)))
 
-(defun jit-spell--context-menu (menu click)
-  "Context menu for `jit-spell-mode'.
-MENU and CLICK are as expected of a member of `context-menu-functions'.
-It can also be bound to a mouse click to pop up the menu."
-  (interactive "i\ne")
-  (save-excursion
-    (mouse-set-point click)
-    (when-let ((ov (jit-spell--overlay-at (point)))
-               (word (buffer-substring-no-properties
-                  (overlay-start ov) (overlay-end ov)))
-               (map (or menu (make-sparse-keymap))))
-      (dolist (corr (overlay-get ov 'jit-spell-corrections))
-        (easy-menu-add-item map '("Correct Word")
-                            (vector corr (lambda () (interactive)
-                                           (jit-spell--apply-correction ov 
corr)))))
-      (easy-menu-add-item map nil `["Save to Dictionary"
-                                    (jit-spell--accept-word ,word 'dict)])
-      (easy-menu-add-item map nil `["Save to Buffer"
-                                    (jit-spell--accept-word ,word 'buffer)])
-      (easy-menu-add-item map nil `["Accept for Session"
-                                    (jit-spell--accept-word ,word 'session)])
-      (unless menu (popup-menu map)))
-    menu))
-
 (defun jit-spell--unhide-overlay ()
   "Unhide the overlay stored in `jit-spell--hidden-overlay'."
   (pcase jit-spell--hidden-overlay
@@ -417,12 +372,22 @@ The process plist includes the following properties:
       (push (cons (match-beginning 0) (match-end 0)) regions))
     regions))
 
+;;; Mode-specific support
+
 (defun jit-spell--has-face-p (faces v)
   "Non-nil if V, a face or list of faces, includes any of the FACES."
   (if (listp v)
       (seq-some (lambda (f) (memq f faces)) v)
     (memq v faces)))
 
+(defun jit-spell--default-ignored-p (start end)
+  "Return non-nil if word between START and END should not be spell-checked."
+  (or (get-text-property start 'jit-spell-ignored)
+      (jit-spell--has-face-p jit-spell-ignored-faces
+                             (get-char-property start 'face))
+      (member (buffer-substring-no-properties start end)
+              jit-spell--local-words)))
+
 (defun jit-spell--refine-by-face (faces &optional only)
   "Return a function to refine a list of regions based on its faces.
 If ONLY is nil, regions containing any of the FACES are excluded.
@@ -476,7 +441,7 @@ This is intended to be a member of `jit-lock-functions'."
             (jit-spell--send-request proc request)))))
     `(jit-lock-bounds ,start . ,end)))
 
-;;; Interactive commands and major mode
+;;; Interactive commands
 
 (defun jit-spell--accept-word (word where)
   "Accept spelling of WORD.
@@ -558,6 +523,32 @@ With a numeric ARG, move backwards that many misspellings."
 
 (defalias 'jit-spell-change-dictionary 'ispell-change-dictionary) ;For 
discoverability
 
+;;; Minor mode definition
+
+(defun jit-spell--context-menu (menu click)
+  "Context menu for `jit-spell-mode'.
+MENU and CLICK are as expected of a member of `context-menu-functions'.
+It can also be bound to a mouse click to pop up the menu."
+  (interactive "i\ne")
+  (save-excursion
+    (mouse-set-point click)
+    (when-let ((ov (jit-spell--overlay-at (point)))
+               (word (buffer-substring-no-properties
+                  (overlay-start ov) (overlay-end ov)))
+               (map (or menu (make-sparse-keymap))))
+      (dolist (corr (overlay-get ov 'jit-spell-corrections))
+        (easy-menu-add-item map '("Correct Word")
+                            (vector corr (lambda () (interactive)
+                                           (jit-spell--apply-correction ov 
corr)))))
+      (easy-menu-add-item map nil `["Save to Dictionary"
+                                    (jit-spell--accept-word ,word 'dict)])
+      (easy-menu-add-item map nil `["Save to Buffer"
+                                    (jit-spell--accept-word ,word 'buffer)])
+      (easy-menu-add-item map nil `["Accept for Session"
+                                    (jit-spell--accept-word ,word 'session)])
+      (unless menu (popup-menu map)))
+    menu))
+
 (defun jit-spell--read-local-words ()
   "Look for local words in the buffer and accept them for this session."
   (save-excursion
@@ -567,11 +558,10 @@ With a numeric ARG, move backwards that many 
misspellings."
        (while (re-search-forward "\\s-*\\(\\S-+\\)" limit t)
           (jit-spell--accept-word (match-string-no-properties 1) 'session))))))
 
-(defvar-keymap jit-spell-mode-map :doc "Keymap for `jit-spell-mode'.")
-
 ;;;###autoload
 (define-minor-mode jit-spell-mode
   "Just-in-time spell checking."
+  :keymap (make-sparse-keymap)
   :lighter (" Spell"
             (:propertize
              (:eval



reply via email to

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