unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Isearch: retrieve last successful search string from when you quit (`C-g')
@ 2012-09-30 21:09 Drew Adams
  2012-10-01  6:41 ` Dani Moncayo
  0 siblings, 1 reply; 31+ messages in thread
From: Drew Adams @ 2012-09-30 21:09 UTC (permalink / raw)
  To: emacs-devel

I sometimes isearch for a term but ultimately decide not to go to any of its
locations, at least not for the moment.  That is, I hit `C-g' after navigating
around a bit to check things out.

In some cases, the search string for this might have required a bit of typing.
Or maybe it came from multiple `C-w's at search startup, and maybe I later moved
away from that start location, so it would be cumbersome to try to get back that
search string again, for another search.

I guess for a long time I've sub-thought, without considering it consciously,
that it might be good to get back that last successful search string -- the one
I was searching with when I hit `C-g' to quit searching -- for reuse later.  But
it's not saved on the search rings (which makes sense), so it is not available.
`C-g' means bye-bye.

In Isearch+, I added a key (`M-g') to retrieve on demand that last successful
search string (for `C-s') or regexp (for `C-M-s') that was current at the time I
canceled with `C-g'.  To me, it seems handy.

Retrieval is a yank, not a replacement of your current search string.  So you
can append the retrieved string to whatever you are already looking for (or you
can search for just the retrieved string/regexp).

If this sounds like something with wider appeal, let me know - the patch to
isearch.el would be trivial.  You can try it quickly by loading isearch+.el.
http://www.emacswiki.org/emacs-en/download/isearch%2b.el




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-09-30 21:09 Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
@ 2012-10-01  6:41 ` Dani Moncayo
  2012-10-01 14:57   ` Stefan Monnier
  2012-10-01 15:17   ` Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
  0 siblings, 2 replies; 31+ messages in thread
From: Dani Moncayo @ 2012-10-01  6:41 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

> I guess for a long time I've sub-thought, without considering it consciously,
> that it might be good to get back that last successful search string -- the one
> I was searching with when I hit `C-g' to quit searching -- for reuse later.  But
> it's not saved on the search rings (which makes sense), so it is not available.
> `C-g' means bye-bye.

As you say, someone might want that last successful search string to
be stored in the search ring (I've sometimes expected it).

So I think that the proper solution would be to let the user decide
whether C-g from a I-search session saves the current search string in
the search ring.

That, IMO, would be a better (more intuitive/consistent) solution that
taking another key for retrieving the last successful search string
(which is already doable with "C-s C-s" or "C-s M-p").

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01  6:41 ` Dani Moncayo
@ 2012-10-01 14:57   ` Stefan Monnier
  2012-10-01 15:05     ` Christopher Monsanto
  2012-10-01 15:18     ` Drew Adams
  2012-10-01 15:17   ` Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
  1 sibling, 2 replies; 31+ messages in thread
From: Stefan Monnier @ 2012-10-01 14:57 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: Drew Adams, emacs-devel

> As you say, someone might want that last successful search string to
> be stored in the search ring (I've sometimes expected it).

Yes, I actually prefer to have it in the history (and skip it when
I don't want it) than to fail to find it.


        Stefan



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 14:57   ` Stefan Monnier
@ 2012-10-01 15:05     ` Christopher Monsanto
  2012-10-01 15:11       ` Dani Moncayo
  2012-10-01 15:21       ` Drew Adams
  2012-10-01 15:18     ` Drew Adams
  1 sibling, 2 replies; 31+ messages in thread
From: Christopher Monsanto @ 2012-10-01 15:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel, Drew Adams, Dani Moncayo

To be honest, I always thought there was some bug in isearch that made
it forget my search strings. I'd love it if isearch just
unconditionally remembered my searches.

Christopher Monsanto
chris@monsan.to  --  http://monsan.to/



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:05     ` Christopher Monsanto
@ 2012-10-01 15:11       ` Dani Moncayo
  2012-10-01 15:22         ` Drew Adams
  2012-10-01 15:21       ` Drew Adams
  1 sibling, 1 reply; 31+ messages in thread
From: Dani Moncayo @ 2012-10-01 15:11 UTC (permalink / raw)
  To: Christopher Monsanto; +Cc: Stefan Monnier, Drew Adams, emacs-devel

> To be honest, I always thought there was some bug in isearch that made
> it forget my search strings. I'd love it if isearch just
> unconditionally remembered my searches.

Some users may prefer the current behavior, i.e., that `C-g' just
exits i-search without storing the current search string in the search
ring.

So, I think this behavior should be user-configurable.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01  6:41 ` Dani Moncayo
  2012-10-01 14:57   ` Stefan Monnier
@ 2012-10-01 15:17   ` Drew Adams
  2012-10-02 11:29     ` Nix
  1 sibling, 1 reply; 31+ messages in thread
From: Drew Adams @ 2012-10-01 15:17 UTC (permalink / raw)
  To: 'Dani Moncayo'; +Cc: emacs-devel

> > I guess for a long time I've sub-thought, without 
> > considering it consciously, that it might be good to get
> > back that last successful search string -- the one
> > I was searching with when I hit `C-g' to quit searching -- 
> > for reuse later.  But it's not saved on the search rings
> > (which makes sense), so it is not available.
> > `C-g' means bye-bye.
> 
> As you say, someone might want that last successful search string to
> be stored in the search ring (I've sometimes expected it).

No, I did not say that.  In fact, I said that it makes sense that it NOT be
added to the search rings.

I said that it would sometimes be useful to retrieve that string for a later
search.  That's not the same thing as treating it the same as the strings on the
rings.

> So I think that the proper solution would be to let the user decide
> whether C-g from a I-search session saves the current search string in
> the search ring.

1. If you mean systematically, e.g. via a user option, then that is a bad idea,
IMO.  I, for one, do not want abandoned searches polluting my search rings.

But I do want to be able to get back the _last_ abandoned search string on
demand, for reuse.  What Isearch+ does is save only the last abandoned search
strings (separately for simple search and regexp search).  It specifically does
not add those to the search rings.

2. If you instead meant that a user would signal this intention when hitting C-g
(prefix arg or some such), then that would be pretty useless, IMHO.  At the time
you hit C-g you typically do not know whether you might later want to reuse that
search string.  And again, it should not be saved to the search rings.

> That, IMO, would be a better (more intuitive/consistent) solution that
> taking another key for retrieving the last successful search string
> (which is already doable with "C-s C-s" or "C-s M-p").

This is not about the last search where you moved to a search hit and stayed
there.  That is what is recorded in the search rings and so is available via C-s
C-s.  Those are not only successful searches in terms of finding hits; they are
also searches that you have accepted, i.e., used to move to a hit and stay
there.

That meaning for the search rings should be kept, IMO.  It is what you want 99%
of the time.  You do not want to wade through a myriad of successful but
unused/unaccepted searches on the ring, to find and reuse a search that you
actually followed.

This is about retrieving the last successful search string where you canceled
searching using C-g, and so did not stay at any of its hits.  It's about letting
you insert that string later, adding (appending) it to the current search
string.

It is very simple.  Just hit `M-g' to yank the string into the current search.

This is a one-off, occasional thing - nowhere near as frequent as reusing a
search that you actually followed.  Just imagine saving your search rings
persistently (e.g. via savehist.el), to see the folly of saving each successful
but abandoned search string.





^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 14:57   ` Stefan Monnier
  2012-10-01 15:05     ` Christopher Monsanto
@ 2012-10-01 15:18     ` Drew Adams
  2012-10-02  3:22       ` Stephen J. Turnbull
  1 sibling, 1 reply; 31+ messages in thread
From: Drew Adams @ 2012-10-01 15:18 UTC (permalink / raw)
  To: 'Stefan Monnier', 'Dani Moncayo'; +Cc: emacs-devel

> > As you say, someone might want that last successful search string to
> > be stored in the search ring (I've sometimes expected it).
> 
> Yes, I actually prefer to have it in the history (and skip it when
> I don't want it)

Folly.  See my reply to Dani.

> than to fail to find it.

Today, you do fail to find it.  It is completely lost.

But I cannot imagine that you really want to be able to find _all_ such
unvisited search strings on your search rings.

To me, being able to retrieve just the last such string is adequate - TRT.  I've
used this feature (what I proposed).  I suggest you try it, and you try also
your suggestion of systematically adding all successful searches to the rings,
and then compare.

If you do decide to do what you are proposing, please provide us users a way out
- a way to keep the sane search histories of today, without their pollution by
umpteen zillion abandoned searches.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:05     ` Christopher Monsanto
  2012-10-01 15:11       ` Dani Moncayo
@ 2012-10-01 15:21       ` Drew Adams
  2012-10-01 15:30         ` Christopher Monsanto
  2012-10-05 22:58         ` Andrew W. Nosenko
  1 sibling, 2 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 15:21 UTC (permalink / raw)
  To: 'Christopher Monsanto', 'Stefan Monnier'
  Cc: emacs-devel, 'Dani Moncayo'

> To be honest, I always thought there was some bug in isearch that made
> it forget my search strings.  I'd love it if isearch just
> unconditionally remembered my searches.

It is not a bug; it is by design.  And a good design it is.

AFAIK, no one has ever filed a bug report complaining that abandoned searches
are not saved in the histories.

I doubt if you would really love it, in practice.  But it is simple for you to
try it, to see.

As an analogy, think of moving to a search hit and staying there as "entering"
the search string into an input history, much as when you hit RET to choose a
completion during minibuffer input with completion.  Would you want your input
history to also remember the minibuffer content that was current each time you
hit TAB?  I don't think so.

When you "accept" a search hit, moving there and ending Isearch, it shows that
the search string was useful to you.  It should be added to the search history.

When you abandon searching, regardless of whether you might have looked at some
search hits, it indicates that you did not want to move to any of them and stay
there.  That search was not useful to you - at least not in terms of changing
your location.  That search string should not be added to the history, IMO.  The
history is (and should remain, IMO) a history of used searches.

But for the last such successful-but-unused search string, yes, there should
perhaps be a way to get it back.  That is what I proposed, not systematically
adding unused searches to the history.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:11       ` Dani Moncayo
@ 2012-10-01 15:22         ` Drew Adams
  0 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 15:22 UTC (permalink / raw)
  To: 'Dani Moncayo', 'Christopher Monsanto'
  Cc: 'Stefan Monnier', emacs-devel

> > To be honest, I always thought there was some bug in 
> > isearch that made it forget my search strings. I'd love it
> > if isearch just unconditionally remembered my searches.
> 
> Some users may prefer the current behavior, i.e., that `C-g' just
> exits i-search without storing the current search string in the search
> ring.  So, I think this behavior should be user-configurable.

It is misguided.  But as with all misguided features, users should have a way to
opt out (or in).

Why don't you simply try what I suggested?  It takes only a few seconds to do
(just load isearch+.el).  And you can easily try your approach as well.  Try
both approaches for a few hours, and then compare.

I think you will find that it makes little sense to systematically add all
abandoned searches to the search rings, but it does make sense to be able to
retrieve the last such.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:21       ` Drew Adams
@ 2012-10-01 15:30         ` Christopher Monsanto
  2012-10-01 15:40           ` Drew Adams
  2012-10-01 15:41           ` Dani Moncayo
  2012-10-05 22:58         ` Andrew W. Nosenko
  1 sibling, 2 replies; 31+ messages in thread
From: Christopher Monsanto @ 2012-10-01 15:30 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, Stefan Monnier, Dani Moncayo

On Mon, Oct 1, 2012 at 11:21 AM, Drew Adams <drew.adams@oracle.com> wrote:
>> To be honest, I always thought there was some bug in isearch that made
>> it forget my search strings.  I'd love it if isearch just
>> unconditionally remembered my searches.
>
> It is not a bug; it is by design.  And a good design it is.
> AFAIK, no one has ever filed a bug report complaining that abandoned searches
> are not saved in the histories.

I rarely use isearch to find things that I don't already know exist. I
use occur or grep for that and use next-error/prev-error to navigate.
When I hit C-g, it means "I don't want to operate at the search
position, I was just looking for something and now I'm ready to go
back to where I was." Basically, a shortcut for accept the search and
pop mark.

> I doubt if you would really love it, in practice.  But it is simple for you to
> try it, to see. ...
> But for the last such successful-but-unused search string, yes, there should
> perhaps be a way to get it back.  That is what I proposed, not systematically
> adding unused searches to the history.

That's your speculation :) I'm just putting my two cents in for what
works best for my (perhaps eccentric, but that's none of your
business!) workflow. Since there is a difference in opinion, a user
configurable flag is what I would advocate for.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:30         ` Christopher Monsanto
@ 2012-10-01 15:40           ` Drew Adams
  2012-10-01 15:41           ` Dani Moncayo
  1 sibling, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 15:40 UTC (permalink / raw)
  To: 'Christopher Monsanto'
  Cc: emacs-devel, 'Stefan Monnier', 'Dani Moncayo'

> When I hit C-g, it means "I don't want to operate at the search
> position, I was just looking for something and now I'm ready to go
> back to where I was."

Precisely.  "I was just looking for something" and I didn't really want to move
there - just now at least.

And you perhaps have no idea at that time whether you might want to repeat that
looking later, or even perhaps move to one of the search hits.

The question (between the two proposals) is whether to record all such abandoned
searches or just the last one.

More precisely (because we could, if we wanted, create additional search rings
for this), it is whether to record such abandoned searches in the regular search
rings or separately.  Should they be mixed in with the accepted/used searches?

> > I doubt if you would really love it, in practice.  But it 
> > is simple for you to try it, to see. ...
> 
> That's your speculation :) I'm just putting my two cents in for what
> works best for my (perhaps eccentric, but that's none of your
> business!) workflow.  Since there is a difference in opinion, a user
> configurable flag is what I would advocate for.

Why don't you try it?  Try both.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:30         ` Christopher Monsanto
  2012-10-01 15:40           ` Drew Adams
@ 2012-10-01 15:41           ` Dani Moncayo
  2012-10-01 16:00             ` Drew Adams
  2012-10-02 11:26             ` Nix
  1 sibling, 2 replies; 31+ messages in thread
From: Dani Moncayo @ 2012-10-01 15:41 UTC (permalink / raw)
  To: Christopher Monsanto; +Cc: Stefan Monnier, Drew Adams, emacs-devel

> Since there is a difference in opinion, a user
> configurable flag is what I would advocate for.

Another approach: keep `C-g' as it is now (just cancel the current
command) and choose another key for exiting i-search saving the
current search string...

I don't feel strongly about this, but the more I think about it, the
less I like the idea of altering the usual meaning of `C-g' (so I
think I'm with Drew here).

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:41           ` Dani Moncayo
@ 2012-10-01 16:00             ` Drew Adams
  2012-10-01 17:49               ` Juri Linkov
  2012-10-01 18:31               ` Dani Moncayo
  2012-10-02 11:26             ` Nix
  1 sibling, 2 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 16:00 UTC (permalink / raw)
  To: 'Dani Moncayo', 'Christopher Monsanto'
  Cc: 'Stefan Monnier', emacs-devel

> Another approach: keep `C-g' as it is now (just cancel the current
> command) and choose another key for exiting i-search saving the
> current search string...

To repeat: At the time that you abandon searching, you do not necessarily _know_
whether you might later want to come back and reuse that search string:

d> 2. If you instead meant that a user would signal this intention
d>    when hitting C-g (prefix arg or some such), then that would be
d>    pretty useless,  IMHO.  At the time you hit C-g you typically
d>    do not know whether you might later want to reuse that search
d>    string.  And again, it should not be saved to the search rings.

> I don't feel strongly about this, but the more I think about it, the
> less I like the idea of altering the usual meaning of `C-g' (so I
> think I'm with Drew here).

Again, I suggest that people take a moment and actually try out both approaches.

For what I proposed, you need only load isearch+.el and then use `M-g' whenever
you want to retrieve the last such search.
http://www.emacswiki.org/emacs-en/download/isearch%2b.el

For what others have proposed, just alter the definition of `isearch-abort' in
isearch.el, like this (untested):

(defun isearch-abort ()
  "Abort incremental search mode if searching is successful, signaling quit.
Otherwise, revert to previous successful search and continue searching.
Use `isearch-exit' to quit without signaling."
  (interactive)
  (discard-input)
  (if (and isearch-success (not isearch-error))
      (progn
        (setq isearch-success nil)

        ;; ADD THIS LINE <===============
        (isearch-update-ring isearch-string isearch-regexp)

        (isearch-cancel))
    (while (or (not isearch-success) isearch-error)
      (isearch-pop-state))
    (isearch-update)))

With the latter approach, you can get back any successful but abandoned search
in the usual way: repeated `C-(M-)s' or `M-p'.  With the former approach (my
proposal), you can get back only the last one, using `M-g'.

With the former approach, `M-p' passes through all such abandoned searches.
With my proposal, `M-p' does not see any such abandoned searches.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 16:00             ` Drew Adams
@ 2012-10-01 17:49               ` Juri Linkov
  2012-10-01 18:21                 ` Drew Adams
  2012-10-01 18:31               ` Dani Moncayo
  1 sibling, 1 reply; 31+ messages in thread
From: Juri Linkov @ 2012-10-01 17:49 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, 'Stefan Monnier', 'Dani Moncayo'

> For what others have proposed, just alter the definition of `isearch-abort' in
> isearch.el, like this (untested):
>
> (defun isearch-abort ()
>   "Abort incremental search mode if searching is successful, signaling quit.
> Otherwise, revert to previous successful search and continue searching.
> Use `isearch-exit' to quit without signaling."
>   (interactive)
>   (discard-input)
>   (if (and isearch-success (not isearch-error))
>       (progn
>         (setq isearch-success nil)
>
>         ;; ADD THIS LINE <===============
>         (isearch-update-ring isearch-string isearch-regexp)

If someone will be willing to implement this, then better would be to
add a new arg to `isearch-cancel' propagating its value to the arg
NOPUSH of `isearch-done'.  And also add a new arg to `isearch-abort',
and maybe even make it a prefix arg C-u, e.g. `C-g' saves the search
string to the search ring, but `C-u C-g' doesn't.

But really I see no need to do this.  You can do the same by exiting
normally with RET and jumping back to the mark with `C-u C-SPC'
to return to where you were before beginning the search.

If you want to put the search string to the kill ring
(instead of the search ring) before canceling Isearch,
then you can do `M-e C-k C-g C-g'.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 17:49               ` Juri Linkov
@ 2012-10-01 18:21                 ` Drew Adams
  0 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 18:21 UTC (permalink / raw)
  To: 'Juri Linkov'
  Cc: emacs-devel, 'Stefan Monnier', 'Dani Moncayo'

> > For what others have proposed, just alter the definition of 
> > `isearch-abort' in isearch.el, like this (untested):
> >
> >         ;; ADD THIS LINE <===============
> >         (isearch-update-ring isearch-string isearch-regexp)
> 
> If someone will be willing to implement this,

Not I.  I am not in favor of that approach.  If it is implemented then I, for
one, will opt out of it.

> then better would be to
> add a new arg to `isearch-cancel' propagating its value to the arg
> NOPUSH of `isearch-done'.

> And also add a new arg to `isearch-abort',
> and maybe even make it a prefix arg C-u, e.g. `C-g' saves the search
> string to the search ring, but `C-u C-g' doesn't.

Ugh.  Again, at the time you cancel using C-g, you probably do not know whether
you might later want to reuse that search string.  This approach makes no sense
to me.

> But really I see no need to do this.  You can do the same by exiting
> normally with RET and jumping back to the mark with `C-u C-SPC'
> to return to where you were before beginning the search.

I almost mentioned that as well.  But again, that presumes that you have a good
idea at that time whether you might want to reuse the search string.  Not a good
assumption.

My suggestion was not about putting the search string on the history, and it was
not about reusing the search string only as a _replacement_ search.  It was
about reusing such a search string by yanking it into the current search, even
if that is not empty.

You can yank it into the search string any number of times (repetitions).  And
it does not pollute your search rings, which continue to contain only searches
you have used (followed to some hit and stayed there).  It is handled pretty
much the same way yanking a kill into the search string is handled.

> If you want to put the search string to the kill ring
> (instead of the search ring) before canceling Isearch,
> then you can do `M-e C-k C-g C-g'.

See above.  You typically do not know whether you want to reuse the current
search string at the time you quit with C-g.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 16:00             ` Drew Adams
  2012-10-01 17:49               ` Juri Linkov
@ 2012-10-01 18:31               ` Dani Moncayo
  2012-10-01 18:47                 ` Drew Adams
  1 sibling, 1 reply; 31+ messages in thread
From: Dani Moncayo @ 2012-10-01 18:31 UTC (permalink / raw)
  To: Drew Adams; +Cc: Stefan Monnier, emacs-devel

Hi Drew,

I've tested your proposal (I don't need to test the other one, since
the behavior is pretty obvious).

I see two problems in your proposal:
1. It adds a bit of (unnecesary) user-level complexity: the users has
to remember whether the search string was accepted (i.e. pushed to the
search ring) or not, since the way of retrieving it is different in
each case.
2. The user can't  The search string is lost if is not accepted and is
not the last one.

The following approach overcomes these two problems:

Define a new user-option whereby the user can choose between these 3 behaviors:
a. Don't remember any cancelled search strings: i.e., the current behavior.
b. Remember only the last cancelled search string: if the users
cancels an i-search with `C-g', that search string will be retrieved
by `C-s C-s' or `C-s M-p' as if it was stored at the top of the search
ring; but this string will be forgot/removed after the next i-search
session.
b. Remember all cancelled search string: any cancelled search string
will be pushed to the search ring, like the accepted ones.

I think this approach is simple and flexible.  I would adapt to the
different usage patterns that people have expressed so far in this
thread.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 18:31               ` Dani Moncayo
@ 2012-10-01 18:47                 ` Drew Adams
  2012-10-01 18:50                   ` Christopher Monsanto
                                     ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 18:47 UTC (permalink / raw)
  To: 'Dani Moncayo'; +Cc: 'Stefan Monnier', emacs-devel

> I've tested your proposal (I don't need to test the other one, since
> the behavior is pretty obvious).

Good.  Thanks for trying it out.

> I see two problems in your proposal:
> 1. It adds a bit of (unnecesary) user-level complexity: the users has
> to remember whether the search string was accepted (i.e. pushed to the
> search ring) or not, since the way of retrieving it is different in
> each case.
> 2. The user can't  The search string is lost if is not accepted and is
> not the last one.

Agreed.  To me, neither of those is a problem in practice.
But it is well to point them out.

As I said, if the second is really a problem then we could add separate search
rings for such strings.  Having used the feature a bit, I don't really think
that's necessary.  I use `M-g' to retrieve such a string only occasionally, and
the last such string is the one I want, in practice.  YMMV.

> The following approach overcomes these two problems:
> 
> Define a new user-option whereby the user can choose between 
> these 3 behaviors:
> a. Don't remember any cancelled search strings: i.e., the 
> current behavior.
> b. Remember only the last cancelled search string: if the users
> cancels an i-search with `C-g', that search string will be retrieved
> by `C-s C-s' or `C-s M-p' as if it was stored at the top of the search
> ring; but this string will be forgot/removed after the next i-search
> session.
> b. Remember all cancelled search string: any cancelled search string
> will be pushed to the search ring, like the accepted ones.
> 
> I think this approach is simple and flexible.  I would adapt to the
> different usage patterns that people have expressed so far in this
> thread.

None of those 3 does what I proposed and what you tried: be able to _yank_ that
search string anywhere you like into the current search string, as many times as
you like.

Think of what `C-y' does during search - this is similar to that.  (But you can
follow `C-y' with `M-y' to cycle through the kill ring.  My proposal does not
save/retrieve more than the most recent such search string, as you pointed out.)

Anyway, I've explained this enough.  For anyone who wants it there is Isearch+.
Whatever Emacs Dev ends up doing for isearch.el, I hope that at least users will
be able to get the current, traditional behavior back.  And I would hope that
any optional alternative behavior be opt-in rather than opt-out.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 18:47                 ` Drew Adams
@ 2012-10-01 18:50                   ` Christopher Monsanto
  2012-10-01 18:54                   ` Lennart Borgman
  2012-10-01 19:12                   ` Dani Moncayo
  2 siblings, 0 replies; 31+ messages in thread
From: Christopher Monsanto @ 2012-10-01 18:50 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, Stefan Monnier, Dani Moncayo

The only reason I spoke up was to concur with Stefan:

> Yes, I actually prefer to have it in the history (and skip it when
> I don't want it) than to fail to find it.

This isn't at all a big deal to me; I'm just happy to know what was
causing my searches to be lost. The default behavior should not be
changed. I would be happy to see an option for other behavior, but as
long as there are enough hooks in the system to change this behavior,
I'm happy to do so in my .emacs.

Christopher Monsanto
chris@monsan.to  --  http://monsan.to/



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 18:47                 ` Drew Adams
  2012-10-01 18:50                   ` Christopher Monsanto
@ 2012-10-01 18:54                   ` Lennart Borgman
  2012-10-01 20:00                     ` Drew Adams
  2012-10-01 19:12                   ` Dani Moncayo
  2 siblings, 1 reply; 31+ messages in thread
From: Lennart Borgman @ 2012-10-01 18:54 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, Stefan Monnier, Dani Moncayo

On Mon, Oct 1, 2012 at 8:47 PM, Drew Adams <drew.adams@oracle.com> wrote:
>
> > I've tested your proposal (I don't need to test the other one, since
> > the behavior is pretty obvious).
>
> Good.  Thanks for trying it out.
>
> > I see two problems in your proposal:
> > 1. It adds a bit of (unnecesary) user-level complexity: the users has
> > to remember whether the search string was accepted (i.e. pushed to the
> > search ring) or not, since the way of retrieving it is different in
> > each case.
> > 2. The user can't  The search string is lost if is not accepted and is
> > not the last one.

Would it be possible to add the search string aborted with C-g to the
other end of the search string history? (It is cyclic, isn't it?)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 18:47                 ` Drew Adams
  2012-10-01 18:50                   ` Christopher Monsanto
  2012-10-01 18:54                   ` Lennart Borgman
@ 2012-10-01 19:12                   ` Dani Moncayo
  2 siblings, 0 replies; 31+ messages in thread
From: Dani Moncayo @ 2012-10-01 19:12 UTC (permalink / raw)
  To: Drew Adams; +Cc: Stefan Monnier, emacs-devel

>> The following approach overcomes these two problems:
>>
>> Define a new user-option whereby the user can choose between
>> these 3 behaviors:
>> a. Don't remember any cancelled search strings: i.e., the
>> current behavior.
>> b. Remember only the last cancelled search string: if the users
>> cancels an i-search with `C-g', that search string will be retrieved
>> by `C-s C-s' or `C-s M-p' as if it was stored at the top of the search
>> ring; but this string will be forgot/removed after the next i-search
>> session.
>> b. Remember all cancelled search string: any cancelled search string
>> will be pushed to the search ring, like the accepted ones.
>>
>> I think this approach is simple and flexible.  I would adapt to the
>> different usage patterns that people have expressed so far in this
>> thread.
>
> None of those 3 does what I proposed and what you tried: be able to _yank_ that
> search string anywhere you like into the current search string, as many times as
> you like.

Mmmm... I think this problem is pretty insignificant, since:
* Usually you will not want to do that (yank the search string
multiple times or in other places than the minibuffer).
* If you want to do that, you always can do `C-s M-p C-a C-k' and yank
it anywhere.

Therefore, IMO the advantages of my proposal (simplicity/flexibility)
outweigh this problem, but YMMV.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 18:54                   ` Lennart Borgman
@ 2012-10-01 20:00                     ` Drew Adams
  0 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-01 20:00 UTC (permalink / raw)
  To: 'Lennart Borgman'
  Cc: emacs-devel, 'Stefan Monnier', 'Dani Moncayo'

> Would it be possible to add the search string aborted with C-g to the
> other end of the search string history? (It is cyclic, isn't it?)

No, it is not.  That is why you see these messages:

"Beginning of history; no preceding item"
"End of history; no default available"

Otherwise, yes, that would be a reasonable suggestion.

(But it still would not let you yank the string into an existing search string
one or more times.)




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:18     ` Drew Adams
@ 2012-10-02  3:22       ` Stephen J. Turnbull
  2012-10-02 12:37         ` Richard Stallman
  0 siblings, 1 reply; 31+ messages in thread
From: Stephen J. Turnbull @ 2012-10-02  3:22 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, 'Stefan Monnier', 'Dani Moncayo'

Drew Adams writes:

 > But I cannot imagine that you really want to be able to find _all_
 > such unvisited search strings on your search rings.

I can.  XEmacs 21.5 does precisely that (since February 2004).  Nobody
has ever complained about "pollution".  Not even once.

That's a statistically small sample, it's true, but clearly, it's not
unimaginable by at least some reasonable people.

In the XEmacs implementation, C-s ... RET C-x C-x and a successful C-s
... C-g are different.  Although both push the successful search
string on the ring, only the first pushes a mark.

Your approach might be better, but ... you already have it, so it's no
skin off your nose if Emacs experiments with the alternative.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:41           ` Dani Moncayo
  2012-10-01 16:00             ` Drew Adams
@ 2012-10-02 11:26             ` Nix
  2012-10-02 13:55               ` Drew Adams
  2012-10-02 16:48               ` Eli Zaretskii
  1 sibling, 2 replies; 31+ messages in thread
From: Nix @ 2012-10-02 11:26 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: Stefan Monnier, Drew Adams, emacs-devel

On 1 Oct 2012, Dani Moncayo stated:

>> Since there is a difference in opinion, a user
>> configurable flag is what I would advocate for.
>
> Another approach: keep `C-g' as it is now (just cancel the current
> command) and choose another key for exiting i-search saving the
> current search string...

Quite. Perhaps I'm just an idiot, but I always thought the current
isearch behaviour of not immediately quitting when C-g was stuck on a
failed search was a *bug*. Only now, after Drew commented on it, do I
notice that it's removing the unfound component of the failed search:
i.e., it's a feature, but unless you spend your time looking at the echo
area while isearching (and who does that?) they'll never notice it.

I don't know the right way to fix this. The operation is clearly useful;
C-g is clearly a meaningful keybinding for it, and lots of keys work
differently form the norm in isearch, so why not keyboard-escape-quit
too; it is clearly documented... but I never realised it was there and
thought C-g instantly quit anything unless Emacs was busy at the C
layer. So perhaps there is no problem here and I should just chalk this
up to being a doofus and needing to spend some time learning what
features have been added to isearch in the last fifteen years. Maybe
everyone else expects C-g to work the way it does in isearch.

But perhaps something other than C-g is the right binding, and C-g
really *should* quit, dammit.

-- 
NULL && (void)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:17   ` Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
@ 2012-10-02 11:29     ` Nix
  2012-10-02 14:03       ` Drew Adams
  0 siblings, 1 reply; 31+ messages in thread
From: Nix @ 2012-10-02 11:29 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel, 'Dani Moncayo'

On 1 Oct 2012, Drew Adams told this:
> This is a one-off, occasional thing - nowhere near as frequent as reusing a
> search that you actually followed.  Just imagine saving your search rings
> persistently (e.g. via savehist.el), to see the folly of saving each successful
> but abandoned search string.

If you're trying to avoid having unsuccessful searches crowd successful
ones out of he history, the right solution is presumably to have two
rings, one for successful searches, one for unsuccessful ones, and have
the default 'back in search' option merge the two rings at runtime.
(This is easily implementable by making each entry in each ring a pair
of (counter . value), incrementing the counter on each ring insertion,
and taking from whichever ring has the lowest counter value for the next
item on each ring pop.)

This has the benefit that it is easy to have two keybindings to navigate
each ring independently, if you so desire.

-- 
NULL && (void)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-02  3:22       ` Stephen J. Turnbull
@ 2012-10-02 12:37         ` Richard Stallman
  2012-10-02 14:05           ` Isearch: retrieve last successful search string from when youquit (`C-g') Drew Adams
  0 siblings, 1 reply; 31+ messages in thread
From: Richard Stallman @ 2012-10-02 12:37 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: dmoncayo, monnier, drew.adams, emacs-devel

We could poll the users to see what they would prefer.
A good way would be to implement this behavior as an option,
release that, then ask users to try the option and say
what they think of it.

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-02 11:26             ` Nix
@ 2012-10-02 13:55               ` Drew Adams
  2012-10-02 16:48               ` Eli Zaretskii
  1 sibling, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-02 13:55 UTC (permalink / raw)
  To: 'Nix', 'Dani Moncayo'
  Cc: 'Stefan Monnier', emacs-devel

> Quite. Perhaps I'm just an idiot, but I always thought the current
> isearch behaviour of not immediately quitting when C-g was stuck on a
> failed search was a *bug*. 

That is something very different from what this thread is about (and not a bug,
IMO).  The C-g behavior in Emacs incremental search is somewhat complex (depends
on the search state), and fine as is (IMO).

> Only now, after Drew commented on it, do I
> notice that it's removing the unfound component of the failed
> search: i.e., it's a feature, but unless you spend your time
> looking at the echo area while isearching (and who does that?)
> they'll never notice it.

And that too is something very different from what this thread is about.

This thread is about a proposal to save (it is not currently saved) the last
_successful_ search string when you exit isearch using C-g.  It is not about
saving the search string for a _failed_ search.

A successful search is one where the search string is found - matches text in
the buffer.  Just because a search is successful does not mean that you decide
to accept it, i.e., to stay at one of the search hits.

C-g abandons a successful search, and it keeps no record of the search string
that was successful.

The question of this thread is whether to save (one way or another) the search
string when searching succeeded and make it available to you later, and if so,
how.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-02 11:29     ` Nix
@ 2012-10-02 14:03       ` Drew Adams
  0 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-02 14:03 UTC (permalink / raw)
  To: 'Nix'; +Cc: emacs-devel, 'Dani Moncayo'

> If you're trying to avoid having unsuccessful searches

See previous reply.  It's about successful searches that you abandon with C-g.
It's not about unsuccessful searches.

> crowd successful ones out of he history, the right solution
> is presumably to have two rings, one for successful searches,
> one for unsuccessful ones,

With the correction of "unsuccessful" to successful but abandoned, yes, that is
one of the possibilities that was discussed.

Discussed so far are these possibilities (there may have been others too):

1. Save (only) the last such search.
   Make it yankable using M-g.  This was my proposal.

2. Save all such searches.  Put them all new search rings
   (simple, regexp).  I mentioned this as another possibility.

3. Save all such searches.  Put them all on the usual search
   (simple, regexp) rings.  This was a counter proposal.

> This has the benefit that it is easy to have two keybindings 
> to navigate each ring independently, if you so desire.

Agreed.  Apart from your "merging", this is #2 above.  The main advantage, from
my point of view, is that it leaves the traditional rings unpolluted by
abandoned searches.  #2 is an extension of #1: it saves all abandoned
(successful) searches, not just the last one.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: Isearch: retrieve last successful search string from when youquit (`C-g')
  2012-10-02 12:37         ` Richard Stallman
@ 2012-10-02 14:05           ` Drew Adams
  0 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2012-10-02 14:05 UTC (permalink / raw)
  To: rms, 'Stephen J. Turnbull'; +Cc: dmoncayo, monnier, emacs-devel

> We could poll the users to see what they would prefer.
> A good way would be to implement this behavior as an option,
> release that, then ask users to try the option and say
> what they think of it.

+1.  But it's not clear there is much consensus yet on what the optional
behavior should be.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-02 11:26             ` Nix
  2012-10-02 13:55               ` Drew Adams
@ 2012-10-02 16:48               ` Eli Zaretskii
  2012-10-04 11:37                 ` Nix
  1 sibling, 1 reply; 31+ messages in thread
From: Eli Zaretskii @ 2012-10-02 16:48 UTC (permalink / raw)
  To: Nix; +Cc: emacs-devel, monnier, drew.adams, dmoncayo

> From: Nix <nix@esperi.org.uk>
> Emacs: (setq software-quality (/ 1 number-of-authors))
> Date: Tue, 02 Oct 2012 12:26:21 +0100
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
> 	Drew Adams <drew.adams@oracle.com>, emacs-devel@gnu.org
> 
> Perhaps I'm just an idiot, but I always thought the current
> isearch behaviour of not immediately quitting when C-g was stuck on a
> failed search was a *bug*. Only now, after Drew commented on it, do I
> notice that it's removing the unfound component of the failed search:
> i.e., it's a feature, but unless you spend your time looking at the echo
> area while isearching (and who does that?) they'll never notice it.

They could read the manual.

  15.1.3 Errors in Incremental Search
  -----------------------------------

  If your string is not found at all, the echo area says `Failing
  I-Search', and the cursor moves past the place where Emacs found as
  much of your string as it could.  Thus, if you search for `FOOT', and
  there is no `FOOT', you might see the cursor after the `FOO' in `FOOL'.
  In the echo area, the part of the search string that failed to match is
  highlighted using the face `isearch-fail'.

     At this point, there are several things you can do.  If your string
  was mistyped, you can use <DEL> to erase some of it and correct it.  If
  you like the place you have found, you can type <RET> to remain there.
  Or you can type `C-g', which removes from the search string the
  characters that could not be found (the `T' in `FOOT'), leaving those
  that were found (the `FOO' in `FOOT').  A second `C-g' at that point
  cancels the search entirely, returning point to where it was when the
  search started.

     The quit command, `C-g', does special things during searches; just
  what it does depends on the status of the search.  If the search has
  found what you specified and is waiting for input, `C-g' cancels the
  entire search, moving the cursor back to where you started the search.
  If `C-g' is typed when there are characters in the search string that
  have not been found--because Emacs is still searching for them, or
  because it has failed to find them--then the search string characters
  which have not been found are discarded from the search string.  With
  them gone, the search is now successful and waiting for more input, so
  a second `C-g' will cancel the entire search.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-02 16:48               ` Eli Zaretskii
@ 2012-10-04 11:37                 ` Nix
  0 siblings, 0 replies; 31+ messages in thread
From: Nix @ 2012-10-04 11:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel, monnier, drew.adams, dmoncayo

On 2 Oct 2012, Eli Zaretskii verbalised:

>> From: Nix <nix@esperi.org.uk>
>> Emacs: (setq software-quality (/ 1 number-of-authors))
>> Date: Tue, 02 Oct 2012 12:26:21 +0100
>> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
>> 	Drew Adams <drew.adams@oracle.com>, emacs-devel@gnu.org
>> 
>> Perhaps I'm just an idiot, but I always thought the current
>> isearch behaviour of not immediately quitting when C-g was stuck on a
>> failed search was a *bug*. Only now, after Drew commented on it, do I
>> notice that it's removing the unfound component of the failed search:
>> i.e., it's a feature, but unless you spend your time looking at the echo
>> area while isearching (and who does that?) they'll never notice it.
>
> They could read the manual.

Yeah. I did say that it was documented. That's not the problem. The
problem is that changing the behaviour of C-g to not quit is surprising.
(Nothing else does it, modulo short-term setting of inhibit-quit, and
there is no obvious reason why searching should be different.)

But, as Drew and others have pointed out, this behaviour is easy to
customize -- once you become aware that it's not a simple bug.

-- 
NULL && (void)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Isearch: retrieve last successful search string from when you quit (`C-g')
  2012-10-01 15:21       ` Drew Adams
  2012-10-01 15:30         ` Christopher Monsanto
@ 2012-10-05 22:58         ` Andrew W. Nosenko
  1 sibling, 0 replies; 31+ messages in thread
From: Andrew W. Nosenko @ 2012-10-05 22:58 UTC (permalink / raw)
  To: Drew Adams; +Cc: Stefan Monnier, Dani Moncayo, emacs-devel

On Mon, Oct 1, 2012 at 6:21 PM, Drew Adams <drew.adams@oracle.com> wrote:
> But for the last such successful-but-unused search string, yes, there should
> perhaps be a way to get it back.  That is what I proposed, not systematically
> adding unused searches to the history.
>

From keyboard: Right, Left, C-x C-x?

-- 
Andrew W. Nosenko <andrew.w.nosenko@gmail.com>



^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2012-10-05 22:58 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-30 21:09 Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
2012-10-01  6:41 ` Dani Moncayo
2012-10-01 14:57   ` Stefan Monnier
2012-10-01 15:05     ` Christopher Monsanto
2012-10-01 15:11       ` Dani Moncayo
2012-10-01 15:22         ` Drew Adams
2012-10-01 15:21       ` Drew Adams
2012-10-01 15:30         ` Christopher Monsanto
2012-10-01 15:40           ` Drew Adams
2012-10-01 15:41           ` Dani Moncayo
2012-10-01 16:00             ` Drew Adams
2012-10-01 17:49               ` Juri Linkov
2012-10-01 18:21                 ` Drew Adams
2012-10-01 18:31               ` Dani Moncayo
2012-10-01 18:47                 ` Drew Adams
2012-10-01 18:50                   ` Christopher Monsanto
2012-10-01 18:54                   ` Lennart Borgman
2012-10-01 20:00                     ` Drew Adams
2012-10-01 19:12                   ` Dani Moncayo
2012-10-02 11:26             ` Nix
2012-10-02 13:55               ` Drew Adams
2012-10-02 16:48               ` Eli Zaretskii
2012-10-04 11:37                 ` Nix
2012-10-05 22:58         ` Andrew W. Nosenko
2012-10-01 15:18     ` Drew Adams
2012-10-02  3:22       ` Stephen J. Turnbull
2012-10-02 12:37         ` Richard Stallman
2012-10-02 14:05           ` Isearch: retrieve last successful search string from when youquit (`C-g') Drew Adams
2012-10-01 15:17   ` Isearch: retrieve last successful search string from when you quit (`C-g') Drew Adams
2012-10-02 11:29     ` Nix
2012-10-02 14:03       ` Drew Adams

Code repositories for project(s) associated with this public inbox

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

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).