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

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

[nongnu] elpa/spell-fu 103d3a19ce 49/86: Fix checking words that spanned


From: ELPA Syncer
Subject: [nongnu] elpa/spell-fu 103d3a19ce 49/86: Fix checking words that spanned different faces
Date: Thu, 7 Jul 2022 12:03:42 -0400 (EDT)

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

    Fix checking words that spanned different faces
---
 changelog.rst |  3 +++
 spell-fu.el   | 41 +++++++++++++++++++++++++++--------------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/changelog.rst b/changelog.rst
index f0e50bb759..07252c50cd 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -4,7 +4,10 @@ Change Log
 ##########
 
 - In development.
+  - Changes to the face are now treated as word separators.
 
+    This fixes spell checking in situations where characters are escaped for 
example ``"test\nterm"``,
+    will use the ``\n`` as a divider when escape characters use a different 
face.
   - ``global-spell-fu-mode`` no longer enables spell-fu for modes derived from 
``special-mode``
     such as package list for example (fixes ``#15``).
   - Support conditionally disabling ``global-spell-fu-mode`` via
diff --git a/spell-fu.el b/spell-fu.el
index 8100e231cf..da1c2d6006 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -592,20 +592,33 @@ Argument FACES-EXCLUDE faces to check POS excludes or 
ignored when nil."
   "Check spelling for POINT-START & POINT-END, checking text matching face 
rules."
   (spell-fu--remove-overlays point-start point-end)
   (with-syntax-table spell-fu-syntax-table
-    (save-match-data
-      (save-excursion
-        (goto-char point-start)
-        (while (re-search-forward spell-fu-word-regexp point-end t)
-          (let
-            (
-              (word-start (match-beginning 0))
-              (word-end (match-end 0)))
-            (when
-              (spell-fu--check-faces-at-point
-                word-start
-                spell-fu-faces-include
-                spell-fu-faces-exclude)
-              (spell-fu-check-word word-start word-end 
(match-string-no-properties 0)))))))))
+    (save-match-data ;; For regex search.
+      (save-excursion ;; For moving the point.
+        (save-restriction ;; For narrowing.
+          ;; It's possible the face changes part way through the word.
+          ;; In practice this is likely caused by escape characters, e.g.
+          ;; "test\nthe text" where "\n" may have separate highlighting.
+          (while (< point-start point-end)
+            (let ((point-end-iter (next-single-property-change point-start 
'face nil point-end)))
+              ;; Use narrowing so the regex correctly handles boundaries
+              ;; that happen to fall on face changes.
+              (narrow-to-region point-start point-end-iter)
+              (goto-char point-start)
+              (while (re-search-forward spell-fu-word-regexp point-end-iter t)
+                (let
+                  (
+                    (word-start (match-beginning 0))
+                    (word-end (match-end 0)))
+                  (when
+                    (spell-fu--check-faces-at-point
+                      word-start
+                      spell-fu-faces-include
+                      spell-fu-faces-exclude)
+                    (spell-fu-check-word
+                      word-start
+                      word-end
+                      (buffer-substring-no-properties word-start word-end)))))
+              (setq point-start point-end-iter))))))))
 
 (defun spell-fu--check-range-without-faces (point-start point-end)
   "Check spelling for POINT-START & POINT-END, checking all text."



reply via email to

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