unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Bob Proulx <bob@proulx.com>
To: help-gnu-emacs@gnu.org
Subject: Re: killing the result of isearch
Date: Tue, 7 Nov 2017 13:59:06 -0700	[thread overview]
Message-ID: <20171107132316472375613@bob.proulx.com> (raw)
In-Reply-To: <852BAA28-2A50-4AD9-B8D6-9F06905A4395@gmail.com>

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



  parent reply	other threads:[~2017-11-07 20:59 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07  2:41 killing the result of isearch Jean-Christophe Helary
2017-11-07  5:34 ` Drew Adams
2017-11-07  6:01   ` Jean-Christophe Helary
2017-11-07  6:25     ` Søren Pilgård
     [not found]     ` <mailman.3103.1510035932.27995.help-gnu-emacs@gnu.org>
2017-11-07  7:07       ` Loris Bennett
2017-11-07  7:49         ` Jean-Christophe Helary
2017-11-07  8:43         ` Jean-Christophe Helary
     [not found]         ` <mailman.3106.1510044223.27995.help-gnu-emacs@gnu.org>
2017-11-07 10:49           ` Loris Bennett
2017-11-07 12:45             ` Jean-Christophe Helary
2017-11-07 15:26               ` Drew Adams
2017-11-07 15:51                 ` Jean-Christophe Helary
2017-11-07 16:46                   ` Drew Adams
2017-11-07 22:38                     ` Jean-Christophe Helary
2017-11-07 16:53                   ` Eric Abrahamsen
2017-11-07 17:24                     ` Drew Adams
2017-11-07 17:45                       ` Eric Abrahamsen
2017-11-08  8:21               ` Thien-Thi Nguyen
2017-11-08 13:47                 ` Emanuel Berg
2017-11-11 15:36                   ` Charles A. Roelli
     [not found]             ` <mailman.3114.1510058721.27995.help-gnu-emacs@gnu.org>
2017-11-07 15:08               ` Loris Bennett
2017-11-07 15:28                 ` Jean-Christophe Helary
2017-11-07 16:24                   ` Drew Adams
2017-11-07 22:34                     ` Jean-Christophe Helary
2017-11-07 22:54                       ` Drew Adams
2017-11-08 22:24                   ` Tomas Nordin
2017-11-08 22:44                     ` Jean-Christophe Helary
2017-11-08 23:07                       ` Emanuel Berg
2017-11-09 21:38                       ` Tomas Nordin
2017-11-10 13:11                         ` Jean-Christophe Helary
2017-11-10 16:54                           ` Drew Adams
2017-11-07  8:31     ` Marcin Borkowski
2017-11-07 15:26     ` Drew Adams
2017-11-07 20:59     ` Bob Proulx [this message]
2017-11-07 22:10       ` Drew Adams
2017-11-07 22:53         ` Bob Proulx
2017-11-07 23:15       ` Jean-Christophe Helary
2017-11-08  4:27         ` Bob Proulx
2017-11-08  5:29           ` Jean-Christophe Helary
2017-11-08 18:50             ` Bob Proulx
2017-11-07 17:53 ` Stefan Monnier
2017-11-07 22:59   ` Jean-Christophe Helary
2017-11-12 20:02     ` Tomas Nordin
2017-11-12 22:13       ` Emanuel Berg
2017-11-13 21:17         ` Tomas Nordin
2017-11-13 22:13           ` Emanuel Berg
2017-11-20  3:24           ` Emanuel Berg
2017-11-15 14:48       ` Emanuel Berg

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20171107132316472375613@bob.proulx.com \
    --to=bob@proulx.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).