Subject: Re: bug#22097: Ispell: lazy highlighting doesn't work properly.

From: Juri Linkov <[email-masked]>
Date: Tue, 08 Dec 2015 02:47:32 +0200

> Another limitation is limiting lazy-highlighting by reg-start/reg-end
> instead of a wider area of window-start/window-end.

This patch addresses this limitation: it limits the highlighting area
either to the region boundaries, or to the window boundaries.

diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index aa51446..82c589d 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -2786,6 +2786,8 @@ ispell-highlight-spelling-error-xemacs
   ;;(sit-for 0)
   )
 
+(defvar ispell-reg-start nil)
+(defvar ispell-reg-end nil)
 
 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
   "Highlight the word from START to END using overlays.
@@ -2815,8 +2817,8 @@ ispell-highlight-spelling-error-overlay
 		(isearch-other-end start)
 		(isearch-error nil))
 	    (isearch-lazy-highlight-new-loop
-	     (if (boundp 'reg-start) reg-start)
-	     (if (boundp 'reg-end)   reg-end)))
+	     (if (not (eq ispell-reg-start (point-min))) ispell-reg-start (window-start))
+	     (if (not (eq ispell-reg-end   (point-max))) ispell-reg-end   (window-end))))
 	(lazy-highlight-cleanup lazy-highlight-cleanup)
 	(setq isearch-lazy-highlight-last-string nil))))
 
@@ -3211,6 +3213,7 @@ ispell-region
 amount for last line processed."
   (interactive "r")			; Don't flag errors on read-only bufs.
   (ispell-set-spellchecker-params)      ; Initialize variables and dicts alists
+  (setq ispell-reg-start reg-start ispell-reg-end reg-end)
   (if (not recheckp)
       (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
   (let ((skip-region-start (make-marker))