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

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

[nongnu] elpa/spell-fu db0eef27ab 33/86: Add: spell-fu-goto-next-error,


From: ELPA Syncer
Subject: [nongnu] elpa/spell-fu db0eef27ab 33/86: Add: spell-fu-goto-next-error, spell-fu-goto-previous-error
Date: Thu, 7 Jul 2022 12:03:41 -0400 (EDT)

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

    Add: spell-fu-goto-next-error, spell-fu-goto-previous-error
    
    Useful for jumping between errors.
---
 readme.rst  | 17 +++++++++++++++-
 spell-fu.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/readme.rst b/readme.rst
index bc842cac1c..cc429f8284 100644
--- a/readme.rst
+++ b/readme.rst
@@ -145,6 +145,22 @@ however they will be used when set:
    When generating the word-list, this file is included when present.
 
 
+Commands
+--------
+
+While this package is intended to be used with minimal interaction,
+there are some commands provided which may come in handy.
+
+``spell-fu-goto-next-error``
+   Moves the point to the next error.
+
+``spell-fu-goto-previous-error``
+   Moves the point to the previous error.
+
+``spell-fu-buffer``
+   Checks spelling for the entire buffer, reporting the number of misspelled 
words found.
+
+
 Other Packages
 ==============
 
@@ -167,7 +183,6 @@ TODO
 
 - Support alternates to ``aspell`` for generating word lists.
 - Support a custom command for generating a word list.
-- Support going to next/previous misspelled word.
 - Support affix expansion when calling aspell (some non English dictionaries 
use this).
 - Support refreshing the word list at run-time when ispell updates the 
personal dictionary
   *(currently updates require re-enabling the mode).*
diff --git a/spell-fu.el b/spell-fu.el
index a3eec4b8aa..e6b51d76d4 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -97,7 +97,6 @@ Set to 0.0 to highlight immediately (as part of syntax 
highlighting)."
 (defvar-local spell-fu-faces-exclude nil
   "List of faces to check or nil to exclude none (used by 
`spell-fu-check-range').")
 
-
 (defvar-local spell-fu-check-range 'spell-fu-check-range-default
   "Function that takes a beginning and end points to check for the current 
buffer.
 
@@ -116,7 +115,6 @@ Notes:
 ;; ---------------------------------------------------------------------------
 ;; Internal Variables
 
-
 ;; Use to ensure the cache is not from a previous release.
 ;; Only ever increase.
 (defconst spell-fu--cache-version "0.1")
@@ -361,7 +359,6 @@ save some time by not spending time reading it back."
           (message "failed, %s" (error-message-string err))
           nil)))))
 
-
 (defun spell-fu--cache-words-load-impl (cache-file)
   "Return the Lisp content from reading CACHE-FILE.
 
@@ -417,7 +414,6 @@ On failure of any kind, return nil, the caller will need to 
regenerate the cache
 
     (spell-fu--word-list-ensure words-file dict)
 
-
     ;; Use previously loaded dictionary from language 'dict' where possible.
     (setq spell-fu--cache-table (assoc-default dict 
spell-fu--cache-table-alist))
 
@@ -496,7 +492,6 @@ Argument FACES-EXCLUDE faces to check POS excludes or 
ignored when nil."
         (setq result t)))
     result))
 
-
 (defun spell-fu--check-range-with-faces (point-start point-end)
   "Check spelling for POINT-START & POINT-END, checking text matching face 
rules."
   (spell-fu--remove-overlays point-start point-end)
@@ -702,6 +697,67 @@ when checking the entire buffer for example."
   (interactive)
   (spell-fu-region nil nil t))
 
+(defun spell-fu--goto-next-or-previous-error (dir)
+  "Jump to the next or previous error using DIR, return t when found, 
otherwise nil."
+  (let
+    ( ;; Track the closest point in a given line.
+      (point-found-delta most-positive-fixnum)
+      (point-init (point))
+      (point-prev nil)
+      (point-found nil))
+    (save-excursion
+      (while (and (null point-found) (not (equal (point) point-prev)))
+        (let
+          (
+            (point-start (line-beginning-position))
+            (point-end (line-end-position)))
+
+          (jit-lock-fontify-now point-start point-end)
+
+          ;; Ensure idle timer is handled immediately.
+          (cond
+            ((<= spell-fu-idle-delay 0.0)
+              nil)
+            (t
+              (spell-fu--idle-handle-pending-ranges-impl point-start 
point-end)))
+
+          (dolist (item-ov (overlays-in point-start point-end))
+            (when (overlay-get item-ov 'spell-fu-mode)
+              (let
+                (
+                  (item-start (overlay-start item-ov))
+                  (item-end (overlay-end item-ov)))
+                (when
+                  (if (< dir 0)
+                    (< item-end point-init)
+                    (> item-start point-init))
+                  (let ((test-delta (abs (- point-init item-start))))
+                    (when (< test-delta point-found-delta)
+                      (setq point-found item-start)
+                      (setq point-found-delta test-delta))))))))
+        (setq point-prev (point))
+        (forward-line dir)))
+
+    (if point-found
+      (progn
+        (goto-char point-found)
+        t)
+      (message
+        "Spell-fu: no %s spelling error found"
+        (if (< dir 0)
+          "previous"
+          "next"))
+      nil)))
+
+(defun spell-fu-goto-next-error ()
+  "Jump to the next error, return t when found, otherwise nil."
+  (interactive)
+  (spell-fu--goto-next-or-previous-error 1))
+
+(defun spell-fu-goto-previous-error ()
+  "Jump to the previous error, return t when found, otherwise nil."
+  (interactive)
+  (spell-fu--goto-next-or-previous-error -1))
 
 ;; ---------------------------------------------------------------------------
 ;; Define Minor Mode



reply via email to

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