[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Query-replace is misbehaving!
From: |
lawrence mitchell |
Subject: |
Re: Query-replace is misbehaving! |
Date: |
Thu, 05 Sep 2002 00:07:34 +0100 |
User-agent: |
Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2.90 (i386-mingw-windows98.2222) |
Siegfried Heintze wrote:
> I need to surpress the prompt so I pass nil for query but it
> still queries! I am using emacs versino 21.2.1 on NT.
Since you want to suppress the prompt, I guess you want to use
`perform-replace' in a lisp program, rather than interactively
(if this is not the case, I'm not sure exactly where your problem
is). However, this is probably not a good idea.
Indeed, the docstring of `perform-replace' explicitly recommends
against its usage in lisp programs, and gives a recommended
alternative.
/----[ C-h f perform-replace RET ]
| [...]
| Subroutine of `query-replace'. Its complexity handles interactive queries.
| Don't use this in your own program unless you want to query and set the mark
| just as `query-replace' does. Instead, write a simple loop like this:
|
| (while (re-search-forward "foo[ \t]+bar" nil t)
| (replace-match "foobar" nil nil))
|
| which will run faster and probably do exactly what you want.
| [...]
\----
> (perform-replace "\\\\\\\\progra" ; from-string
> (concat (colonize *msvcdrive*) "\\\\\\\\progra") ; replacements
> (point-min) ; start
> (point-max) ; end
> nil ; query-flag
> t ; regexp
> nil)) ; delimited flags
Hence, you would probably want to write something like:
(save-excursion ; restore `point' to its
; original position after
; completion
(goto-char (point-min))
(while (re-search-forward
"\\\\\\\\progra" ; search forward for this regexp
nil ; don't set a bound on the search
t) ; don't error if search fails
(replace-match
(concat (colonize *msvcdrive*)
"\\\\\\\\progra")))) ; replace the matched string
--
lawrence mitchell <wence@gmx.li>