Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!husc6!mit-eddie!fh From: king@kestrel.ARPA Newsgroups: net.emacs Subject: minor mod to query-replace Message-ID: <3737@mit-eddie.MIT.EDU> Date: Thu, 6-Nov-86 18:06:27 EST Article-I.D.: mit-eddi.3737 Posted: Thu Nov 6 18:06:27 1986 Date-Received: Fri, 7-Nov-86 22:13:07 EST Sender: fh@mit-eddie.MIT.EDU Organization: M.I.T. EE/CS Computer Facility, Cambridge MA Lines: 51 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