- (progn (message "Replace? Type Yes, No, All, Last, or Quit: ")
- (let ((ans (read-char)))
-
- (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\r) (= ans ?\ ))
- (let ((beg (point)))
- (replace-match to (not case-replace) (not tpu-regexp-p))
- (setq strings (1+ strings))
- (if tpu-searching-forward (forward-char -1) (goto-char beg)))
- (tpu-search-internal from t))
-
- ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
- (tpu-search-internal from t))
-
- ((or (= ans ?a) (= ans ?A))
- (save-excursion
- (let ((beg (point)))
- (replace-match to (not case-replace) (not tpu-regexp-p))
- (setq strings (1+ strings))
- (if tpu-searching-forward (forward-char -1) (goto-char beg)))
- (tpu-search-internal-core from t)
- (while (tpu-check-match)
- (let ((beg (point)))
- (replace-match to (not case-replace) (not tpu-regexp-p))
- (setq strings (1+ strings))
- (if tpu-searching-forward (forward-char -1) (goto-char beg)))
- (tpu-search-internal-core from t)))
- (setq doit nil))
-
- ((or (= ans ?l) (= ans ?L))
- (let ((beg (point)))
- (replace-match to (not case-replace) (not tpu-regexp-p))
- (setq strings (1+ strings))
- (if tpu-searching-forward (forward-char -1) (goto-char beg)))
- (setq doit nil))
-
- ((or (= ans ?q) (= ans ?Q))
- (setq doit nil)))))))
-
- (message "Replaced %s occurrence%s." strings
- (if (not (= 1 strings)) "s" ""))))
+ (progn
+ (move-overlay tpu-replace-overlay
+ (tpu-match-beginning) (tpu-match-end) (current-buffer))
+ (message "Replace? Type Yes, No, All, Last, or Quit: ")
+ (let ((ans (read-char)))
+
+ (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\r) (= ans ?\ ))
+ (let ((beg (point)))
+ (replace-match to (not case-replace) (not tpu-regexp-p))
+ (setq strings (1+ strings))
+ (if tpu-searching-forward (forward-char -1) (goto-char beg)))
+ (tpu-search-internal from t))
+
+ ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
+ (tpu-search-internal from t))
+
+ ((or (= ans ?a) (= ans ?A))
+ (save-excursion
+ (let ((beg (point)))
+ (replace-match to (not case-replace) (not tpu-regexp-p))
+ (setq strings (1+ strings))
+ (if tpu-searching-forward (forward-char -1) (goto-char beg)))
+ (tpu-search-internal-core from t)
+ (while (tpu-check-match)
+ (let ((beg (point)))
+ (replace-match to (not case-replace) (not tpu-regexp-p))
+ (setq strings (1+ strings))
+ (if tpu-searching-forward (forward-char -1) (goto-char beg)))
+ (tpu-search-internal-core from t)))
+ (setq doit nil))
+
+ ((or (= ans ?l) (= ans ?L))
+ (let ((beg (point)))
+ (replace-match to (not case-replace) (not tpu-regexp-p))
+ (setq strings (1+ strings))
+ (if tpu-searching-forward (forward-char -1) (goto-char beg)))
+ (setq doit nil))
+
+ ((or (= ans ?q) (= ans ?Q))
+ (tpu-unset-match)
+ (setq doit nil)))))))
+
+ (move-overlay tpu-replace-overlay 1 1 (current-buffer))
+ (message "Replaced %s occurrence%s." strings (if (not (= 1 strings)) "s" ""))))