Subject: bug#21684: 25.0.50; undo in query-replace w/o exit

From: Juri Linkov <[email-masked]>
Date: Wed, 14 Oct 2015 19:23:05 +0300

> Quite often, performing query-replace, i just hit the [space] quicky
> with no much attention. If i replace one string by mistake, i can
> comeback to it with "^", but if i edit the string with "E" to reset it to
> its original value, the interactive query-replace session ends.
>
> I found useful if we can undo such replacements without exiting the
> query-replace.
>
> The attached patch implement such behaviour for `query-replace'.
> Having this also working for `query-replace-regexp' would be very nice,
> but harder to implement.

This would be a useful feature.  But I wonder why it's harder to
implement for regexps?  If you need, you could add all previous
replacements strings to the same stack at the end of data elements in
the stack like we did when necessary by adding new data at the end of the
similar isearch stack elements in isearch-cmds.  This would simplify
restoring the previous replaced strings from the stack.

PS: an alternative solution would be to call ordinary (undo) since
perform-replace places undo boundaries with (undo-boundary), but
it seems this would be a less reliable approach?