emacs-devel
[Top][All Lists]
Advanced

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

RE: Isearch: retrieve last successful search string from when you quit (


From: Drew Adams
Subject: RE: Isearch: retrieve last successful search string from when you quit (`C-g')
Date: Mon, 1 Oct 2012 09:00:23 -0700

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




reply via email to

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