[Top][All Lists]

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

Re: Strange behavior of word isearch

From: Juri Linkov
Subject: Re: Strange behavior of word isearch
Date: Sun, 09 Nov 2008 00:59:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

> I checked in the modified functions as word-search-forward-lax
> and word-search-backward-lax, and made isearch use them.
> If someone has a better idea, let me know.

Currently word isearch is open-ended, so it is not possible to restrict
the search to the right word boundary, such as matching only singular
word forms and not plurals ("default" vs "defaults" etc.)  And typing
additional whitespace at the end is both inconvenient and not self-apparent
especially when there is only one word and not a list of words separated
by whitespace.  However, there exists a good solution.

In http://thread.gmane.org/gmane.emacs.devel/76174/focus=101795
Stefan writes:

    E.g. we could provide a key that says "here, I'm done entering the
    pattern".  That key could be C-s/C-r or RET, or something else.
    Entering more text should probably revert back to "the pattern is not
    done yet".

I now think this is the best way to implement the word search.
The following small patch does this.  It uses the lax versions of
word search functions recently implemented by Yidong, only when the user
incrementally adds or removes characters in the search string,
thus allowing the user to enter a complete word string without
failing in the middle.

In all other cases like using C-s/C-r to navigate between matches, it uses
the default strict versions of word search functions that allows to find
all exact word matches.  And lazy highlighting works correctly as well.
I believe this will provide the most useful behavior for the word search:

Index: lisp/isearch.el
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.331
diff -c -r1.331 isearch.el
*** lisp/isearch.el     19 Oct 2008 22:33:17 -0000      1.331
--- lisp/isearch.el     8 Nov 2008 22:54:14 -0000
*** 2178,2184 ****
        (funcall isearch-search-fun-function)
!       (if isearch-forward 'word-search-forward-lax 'word-search-backward-lax))
        (if isearch-forward 're-search-forward 're-search-backward))
--- 2182,2193 ----
        (funcall isearch-search-fun-function)
!       ;; Use lax versions to not fail at the end of the word while the user
!       ;; adds and removes characters in the search string
!       (if (not (eq (length isearch-string)
!                  (length (isearch-string-state (car isearch-cmds)))))
!         (if isearch-forward 'word-search-forward-lax 
!       (if isearch-forward 'word-search-forward 'word-search-backward)))
        (if isearch-forward 're-search-forward 're-search-backward))

Juri Linkov

reply via email to

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