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
This commit is contained in:
Agustin Martin Domingo 2015-02-12 18:38:11 +01:00
parent f5d1e1f550
commit a7254bbf99
2 changed files with 59 additions and 20 deletions

View file

@ -1,3 +1,12 @@
2015-02-12 Agustín Martín Domingo <agustin6martin@gmail.com>
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.
2015-02-10 Juri Linkov <juri@linkov.net> 2015-02-10 Juri Linkov <juri@linkov.net>
Better support for the case of typing RET on the prompt in comint. Better support for the case of typing RET on the prompt in comint.

View file

@ -92,7 +92,7 @@ downcased before comparing with these exceptions."
:version "21.1" :version "21.1"
:type 'boolean) :type 'boolean)
(defcustom flyspell-duplicate-distance -1 (defcustom flyspell-duplicate-distance 400000
"The maximum distance for finding duplicates of unrecognized words. "The maximum distance for finding duplicates of unrecognized words.
This applies to the feature that when a word is not found in the dictionary, This applies to the feature that when a word is not found in the dictionary,
if the same spelling occurs elsewhere in the buffer, if the same spelling occurs elsewhere in the buffer,
@ -1010,17 +1010,33 @@ Mostly we check word delimiters."
;;*---------------------------------------------------------------------*/ ;;*---------------------------------------------------------------------*/
(defun flyspell-word-search-backward (word bound &optional ignore-case) (defun flyspell-word-search-backward (word bound &optional ignore-case)
(save-excursion (save-excursion
(let ((r '()) (let* ((r '())
(inhibit-point-motion-hooks t) (inhibit-point-motion-hooks t)
p) (flyspell-not-casechars (flyspell-get-not-casechars))
(while (and (not r) (setq p (search-backward word bound t))) (bound (if (and bound
(let ((lw (flyspell-get-word))) (> bound (point-min)))
(if (and (consp lw) (- bound 1)))
(if ignore-case (word-re (concat
(string-equal (downcase (car lw)) (downcase word)) "\\(?:" flyspell-not-casechars "\\|\\`\\)"
(string-equal (car lw) word))) (regexp-quote word)
(setq r p) flyspell-not-casechars))
(goto-char p)))) 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))) r)))
;;*---------------------------------------------------------------------*/ ;;*---------------------------------------------------------------------*/
@ -1028,14 +1044,28 @@ Mostly we check word delimiters."
;;*---------------------------------------------------------------------*/ ;;*---------------------------------------------------------------------*/
(defun flyspell-word-search-forward (word bound) (defun flyspell-word-search-forward (word bound)
(save-excursion (save-excursion
(let ((r '()) (let* ((r '())
(inhibit-point-motion-hooks t) (inhibit-point-motion-hooks t)
p) (flyspell-not-casechars (flyspell-get-not-casechars))
(while (and (not r) (setq p (search-forward word bound t))) (bound (if (and bound
(let ((lw (flyspell-get-word))) (< bound (point-max)))
(if (and (consp lw) (string-equal (car lw) word)) (+ bound 1)))
(setq r p) (word-re (concat flyspell-not-casechars
(goto-char (1+ p))))) (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))) r)))
;;*---------------------------------------------------------------------*/ ;;*---------------------------------------------------------------------*/