aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Martin Domingo2015-02-12 18:38:11 +0100
committerAgustin Martin Domingo2015-02-12 18:45:26 +0100
commita7254bbf99d9c9a55c93aae840c9d97598d4ce73 (patch)
treead0f15318db74707d87d4d978fd12f3112c0ec04
parentf5d1e1f5509b23959f92117c5e1d1a09e05661d1 (diff)
downloademacs-a7254bbf99d9c9a55c93aae840c9d97598d4ce73.tar.gz
emacs-a7254bbf99d9c9a55c93aae840c9d97598d4ce73.zip
Improve string search in `flyspell-word-search-*`. (Bug#16800)
* flyspell.el (flyspell-duplicate-distance): Limit default search distance for duplicated words to 40000. (flyspell-word-search-backward, flyspell-word-search-forward): Search as full word with defined casechars, not as substring. Fixes: debbugs:16800
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/textmodes/flyspell.el70
2 files changed, 59 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ea428b1de15..6fb752a48a9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12015-02-12 Agustín Martín Domingo <agustin6martin@gmail.com>
2
3 Improve string search in `flyspell-word-search-*`. (Bug#16800)
4
5 * flyspell.el (flyspell-duplicate-distance): Limit default search
6 distance for duplicated words to 40000.
7 (flyspell-word-search-backward, flyspell-word-search-forward):
8 Search as full word with defined casechars, not as substring.
9
12015-02-10 Juri Linkov <juri@linkov.net> 102015-02-10 Juri Linkov <juri@linkov.net>
2 11
3 Better support for the case of typing RET on the prompt in comint. 12 Better support for the case of typing RET on the prompt in comint.
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 66243b42102..cd64a806778 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -92,7 +92,7 @@ downcased before comparing with these exceptions."
92 :version "21.1" 92 :version "21.1"
93 :type 'boolean) 93 :type 'boolean)
94 94
95(defcustom flyspell-duplicate-distance -1 95(defcustom flyspell-duplicate-distance 400000
96 "The maximum distance for finding duplicates of unrecognized words. 96 "The maximum distance for finding duplicates of unrecognized words.
97This applies to the feature that when a word is not found in the dictionary, 97This applies to the feature that when a word is not found in the dictionary,
98if the same spelling occurs elsewhere in the buffer, 98if the same spelling occurs elsewhere in the buffer,
@@ -1010,17 +1010,33 @@ Mostly we check word delimiters."
1010;;*---------------------------------------------------------------------*/ 1010;;*---------------------------------------------------------------------*/
1011(defun flyspell-word-search-backward (word bound &optional ignore-case) 1011(defun flyspell-word-search-backward (word bound &optional ignore-case)
1012 (save-excursion 1012 (save-excursion
1013 (let ((r '()) 1013 (let* ((r '())
1014 (inhibit-point-motion-hooks t) 1014 (inhibit-point-motion-hooks t)
1015 p) 1015 (flyspell-not-casechars (flyspell-get-not-casechars))
1016 (while (and (not r) (setq p (search-backward word bound t))) 1016 (bound (if (and bound
1017 (let ((lw (flyspell-get-word))) 1017 (> bound (point-min)))
1018 (if (and (consp lw) 1018 (- bound 1)))
1019 (if ignore-case 1019 (word-re (concat
1020 (string-equal (downcase (car lw)) (downcase word)) 1020 "\\(?:" flyspell-not-casechars "\\|\\`\\)"
1021 (string-equal (car lw) word))) 1021 (regexp-quote word)
1022 (setq r p) 1022 flyspell-not-casechars))
1023 (goto-char p)))) 1023 p)
1024 (while
1025 (and (not r)
1026 (setq p
1027 (and
1028 (re-search-backward word-re bound t)
1029 (if (bobp)
1030 (point)
1031 (forward-char)
1032 (point)))))
1033 (let ((lw (flyspell-get-word)))
1034 (if (and (consp lw)
1035 (if ignore-case
1036 (string-equal (downcase (car lw)) (downcase word))
1037 (string-equal (car lw) word)))
1038 (setq r p)
1039 (goto-char p))))
1024 r))) 1040 r)))
1025 1041
1026;;*---------------------------------------------------------------------*/ 1042;;*---------------------------------------------------------------------*/
@@ -1028,14 +1044,28 @@ Mostly we check word delimiters."
1028;;*---------------------------------------------------------------------*/ 1044;;*---------------------------------------------------------------------*/
1029(defun flyspell-word-search-forward (word bound) 1045(defun flyspell-word-search-forward (word bound)
1030 (save-excursion 1046 (save-excursion
1031 (let ((r '()) 1047 (let* ((r '())
1032 (inhibit-point-motion-hooks t) 1048 (inhibit-point-motion-hooks t)
1033 p) 1049 (flyspell-not-casechars (flyspell-get-not-casechars))
1034 (while (and (not r) (setq p (search-forward word bound t))) 1050 (bound (if (and bound
1035 (let ((lw (flyspell-get-word))) 1051 (< bound (point-max)))
1036 (if (and (consp lw) (string-equal (car lw) word)) 1052 (+ bound 1)))
1037 (setq r p) 1053 (word-re (concat flyspell-not-casechars
1038 (goto-char (1+ p))))) 1054 (regexp-quote word)
1055 "\\(?:" flyspell-not-casechars "\\|\\'\\)"))
1056 p)
1057 (while
1058 (and (not r)
1059 (setq p (and
1060 (re-search-forward word-re bound t)
1061 (if (eobp)
1062 (point)
1063 (backward-char)
1064 (point)))))
1065 (let ((lw (flyspell-get-word)))
1066 (if (and (consp lw) (string-equal (car lw) word))
1067 (setq r p)
1068 (goto-char (1+ p)))))
1039 r))) 1069 r)))
1040 1070
1041;;*---------------------------------------------------------------------*/ 1071;;*---------------------------------------------------------------------*/