Subject: bug#14979: 24.3; Feature Request: query-replace-backward

From: Juri Linkov <[email-masked]>
Date: Mon, 29 Jul 2013 11:22:47 +0300

>>   1. M-<
>>   2. C-x n n
>>   3. C-M-%
>>   4. M->
>>   6. C-x n w
> Forgot step 0,
> 0. C-SPC

What you described is a feature known in other editors as
"Current selection only".  In Emacs you don't need to use
`C-x n n' and `C-x n w' because `query-replace' limits the
search to the selected region without the need to narrow it.
However, other editors also provide another feature to replace
backwards like you can see in e.g. OpenOffice etc.

So this is not a baseless wish to have the same in Emacs.

With the recent introduction of `replace-search' in replace.el
it's straightforward to implement this in Emacs where
`(isearch-forward t)' in `replace-search' could be replaced
with `(isearch-forward replace-forward)' where `replace-forward'
is a new option that can be changed in `isearch-query-replace'
according to the current value of `isearch-forward'.
The benefits of this feature is that it will replace exactly
the same matches that are lazy-highlighted and visited
by the backward isearch.