]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/flyspell.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / textmodes / flyspell.el
index ffaf7e753f4a66afb7f243609e9613181c28b204..8aadf51871fa2c928a5bb3572a1fe4cb15c740ae 100644 (file)
@@ -93,7 +93,7 @@ downcased before comparing with these exceptions."
   :version "21.1"
   :type 'boolean)
 
-(defcustom flyspell-duplicate-distance -1
+(defcustom flyspell-duplicate-distance 400000
   "The maximum distance for finding duplicates of unrecognized words.
 This applies to the feature that when a word is not found in the dictionary,
 if the same spelling occurs elsewhere in the buffer,
@@ -102,7 +102,7 @@ This variable specifies how far to search to find such a duplicate.
 -1 means no limit (search the whole buffer).
 0 means do not search for duplicate unrecognized spellings."
   :group 'flyspell
-  :version "21.1"
+  :version "24.5"                      ; -1 -> 400000
   :type '(choice (const :tag "no limit" -1)
                 number))
 
@@ -1012,17 +1012,33 @@ Mostly we check word delimiters."
 ;;*---------------------------------------------------------------------*/
 (defun flyspell-word-search-backward (word bound &optional ignore-case)
   (save-excursion
-    (let ((r '())
-         (inhibit-point-motion-hooks t)
-         p)
-      (while (and (not r) (setq p (search-backward word bound t)))
-       (let ((lw (flyspell-get-word)))
-         (if (and (consp lw)
-                  (if ignore-case
-                      (string-equal (downcase (car lw)) (downcase word))
-                    (string-equal (car lw) word)))
-             (setq r p)
-           (goto-char p))))
+    (let* ((r '())
+          (inhibit-point-motion-hooks t)
+          (flyspell-not-casechars (flyspell-get-not-casechars))
+          (bound (if (and bound
+                          (> bound (point-min)))
+                     (- bound 1)))
+          (word-re (concat
+                     "\\(?:" flyspell-not-casechars "\\|\\`\\)"
+                     (regexp-quote word)
+                     flyspell-not-casechars))
+          p)
+      (while
+         (and (not r)
+               (setq p
+                     (and
+                      (re-search-backward word-re bound t)
+                     (if (bobp)
+                         (point)
+                        (forward-char)
+                        (point)))))
+        (let ((lw (flyspell-get-word)))
+          (if (and (consp lw)
+                   (if ignore-case
+                       (string-equal (downcase (car lw)) (downcase word))
+                     (string-equal (car lw) word)))
+              (setq r p)
+            (goto-char p))))
       r)))
 
 ;;*---------------------------------------------------------------------*/
@@ -1030,14 +1046,28 @@ Mostly we check word delimiters."
 ;;*---------------------------------------------------------------------*/
 (defun flyspell-word-search-forward (word bound)
   (save-excursion
-    (let ((r '())
-         (inhibit-point-motion-hooks t)
-         p)
-      (while (and (not r) (setq p (search-forward word bound t)))
-       (let ((lw (flyspell-get-word)))
-         (if (and (consp lw) (string-equal (car lw) word))
-             (setq r p)
-           (goto-char (1+ p)))))
+    (let* ((r '())
+          (inhibit-point-motion-hooks t)
+          (flyspell-not-casechars (flyspell-get-not-casechars))
+          (bound (if (and bound
+                          (< bound (point-max)))
+                     (+ bound 1)))
+          (word-re (concat flyspell-not-casechars
+                            (regexp-quote word)
+                            "\\(?:" flyspell-not-casechars "\\|\\'\\)"))
+          p)
+      (while
+         (and (not r)
+               (setq p (and
+                        (re-search-forward word-re bound t)
+                        (if (eobp)
+                            (point)
+                          (backward-char)
+                          (point)))))
+        (let ((lw (flyspell-get-word)))
+          (if (and (consp lw) (string-equal (car lw) word))
+              (setq r p)
+            (goto-char (1+ p)))))
       r)))
 
 (defvar flyspell-word) ;Backward compatibility; some predicates made use of it!