king@kestrel.ARPA (11/07/86)
From: king@kestrel.ARPA (Dick King) First fix isearch as follows: first 3 lines (defun isearch (forward &optional regexp prompt) (let ((search-string "") (search-message (or prompt "")) (search message used to initialize to "") last line (message "") search-last-string)) instead of (message ""))) . This produces a callable form of isearch that returns the pattern. Then define (defun query-replace (from-string to-string &optional arg) "\ Replace some occurrences of FROM-STRING with TO-STRING. As each match is found, the user must type a character saying what to do with it. For directions, type \\[help-command] at that time. Preserves case in each replacement if case-replace and case-fold-search are non-nil and FROM-STRING has no uppercase letters. Third arg DELIMITED (prefix arg if interactive) non-nil means replace only matches surrounded by word boundaries." (interactive (let* ((search-exit-char ?\r) (point-orig (point)) (pattern (isearch t nil "(Query replace) "))) (goto-char (max point-orig (- (point) (length pattern)))) (list pattern (read-string (format "Query replace %s with: " pattern)) current-prefix-arg))) (perform-replace from-string to-string t nil arg)) and query-replace will do the first search incrementally. Warning - if you do a delimited query replace, the incremental search will not be delimited. -dick