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

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

Re: killing the result of isearch


From: Bob Proulx
Subject: Re: killing the result of isearch
Date: Tue, 7 Nov 2017 13:59:06 -0700
User-agent: NeoMutt/20170609 (1.8.3)

Jean-Christophe Helary wrote:
> I have an isearch that highlights a string, and I just want to delete
> that string.
...
> But, isn't it something emacs users do normally? Search for a string
> and just delete it? Doesn't it look like a function that could be
> useful in vanilla emacs?

I have been using emacs for a very long time and that isn't a feature
I have ever missed.  However I will say that language shapes the way
you think.  If the language you use does or does not have a construct
then it shapes the way one thinks about it.  Emacs doesn't
intrinsically have that feature but has other features and therefore I
think and use those other features.

The answers suggesting M-% are excellent suggestions.  I think they
are the best suggestions.  But exploring other options are good for
learning how to do things in emacs too.  That is what I want to do at
this moment.

Here you see that in the default emacs configuration the search string
is highlighted (in what looks like purple on my testing, I will call
it purple) in the search face.  (Your colors may be different.)  But
the highlighted region face is what looks like brown to me.  Brown
hightlight means a region and pressing DEL (Backspace) would delete
it.  Purple is the search string.  They are different.

In fact if you have a text like this with the point at the 'N' in the
word "Now".

  Now is the time for all good men to come to the aid of their party.

And then type in "C-s party" it will set the mark at the 'N' and then
move the point to the '.' immedately after "party".  The "party" will
be highlighted in purple.  If you terminate the search then and there
with RET then the point is at the '.' and the mark is at the 'N' and
the region is not active.  The region is always the text between the
point and the mark.  You can use C-x C-x to exchange-point-and-mark to
show the region.  Doing that will activate the region.  At that time
you will see that the region covers the entire text fron 'N' to the
'y' of "party".  (But not the '.' after party since that wasn't between
mark and point.)

The typical deletions (killing text in emacs speak) act upon either
single characters or the region.  The region between the point and the
mark.  In order to make the search string a region one wants to make
the point and mark to be placed surrounding the text to be deleted.
How would someone do that.  How would *I* do that.  I would do it like
this.

I would "C-s party" to move point to the end of party.  Seeing that it
is a single word I would simply use M-DEL backward-kill-word to delete
the word behind.  It will terminate the search and then delete the
word behind.  VoilĂ !  The task is done exactly as you wish.

But then one might ask, "What about strings that are more than one
word?"  In that case I would do tihs.  I would "C-s party" to move
point to the end of party.  Knowing that mark was left at the previous
location of the point I would then use C-r to reverse search the same
string.  That will move the point to the start of the search string.
The point would be at the 'p' in "party".  I would press RET to
terminate the search.  The mark is still far away at the previous
location of the point.

But the search has been saved.  I would then press C-s C-s twice.
Once to start a new search and again a second time for
isearch-repeat-forward to recall the previous search.  That will move
the point to the end of the search string and will set a new mark at
the previous location at the start of the search string.  At that
point the point and mark are around the text to be deleted.  Then I
will use C-x C-x to exchange-point-and-mark and to activate the region
showing it.  Then C-w to kill-region it.  (Killing text puts it into
the kill ring.)

  Let's change "One-two, Buckle my shoe" to something else.

  C-s one-two, buckle my shoe C-r RET C-s C-s RET C-x C-x C-w

It's more keys than M-% but the above are all mainstream keys that an
emacs user would press a zillion times a day.  I don't even think
about them.  They just happen reflexively.  And at each step along the
way I have positive feedback from the editor telling me what is
highlighted, what is happening, and what will be deleted when I delete
it.  No stress editing.

Personally I never use the highlighted region.  Using C-x C-x to
exchange-point-and-mark is perfect for me to know what is the region
that will be deleted.  This means that instead of using DEL to delete
a highlighted region that I will use C-w to kill-region instead.  Shrug.

Personally I always bind C-s to isearch-forward-regexp instead of
leaving it at isearch-forward.  Regular expressions are so much more
powerful and useful.  "C-s one.*shoe" matches the entire string I want
to change with much fewer characters.  Learning regular expressions
makes for powerful editing capability.

Again using M-% seems perfect here but hopefully at least some of you
enjoyed seeing the thought process another person might use to perform
this task using the mainstream commands.

Bob



reply via email to

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