unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <emacs-devel@gnu.org>
Subject: Isearch: always try to find longest successful prefix [was: move to fail position in Isearch edit]
Date: Tue, 11 Nov 2008 07:07:32 -0800	[thread overview]
Message-ID: <001901c9440f$39133c90$0200a8c0@us.oracle.com> (raw)
In-Reply-To: <001101c943c8$adc09750$0200a8c0@us.oracle.com>

I suggested this:

> Any interest in this? I bind it to `M-e' in 
> `minibuffer-local-isearch-map', so `M-e M-e' puts the
> cursor at the match failure position. 
> 
> If you type a search string quickly and mistype a char or 
> two, this lets you correct the typo without discarding
> and retyping the rest of the search string:
> `M-e M-e <corrections> C-s'.
> 
> (defun isearch-goto-success-end ()
>     "Go to end of search string text that matches."
>     (interactive)
>     (goto-char (point-max))
>     (let ((cmds  isearch-cmds)
>           succ-msg)
>       (when (or (not isearch-success) isearch-error)
>         (while (or (not (isearch-success-state (car cmds))) 
>                    (isearch-error-state (car cmds)))
>           (pop cmds))
>         (setq succ-msg  (and cmds (isearch-message-state (car cmds))))
>         (backward-char (- (length isearch-string)
>                           (length succ-msg))))))
> 
> (define-key minibuffer-local-isearch-map 
>             "\M-e" 'isearchp-goto-success-end)

You'll notice that this would be a lot handier if Isearch always started out
(and resumed after Isearch edit) by treating the search string incrementally.

For example, suppose you search again with a previous search string `aaxbbb' by
hitting `C-s C-s' in a buffer where there is no match for `aaxbbb' but there are
matches for `aa'.

Isearch fails immediately, showing the entire search string, `aaxbbb', as a
failed match by highlighting it. If, however, you had typed `aaxbbb' to a fresh
`C-s', then the `aa' match would be located, and the failure highlighting would
correctly reflect the `aa' prefix match success and the `xbbb' suffix match
failure.

You could then, for example, hit RET to stop at the partial match (`aa')
position.

Or you could use the above code to quickly edit only the non-matching part. If,
for example, the buffer contained `aapbbb' or `aabbb', then a quick 1-character
change in the middle of the search string would put you on your way.

Besides these benefits would be the benefit of more consistency. Isearch would
always act the same (incrementally), even when it is given a complete string to
start with, just as if you had typed the string a character at a time.

I don't have the time to figure out what might need to be done to get this
behavior, which is preferable in my opinion. Perhaps someone who is an Isearch
guru (Juri?) will be interested and have the time?






  parent reply	other threads:[~2008-11-11 15:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-11  6:42 move to fail position in Isearch edit Drew Adams
2008-11-11  7:13 ` Mathias Dahl
2008-11-11 15:07 ` Drew Adams [this message]
2008-11-11 17:32   ` Isearch: always try to find longest successful prefix [was: move to fail position in Isearch edit] Juri Linkov
2008-11-11 20:19     ` Drew Adams
2008-11-11 17:33 ` move to fail position in Isearch edit Juri Linkov
2008-11-11 20:16   ` Drew Adams
2008-11-11 20:33   ` Mathias Dahl
2008-11-11 21:02     ` Drew Adams
2008-11-11 21:36       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

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

  git send-email \
    --in-reply-to='001901c9440f$39133c90$0200a8c0@us.oracle.com' \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).