help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to search inside a region that has just been used as the target of a


From: Evan Aad
Subject: How to search inside a region that has just been used as the target of a replace operation?
Date: Fri, 27 Jan 2023 10:55:26 +0200

I'd like to be able to search inside a region that has just been used
as the target of a replace operation, without having to specify
explicitly the region's start and end points.

Here's a concrete usage scenario:
1. Initial state: the current buffer contains the text "ABCBD", and
the cursor is on 'A'.
2. Select the region "BCB": C-f C-SPC C-f C-f C-f.
3. Replace all occurrences of the string "C" inside the selected
region: M-x replace-string, C, c.
The buffer's content is now "ABcBD".

Goal: Replace all occurrences of the string "B" inside the region
selected previously by the string "b", so that, at the end of the
operation, the buffer's content will be "AbcbD".

I'd like to accomplish the goal without having to explicitly specify
the region's start and end points.

How can this be accomplished?

Attempt no. 1, the naive approach:

4. Replace all occurrences of the string "B" by the string "b"
starting from the state that was in effect at the end of step no. 3:
M-x replace-string, B, b.

In the end the buffer's content was "ABcbD". The goal is not met,
because the first occurrence of 'B' was not replaced, even though it
was part of the original region.

Attemp no. 2, reactivate the region:

4. Reactivate the region: C-x C-X.
5. Replace all occurrences of the string "B" by the string "b": M-x
replace-string, B, b.

In the end the buffer's content was "AbcBD". The goal is not met,
because the second occurrence of 'B' has not been replaced, even
though it was part of the original region.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]