[Top][All Lists]

[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 15:53:17 -0700
User-agent: NeoMutt/20170609 (1.8.3)

Drew Adams wrote:
> >   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
> (You don't need the `C-x C-x' here, unless you want to
> see highlighted what `C-w' will delete.)

True.  But I always like the positive feedback about the region that
will be deleted.  So I am almost always using C-x C-x prior to region

Plus I was originally thinking of using DEL there and that needs the
highlight to be active.  In that case I needed C-x C-x to highlight
the region so that DEL would delete it.

> > 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.
> OK, but what you show above does not work, in general,
> for regexps.  Regexp search forward and backward do not
> find the same text, generally.

In the completely general case, true.  But most of the time they will
work fine.

  One:  One, two, buckle shoe.

  C-s one.*shoe

That will obviously match all of the way back to the "One:" part,
undesirably, when search forward.  But that doesn't invalidate the
technique all of the time.  I certainly wouldn't give up on regular
expressions simply because not every regular expression can be used in
every case.  And in the above if you try it forward with C-s and see
that it matches too much and then reverse direction with C-r one
finds that it matched exactly what was desired with non-greedy
matching.  (I haven't ever dug into figuring out why.)  But all along
the way there is feedback as to what is happening.  It isn't going to
silently do something scary.  I wouldn't avoid it.  Because that would
mean missing out on all of the capabilities of regular expressions.

> If you regexp-search for the same text, `one-two,
> buckle my shoe', no problem.  But if you use `o.*oe'
> you'll be in trouble.

Using "o" trying to match for "one" and "oe" trying to match for
"shoe" doesn't feel solid enough for me.  Matching only one and two
letters feels like it is asking to match something unexpected.  I
suggest putting enough text in there to anchor it firmly.  Remembering
that all of this is interacive editing, if it isn't doing what you
want then take corrective action and be more explicit by adding more
anchoring text.

When I took my CS200 intro to programming class at university some
time ago the first couple of weeks of the class was teaching us how to
use the text editor.  (What?  No programming?  No, learn to edit files
first!  I think today they expect students to already know how to edit
files, yet from what I can see most students could use a class on it.)
And they started us off right at the beginning editing with regular
expressions.  Literally we had to learn REs before even starting to
work on the programming assignments.  The department expected us to be
proficient editing text!  Looking back on it I am glad they did.  It
has been very useful to me.


reply via email to

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