Function: tpu-lm-replace
tpu-lm-replace is an interactive and byte-compiled function defined in
tpu-edt.el.gz.
Signature
(tpu-lm-replace FROM TO)
Documentation
Interactively search for OLD-string and substitute NEW-string.
Key Bindings
Aliases
replace (obsolete since 27.1)
REPLACE
Source Code
;; Defined in /usr/src/emacs/lisp/obsolete/tpu-edt.el.gz
(defun tpu-lm-replace (from to)
"Interactively search for OLD-string and substitute NEW-string."
(interactive (list (tpu-regexp-prompt "Old String: ")
(tpu-regexp-prompt "New String: ")))
(let ((doit t) (strings 0))
;; Can't replace null strings
(if (string= "" from) (tpu-error "No string to replace."))
;; Find the first occurrence
(tpu-set-search)
(tpu-search-internal from t)
;; Loop on replace question - yes, no, all, last, or quit.
(while doit
(if (not (tpu-check-match)) (setq doit nil)
(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" ""))))