all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Evan Aad <oddeveneven@gmail.com>
To: help-gnu-emacs@gnu.org
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	[thread overview]
Message-ID: <CA+-Lr-Csosdunv5XdJk+2z4TxpmKVzan+7RkTBZ66r7LRn=20A@mail.gmail.com> (raw)

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	other threads:[~2023-01-27  8:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27  8:55 Evan Aad [this message]
2023-01-27  9:28 ` How to search inside a region that has just been used as the target of a replace operation? Anders Munch
2023-01-27 10:44   ` Evan Aad
2023-01-27 14:35     ` Evan Aad
2023-01-27 18:11     ` Marcin Borkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+-Lr-Csosdunv5XdJk+2z4TxpmKVzan+7RkTBZ66r7LRn=20A@mail.gmail.com' \
    --to=oddeveneven@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.