killing the result of isearch

classic Classic list List threaded Threaded
47 messages Options
123
Reply | Threaded
Open this post in threaded view
|

killing the result of isearch

Jean-Christophe Helary
I must be missing something big...

I have an isearch that highlights a string, and I just want to delete that string.

In other editors I'd just hit delete on that selection, but that won't work in emacs...



Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com



Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
> I must be missing something big...

No, you're not.

> I have an isearch that highlights a string, and I just
> want to delete that string.
>
> In other editors I'd just hit delete on that selection,
> but that won't work in emacs...

Not in vanilla Emacs, no; it won't work.

If you use Isearch+ then you can hit `C-M-RET' to delete the
search hit.  (The current search hit is not the "selection",
BTW, in the sense of being the Emacs region.)

[If you prefer that the key for this be, say, the `<delete>'
key, then just bind command `isearchp-act-on-demand' to
`(kbd "<delete>")' in `isearch-mode-map'.]

With Isearch+, `C-M-RET' performs an action on the current
search hit.  By default, the action is to replace it with
some replacement text.  And by default that replacement
text is empty (""), i.e., the search hit is deleted.

The value of option `isearchp-on-demand-action-function'
is the function that acts on the current search hit, which
it is passed when you hit `C-M-RET', along with the buffer
start and end positions of the search hit.

After applying the action, search moves to the next hit in
the same search direction, so just repeating `C-M-RET'
carries out the action on subsequent hits.

With a prefix argument, `C-M-RET'  prompts for the
replacement text, which is used thereafter until you again
use a prefix arg.  (Again, no prefix arg means empty
replacement text, i.e., deletion.)

Since you can use a prefix arg at any time, you can
provide different replacements for different search hits
corresponding to the same search pattern.

[To use a prefix arg within Isearch, you must set
`isearch-allow-prefix' to non-`nil'.]

There's more you can do with it.  See here:

https://www.emacswiki.org/emacs/IsearchPlus#isearchp-act-on-demand


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary


> On Nov 7, 2017, at 14:34, Drew Adams <[hidden email]> wrote:
>
>> I must be missing something big...
>
> No, you're not.

I'm not sure that makes me feel better... But that you very much for the thorough reply.

>> I have an isearch that highlights a string, and I just want to delete that string.
>>
>> In other editors I'd just hit delete on that selection, but that won't work in emacs...
>
> Not in vanilla Emacs, no; it won't work.

> If you use Isearch+

Is there a way to emulate that in vanilla emacs?
Well, I guess yes, by creating the adequate function, etc.

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?

Jean-Christophe

> then you can hit `C-M-RET' to delete the
> search hit.  (The current search hit is not the "selection",
> BTW, in the sense of being the Emacs region.)
>
> [If you prefer that the key for this be, say, the `<delete>'
> key, then just bind command `isearchp-act-on-demand' to
> `(kbd "<delete>")' in `isearch-mode-map'.]
>
> With Isearch+, `C-M-RET' performs an action on the current
> search hit.  By default, the action is to replace it with
> some replacement text.  And by default that replacement
> text is empty (""), i.e., the search hit is deleted.
>
> The value of option `isearchp-on-demand-action-function'
> is the function that acts on the current search hit, which
> it is passed when you hit `C-M-RET', along with the buffer
> start and end positions of the search hit.
>
> After applying the action, search moves to the next hit in
> the same search direction, so just repeating `C-M-RET'
> carries out the action on subsequent hits.
>
> With a prefix argument, `C-M-RET'  prompts for the
> replacement text, which is used thereafter until you again
> use a prefix arg.  (Again, no prefix arg means empty
> replacement text, i.e., deletion.)
>
> Since you can use a prefix arg at any time, you can
> provide different replacements for different search hits
> corresponding to the same search pattern.
>
> [To use a prefix arg within Isearch, you must set
> `isearch-allow-prefix' to non-`nil'.]
>
> There's more you can do with it.  See here:
>
> https://www.emacswiki.org/emacs/IsearchPlus#isearchp-act-on-demand
>

Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Søren Pilgård
On Nov 7, 2017 7:04 AM, "Jean-Christophe Helary" <
[hidden email]> wrote:



> On Nov 7, 2017, at 14:34, Drew Adams <[hidden email]> wrote:
>
>> I must be missing something big...
>
> No, you're not.

I'm not sure that makes me feel better... But that you very much for the
thorough reply.

>> I have an isearch that highlights a string, and I just want to delete
that string.
>>
>> In other editors I'd just hit delete on that selection, but that won't
work in emacs...
>
> Not in vanilla Emacs, no; it won't work.

> If you use Isearch+

Is there a way to emulate that in vanilla emacs?
Well, I guess yes, by creating the adequate function, etc.

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?

Jean-Christophe

> then you can hit `C-M-RET' to delete the
> search hit.  (The current search hit is not the "selection",
> BTW, in the sense of being the Emacs region.)
>
> [If you prefer that the key for this be, say, the `<delete>'
> key, then just bind command `isearchp-act-on-demand' to
> `(kbd "<delete>")' in `isearch-mode-map'.]
>
> With Isearch+, `C-M-RET' performs an action on the current
> search hit.  By default, the action is to replace it with
> some replacement text.  And by default that replacement
> text is empty (""), i.e., the search hit is deleted.
>
> The value of option `isearchp-on-demand-action-function'
> is the function that acts on the current search hit, which
> it is passed when you hit `C-M-RET', along with the buffer
> start and end positions of the search hit.
>
> After applying the action, search moves to the next hit in
> the same search direction, so just repeating `C-M-RET'
> carries out the action on subsequent hits.
>
> With a prefix argument, `C-M-RET'  prompts for the
> replacement text, which is used thereafter until you again
> use a prefix arg.  (Again, no prefix arg means empty
> replacement text, i.e., deletion.)
>
> Since you can use a prefix arg at any time, you can
> provide different replacements for different search hits
> corresponding to the same search pattern.
>
> [To use a prefix arg within Isearch, you must set
> `isearch-allow-prefix' to non-`nil'.]
>
> There's more you can do with it.  See here:
>
> https://www.emacswiki.org/emacs/IsearchPlus#isearchp-act-on-demand
>

Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


You could just use the query-replace functionality with an empty string.
Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Loris Bennett
In reply to this post by Jean-Christophe Helary
Søren Pilgård <[hidden email]> writes:

> On Nov 7, 2017 7:04 AM, "Jean-Christophe Helary" <
> [hidden email]> wrote:
>
>
>
>> On Nov 7, 2017, at 14:34, Drew Adams <[hidden email]> wrote:
>>
>>> I must be missing something big...
>>
>> No, you're not.
>
> I'm not sure that makes me feel better... But that you very much for the
> thorough reply.
>
>>> I have an isearch that highlights a string, and I just want to delete
> that string.
>>>
>>> In other editors I'd just hit delete on that selection, but that won't
> work in emacs...
>>
>> Not in vanilla Emacs, no; it won't work.
>
>> If you use Isearch+
>
> Is there a way to emulate that in vanilla emacs?
> Well, I guess yes, by creating the adequate function, etc.
>
> 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 can sort of imagine that such a function might be useful, but in
several decades of using Emacs, both writing code and prose, I've
honestly never missed it.  What is your use case?  The closest I come is
search and replace, so you could just replace with an empty string.
However, searching and then doing 'C-backspace' deletes the word found
on my system.

Cheers,

Loris

> Jean-Christophe
>
>> then you can hit `C-M-RET' to delete the
>> search hit.  (The current search hit is not the "selection",
>> BTW, in the sense of being the Emacs region.)
>>
>> [If you prefer that the key for this be, say, the `<delete>'
>> key, then just bind command `isearchp-act-on-demand' to
>> `(kbd "<delete>")' in `isearch-mode-map'.]
>>
>> With Isearch+, `C-M-RET' performs an action on the current
>> search hit.  By default, the action is to replace it with
>> some replacement text.  And by default that replacement
>> text is empty (""), i.e., the search hit is deleted.
>>
>> The value of option `isearchp-on-demand-action-function'
>> is the function that acts on the current search hit, which
>> it is passed when you hit `C-M-RET', along with the buffer
>> start and end positions of the search hit.
>>
>> After applying the action, search moves to the next hit in
>> the same search direction, so just repeating `C-M-RET'
>> carries out the action on subsequent hits.
>>
>> With a prefix argument, `C-M-RET'  prompts for the
>> replacement text, which is used thereafter until you again
>> use a prefix arg.  (Again, no prefix arg means empty
>> replacement text, i.e., deletion.)
>>
>> Since you can use a prefix arg at any time, you can
>> provide different replacements for different search hits
>> corresponding to the same search pattern.
>>
>> [To use a prefix arg within Isearch, you must set
>> `isearch-allow-prefix' to non-`nil'.]
>>
>> There's more you can do with it.  See here:
>>
>> https://www.emacswiki.org/emacs/IsearchPlus#isearchp-act-on-demand
>>
>
> Jean-Christophe Helary
> -----------------------------------------------
> @brandelune http://mac4translators.blogspot.com
>
>
> You could just use the query-replace functionality with an empty string.

--
Dr. Loris Bennett (Mr.)
ZEDAT, Freie Universität Berlin         Email [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary

> On Nov 7, 2017, at 16:07, Loris Bennett <[hidden email]> wrote:
>
> I can sort of imagine that such a function might be useful, but in several decades of using Emacs, both writing code and prose, I've honestly never missed it.  What is your use case?

Acting on the matching string. Yank, kill, overwrite. Things that you can do in other editors where the result of a search is a selection.

> The closest I come is search and replace, so you could just replace with an empty string.

isearch
isearch-query-replace
C-w


> However, searching and then doing 'C-backspace' deletes the word found on my system.

Thank you, I guess that's what I was looking for.

It's confusing to have "delete" act where point is *not* (ie in the mini buffer).


Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Marcin Borkowski-3
In reply to this post by Jean-Christophe Helary

On 2017-11-07, at 07:01, Jean-Christophe Helary <[hidden email]> wrote:

> 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?

How about this?

C-s whatever M-% RET .

Explanation: when in isearch, typing M-% starts query-replace
prepopulated with isearched string.  RET makes the replacement empty.
`.' (period) performs a replacements and exits query-replace.

Hth,

--
Marcin Borkowski

Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary
In reply to this post by Loris Bennett


> On Nov 7, 2017, at 16:07, Loris Bennett <[hidden email]> wrote:
>
> However, searching and then doing 'C-backspace' deletes the word found

But it does not delete any arbitrary string matching the search. It just happens to look like it works because the point is at the end of the matching string and what you searched was a word.

If I search for
="2"
C-backspace will only delete the last 2 characters.

So I'm back to the beginning.


Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Loris Bennett
In reply to this post by Loris Bennett
Jean-Christophe Helary <[hidden email]> writes:

>> On Nov 7, 2017, at 16:07, Loris Bennett <[hidden email]> wrote:
>>
>> However, searching and then doing 'C-backspace' deletes the word found
>
> But it does not delete any arbitrary string matching the search. It
> just happens to look like it works because the point is at the end of
> the matching string and what you searched was a word.
>
> If I search for
> ="2"
> C-backspace will only delete the last 2 characters.
>
> So I'm back to the beginning.

So doesn't searching-and-replace with an empty replacement work?

In any case, as Drew pointed out, I think your expectation of how Emacs
regions behaves is not justified.  If you start marking part of a word
with C-<space>, you also can't just overwrite it.

As to Emacs behaving differently to other editors, I think it is the
other way round ;-)

Cheers,

Loris

--
Dr. Loris Bennett (Mr.)
ZEDAT, Freie Universität Berlin         Email [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary


> On Nov 7, 2017, at 19:49, Loris Bennett <[hidden email]> wrote:
>
>
> So doesn't searching-and-replace with an empty replacement work?

It works to accomplish the same result but it takes many more step as I wrote earlier:

isearch string
isearch-query-replace
(replace with nothing)

> As to Emacs behaving differently to other editors, I think it is the
> other way round ;-)

No, actually it really is the other way round. Emacs is not a text editor, it is a Lisp virtual machine with text editing functions. Applications that are created to be specialized in text editing are closer to what the users need in terms of interaction. Which is the point of the current discussion.

The problem with emacs and searches, is that you only search, you don't *find*, as in the action of searching does not result in an object that you can act upon. Which defeats the purpose of searching.

A simple "search" does nothing but put the point at the end of the match. it is nice to navigate the document but it does nothing about the match. isearch is even more treacherous since it makes it look like you are finding something, when actually you have also just moved the point in the buffer and nothing more.

A simple "search" should at least be able to create a region on the match, it doesn't even do that.



Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Loris Bennett
In reply to this post by Loris Bennett
Jean-Christophe Helary <[hidden email]> writes:

>> On Nov 7, 2017, at 19:49, Loris Bennett <[hidden email]> wrote:
>>
>>
>> So doesn't searching-and-replace with an empty replacement work?
>
> It works to accomplish the same result but it takes many more step as I wrote
> earlier:
>
> isearch string isearch-query-replace (replace with nothing)
>
>> As to Emacs behaving differently to other editors, I think it is the other way
>> round ;-)
>
> No, actually it really is the other way round. Emacs is not a text editor, it is
> a Lisp virtual machine with text editing functions.

According to https://www.gnu.org/software/emacs/ GNU Emacs is:

  An extensible, customizable, free/libre text editor — and more.

> Applications that are created to be specialized in text editing are
> closer to what the users need in terms of interaction. Which is the
> point of the current discussion.

My point was that you are comparing the editing idiom of Emacs, which
arose in the 1980s, with that of more modern editors.  In addition, you
are talking about what you need, rather than what "users" need.

> The problem with emacs and searches, is that you only search, you don't *find*,
> as in the action of searching does not result in an object that you can act
> upon. Which defeats the purpose of searching.
>
> A simple "search" does nothing but put the point at the end of the match. it is
> nice to navigate the document but it does nothing about the match. isearch is
> even more treacherous since it makes it look like you are finding something,
> when actually you have also just moved the point in the buffer and nothing more.
>
> A simple "search" should at least be able to create a region on the match, it
> doesn't even do that.

If Emacs doesn't do something, to me, that suggests it is not a very
common thing to do.  However, fortunately Emacs is extensible and
customizable and so you can make it do less common things too.

Cheers,

Loris

--
Dr. Loris Bennett (Mr.)
ZEDAT, Freie Universität Berlin         Email [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
In reply to this post by Jean-Christophe Helary
> > If you use Isearch+
>
> Is there a way to emulate that in vanilla emacs?
> Well, I guess yes, by creating the adequate function, etc.

Isearch+ is defined using vanilla Emacs. ;-)

And yes, any or all of it could be added to Emacs, if
someone were interested.  Or you can just use it as is.
Why not?  It's not a big deal to load a Lisp file.

> 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?

Some Emacs users long ago suggested that setting the
region around the final search target (the last search
hit you visit) can be useful - including for killing it.
I added that feature to Isearch+ in 2006.

It was later (2013, I think) that I added the ability to
act arbitrarily on any number of search hits, selectively
(on demand) during (not after) Isearch.

Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
In reply to this post by Jean-Christophe Helary
> > So doesn't searching-and-replace with an empty replacement work?
>
> It works to accomplish the same result but it takes many more step as I
> wrote earlier:
>
> isearch string
> isearch-query-replace
> (replace with nothing)
...
> The problem with emacs and searches, is that you only search, you don't
> *find*, as in the action of searching does not result in an object that you
> can act upon. Which defeats the purpose of searching.

It does result in an object you can act upon, if you want
that.  Isearch+ gives you that possibility, including the
possibility of setting the region on that object.

> A simple "search" does nothing but put the point at the end of the match.
> it is nice to navigate the document but it does nothing about the match.
> isearch is even more treacherous since it makes it look like you are
> finding something, when actually you have also just moved the point in the
> buffer and nothing more.
>
> A simple "search" should at least be able to create a region on the match,
> it doesn't even do that.

Have you actually tried Isearch+?  As I mentioned, I think
it offers what you're requesting.

As for those who propose query-replace as a substitute for
acting on search hits during Isearch:

* q-r is OK for replacing, but that's the only action it knows

* q-r is one-directional, and not embedded in Isearch: The
  search pattern and replacement patterns are fixed, once
  and for all.

The search-hit replacement (or other action) provided by
Isearch+ is on-demand, and you can change what it acts
on (search pattern, hence search hits) and the replacement
text at any time.

Q-r is nice, and it's good you can invoke it from Isearch,
but it is not the same thing as on-demand replacement
during search.

Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary
In reply to this post by Loris Bennett


> On Nov 8, 2017, at 0:08, Loris Bennett <[hidden email]> wrote:
>
>> Emacs is not a text editor, it is
>> a Lisp virtual machine with text editing functions.
>
> According to https://www.gnu.org/software/emacs/ GNU Emacs is:
>  An extensible, customizable, free/libre text editor — and more.

Obviously. Who wants a Lisp virtual machine nowadays.

> My point was that you are comparing the editing idiom of Emacs, which
> arose in the 1980s, with that of more modern editors.  In addition, you
> are talking about what you need, rather than what "users" need.

No, I am actually talking about expectations from using emacs where regions are highlighted, like what isearch seems like doing. What I am seeing is what looks like a region (and except for the active match, all the others are highlighted exactly as a region would be), but it doesn't act like a region. So there is a UI promise that's broken.


Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Jean-Christophe Helary
In reply to this post by Drew Adams


> On Nov 8, 2017, at 0:26, Drew Adams <[hidden email]> wrote:
>
>>> So doesn't searching-and-replace with an empty replacement work?
>>
>> It works to accomplish the same result but it takes many more step as I
>> wrote earlier:
>>
>> isearch string
>> isearch-query-replace
>> (replace with nothing)
> ...
>> The problem with emacs and searches, is that you only search, you don't
>> *find*, as in the action of searching does not result in an object that you
>> can act upon. Which defeats the purpose of searching.
>
> It does result in an object you can act upon, if you want
> that.

Would you mind being more specific ?

I have no problem using new libraries, but I want to understand why I am missing what I think I am missing. If I understood searches (isearches ?) better, maybe I would not have my questions.

> Q-r is nice, and it's good you can invoke it from Isearch,
> but it is not the same thing as on-demand replacement
> during search.

Exactly.

Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com


Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
In reply to this post by Jean-Christophe Helary
> Who wants a Lisp virtual machine nowadays.

I do.  What better plaything is there?

> I am actually talking about expectations from using emacs where regions
> are highlighted, like what isearch seems like doing. What I am seeing is
> what looks like a region (and except for the active match, all the others
> are highlighted exactly as a region would be), but it doesn't act like a
> region. So there is a UI promise that's broken.

That's not what I see in vanilla Emacs: `emacs -Q'.

I had to check, because I don't generally use `emacs -Q'.
I was half expecting you might be right, in which case I
would have suggested that you use `M-x report-emacs-bug' to
request that different faces be used for Isearch and for
the region.  But I see that that is already the case, as it
should be

You must be using some customization (perhaps from a
library you use), which gives face `lazy-highlight' and
face `region' the same appearance.  Their appearance is
quite different in virginal Emacs.

Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
In reply to this post by Jean-Christophe Helary
> > It does result in an object you can act upon, if you want
> > that.
>
> Would you mind being more specific ?

The code finds a match (over and over: successive matches).
Code (hence you) can act on the current match.  Or code/you
can act on only the last match that you visit.

Everything you need to code the feature you ask for is in the
Isearch source code.  If you don't want to dig into that code
yourself, you're lucky: Isearch+ already provides what you need:

1. A variable whose value can be any function you want,
   tailor-made to act on any current match when you hit a key.

   Write any number of commands, which bind that variable
   to different action functions.  Bind those commands to
   keys in `isearch-mode-map'.  Now you have N keys you can
   hit to perform N different actions on a search hit.
   Pretty good, no?

2. As for acting on the last-visited match, after searching:
   Isearch+ lets you automatically, or on-demand, select it
   as the active region.  You can then use any Emacs command
   that acts on the active region to act on it.  And you can
   define your own such commands, to act on it any way you like.

Be aware too that after you exit Isearch, you can always use
the many Emacs commands that act on text before point or that
move point backward.  There is a lot you can do to the text
before point, even without selecting the part that matches
your last search.  Emacs has commands for moving among and
killing sexps, for example.

> I have no problem using new libraries, but I want to understand why I am
> missing what I think I am missing. If I understood searches (isearches ?)
> better, maybe I would not have my questions.

You are missing what you think you are missing from vanilla
Emacs.  Why?  Because either (1) no one has considered them
important/useful enough to add or (2) no one has volunteered
to work on implementing them.

Emacs is developed by volunteers.  Features are added to it
when its core developers decide to do so.  There are tons
of wonderful Emacs features that have not been incorporated
into vanilla Emacs.  Sometimes that's good; sometimes it's
not so good.  What gets done in vanilla Emacs is a function
of those who contribute directly to its development.  They
do what they want (think is best), naturally.

I think that lots of features that Isearch+ provides, perhaps
all, would make sense in vanilla Emacs.  I've volunteered them.
But it's not for me to decide.

In any case, you can use them now - easily.  You don't need
them to be added to vanilla Emacs to take advantage of them.

Above is just my answer to your "Why not?" question.  What
you're looking for is not part of Emacs by default because
those who maintain Emacs haven't added it - nothing more.
That doesn't mean you're not understanding something, and
it doesn't imply that they're not understanding something.
People are different.

> > Q-r is nice, and it's good you can invoke it from Isearch,
> > but it is not the same thing as on-demand replacement
> > during search.
>
> Exactly.

Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Eric Abrahamsen-2
In reply to this post by Jean-Christophe Helary
Jean-Christophe Helary <[hidden email]> writes:

>> On Nov 8, 2017, at 0:26, Drew Adams <[hidden email]> wrote:
>>
>>>> So doesn't searching-and-replace with an empty replacement work?
>>>
>>> It works to accomplish the same result but it takes many more step as I
>>> wrote earlier:
>>>
>>> isearch string
>>> isearch-query-replace
>>> (replace with nothing)
>> ...
>>> The problem with emacs and searches, is that you only search, you don't
>>> *find*, as in the action of searching does not result in an object that you
>>> can act upon. Which defeats the purpose of searching.
>>
>> It does result in an object you can act upon, if you want
>> that.
>
> Would you mind being more specific ?
>
> I have no problem using new libraries, but I want to understand why I
> am missing what I think I am missing. If I understood searches
> (isearches ?) better, maybe I would not have my questions.
>
>> Q-r is nice, and it's good you can invoke it from Isearch,
>> but it is not the same thing as on-demand replacement
>> during search.
>
> Exactly.

Several years ago, when I wanted to do this, I wrote the following:

(define-key isearch-mode-map (kbd "M-m") 'my-isearch-mark-search-as-region)
(defun my-isearch-mark-search-as-region ()
  (interactive)
  (if (not isearch-mode)
      (message "This is only useful during isearch")
    (isearch-exit)
    (push-mark isearch-other-end)
    (activate-mark)))

I guess that's just a tiny half-step in the direction that isearch+ is
headed.

Another very good facility to get comfortable with is recursive editing:
type "C-r" during search mode, do whatever editing you like, then
"C-M-c" to go back into search mode.

I think what people are trying to say is that Emacs' defaults can often
seem lacking, but it makes up for it by giving you enormous power to
create your ideal behavior yourself. I think this is probably born of
decades of strong personalities, wildly varying "ideal behavior", and a
distaste for bikeshedding. I think we all expect that we need to go the
last half-mile ourselves.

Eric


Reply | Threaded
Open this post in threaded view
|

RE: killing the result of isearch

Drew Adams
> Several years ago, when I wanted to do this, I wrote the following:
>
> (define-key isearch-mode-map (kbd "M-m") 'my-isearch-mark-search-as-region)
> (defun my-isearch-mark-search-as-region ()
>   (interactive)
>   (if (not isearch-mode)
>       (message "This is only useful during isearch")
>     (isearch-exit)
>     (push-mark isearch-other-end)
>     (activate-mark)))

That's essentially the same thing used in Isearch+:

(defun isearchp-set-region-around-search-target ()
  "Set the region around the last search or query-replace target."
  (interactive)
  (case last-command
    ((isearch-forward isearch-backward
      isearch-forward-regexp isearch-backward-regexp)
     (push-mark isearch-other-end t 'activate))
    (t (push-mark (match-beginning 0) t 'activate)))
  (setq deactivate-mark  nil))

> I guess that's just a tiny half-step in the direction that isearch+ is
> headed.

Isearch+ isn't really headed anywhere. ;-)  I just add/change things as
they come to me.

> Another very good facility to get comfortable with is recursive editing:
> type "C-r" during search mode, do whatever editing you like, then
> "C-M-c" to go back into search mode.

+1

But that's not in vanilla Emacs, AFAIK.  (It's certainly not
bound to `C-r' by default - `C-r' is ` isearch-repeat-backward'.)

With Isearch+, `C-x o' during Isearch opens a recursive edit.
And `C-M-c' (`exit-recursive-edit') resumes searching.

> I think what people are trying to say is that Emacs' defaults can often
> seem lacking, but it makes up for it by giving you enormous power to
> create your ideal behavior yourself...  I think we all expect that we
> need to go the last half-mile ourselves.

+1

But sometimes it's not so much that we need to go the last
half mile ourselves.  Sometimes it's more that we want to
go the next N miles, for fun and learning.

Reply | Threaded
Open this post in threaded view
|

Re: killing the result of isearch

Eric Abrahamsen-2
Drew Adams <[hidden email]> writes:

>> Several years ago, when I wanted to do this, I wrote the following:
>>
>> (define-key isearch-mode-map (kbd "M-m") 'my-isearch-mark-search-as-region)
>> (defun my-isearch-mark-search-as-region ()
>>   (interactive)
>>   (if (not isearch-mode)
>>       (message "This is only useful during isearch")
>>     (isearch-exit)
>>     (push-mark isearch-other-end)
>>     (activate-mark)))
>
> That's essentially the same thing used in Isearch+:
>
> (defun isearchp-set-region-around-search-target ()
>   "Set the region around the last search or query-replace target."
>   (interactive)
>   (case last-command
>     ((isearch-forward isearch-backward
>       isearch-forward-regexp isearch-backward-regexp)
>      (push-mark isearch-other-end t 'activate))
>     (t (push-mark (match-beginning 0) t 'activate)))
>   (setq deactivate-mark  nil))

Ah, I hadn't noticed the extra arguments to `push-mark', thanks. Anyway,
OP should be happy with `isearch-other-end'.

>> I guess that's just a tiny half-step in the direction that isearch+ is
>> headed.
>
> Isearch+ isn't really headed anywhere. ;-)  I just add/change things as
> they come to me.
>
>> Another very good facility to get comfortable with is recursive editing:
>> type "C-r" during search mode, do whatever editing you like, then
>> "C-M-c" to go back into search mode.
>
> +1
>
> But that's not in vanilla Emacs, AFAIK.  (It's certainly not
> bound to `C-r' by default - `C-r' is ` isearch-repeat-backward'.)
>
> With Isearch+, `C-x o' during Isearch opens a recursive edit.
> And `C-M-c' (`exit-recursive-edit') resumes searching.

Oops, that binding is for query-replace, not search. Another good
argument for simply starting out in (or switching to) query-replace.

>> I think what people are trying to say is that Emacs' defaults can often
>> seem lacking, but it makes up for it by giving you enormous power to
>> create your ideal behavior yourself...  I think we all expect that we
>> need to go the last half-mile ourselves.
>
> +1
>
> But sometimes it's not so much that we need to go the last
> half mile ourselves.  Sometimes it's more that we want to
> go the next N miles, for fun and learning.

Most definitely!


123