changeset 27009:2439fc8b756c

(ispell-process-line): Add local var line-offset to adjust for the change in positions within the line, due to previous replacements.
author Richard M. Stallman <rms@gnu.org>
date Tue, 28 Dec 1999 05:34:54 +0000
parents 42410fba715f
children 4be26de6d837
files lisp/textmodes/ispell.el
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/ispell.el	Tue Dec 28 03:36:21 1999 +0000
+++ b/lisp/textmodes/ispell.el	Tue Dec 28 05:34:54 1999 +0000
@@ -2252,7 +2252,12 @@
 
 (defun ispell-process-line (string)
   ;;(declare special start end)
-  (let (poss)
+  (let (poss
+	;; line-offset is the change so far in the size of the line.
+	;; The position values we get from ispell reflect the original
+	;; text, and correction of previous words may have shifted the
+	;; current word within the line.
+	(line-offset 0))
     ;; send string to spell process and get input.
     (process-send-string ispell-process string)
     (while (progn
@@ -2270,7 +2275,8 @@
 	  ;; Markers can move with highlighting!  This destroys
 	  ;; end of region markers line-end and ispell-region-end
 	  (let ((word-start
-		 (copy-marker (+ start ispell-offset (car (cdr poss)))))
+		 (copy-marker (+ start ispell-offset line-offset
+				 (car (cdr poss)))))
 		(word-len (length (car poss)))
 		(line-end (copy-marker end))
 		(line-start (copy-marker start))
@@ -2323,6 +2329,7 @@
 		    recheck-region t)
 	      (delete-region (point) (+ word-len (point)))
 	      (insert (car replace))
+	      (setq line-offset (+ line-offset (- line-end end)))
 	      ;; Only typed-in replacements need to be re-checked.
 	      (if (not (eq 'query-replace (car (cdr replace))))
 		  (backward-char (length (car replace))))
@@ -2355,6 +2362,8 @@
 	     (replace			; STRING REPLACEMENT for this word.
 	      (delete-region (point) (+ word-len (point)))
 	      (insert replace)
+	      (setq line-offset (+ line-offset (- line-end end)))
+
 	      (set-marker line-start (+ line-start
 					(- (length replace)
 					   (length (car poss)))))))