From: Juri Linkov <juri@jurta.org>
To: Dani Moncayo <dmoncayo@gmail.com>
Cc: 10145@debbugs.gnu.org
Subject: bug#10145: 24.0.91; Word Isearch backward
Date: Tue, 29 Nov 2011 02:33:06 +0200 [thread overview]
Message-ID: <87k46jyd79.fsf@mail.jurta.org> (raw)
In-Reply-To: <CAH8Pv0iVQsYuJt8XJCEYaYqJTO8_fRwtXeJCsLiA_QLZDrAzPg@mail.gmail.com> (Dani Moncayo's message of "Sat, 26 Nov 2011 21:26:58 +0100")
> from "emacs -Q", type: `a a RET b b RET M-s w C-r a a SPC b b'.
>
> At this point, the Isearch (word-type, backward) should succeed, but I
> see a failing one.
Thanks, this is a bug.
The comment in `isearch-search-and-update' says:
;; In reverse search, adding stuff at
;; the end may cause zero or many more chars to be
;; matched, in the string following point.
;; Allow all those possibilities without moving point as
;; long as the match does not extend past search origin.
and it calls `looking-at' to implement this.
But it doesn't take into account word search.
The following patch fixes this bug by using `wordify'
now exposed to Lisp:
=== modified file 'lisp/isearch.el'
--- lisp/isearch.el 2011-11-28 06:59:03 +0000
+++ lisp/isearch.el 2011-11-29 00:30:33 +0000
@@ -1648,8 +1643,10 @@ (defun isearch-search-and-update ()
(if (and (eq case-fold-search t) search-upper-case)
(setq case-fold-search
(isearch-no-upper-case-p isearch-string isearch-regexp)))
- (looking-at (if isearch-regexp isearch-string
- (regexp-quote isearch-string))))
+ (looking-at (cond
+ (isearch-regexp isearch-string)
+ (isearch-word (wordify isearch-string t))
+ (t (regexp-quote isearch-string)))))
(error nil))
(or isearch-yank-flag
(<= (match-end 0)
=== modified file 'src/search.c'
--- src/search.c 2011-11-27 18:17:40 +0000
+++ src/search.c 2011-11-29 00:29:22 +0000
@@ -2078,13 +2078,12 @@ (at your option) any later version.
XSETBUFFER (last_thing_searched, current_buffer);
}
\f
-/* Given STRING, a string of words separated by word delimiters,
- compute a regexp that matches those exact words separated by
- arbitrary punctuation. If LAX is nonzero, the end of the string
- need not match a word boundary unless it ends in whitespace. */
-
-static Lisp_Object
-wordify (Lisp_Object string, int lax)
+DEFUN ("wordify", Fwordify, Swordify, 1, 2, 0,
+ doc: /* Given STRING, a string of words separated by word delimiters,
+compute a regexp that matches those exact words separated by
+arbitrary punctuation. If LAX is non-nil, the end of the string
+need not match a word boundary unless it ends in whitespace. */)
+ (Lisp_Object string, Lisp_Object lax)
{
register unsigned char *o;
register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0;
@@ -2125,7 +2124,7 @@ (at your option) any later version.
}
adjust = - punct_count + 5 * (word_count - 1)
- + ((lax && !whitespace_at_end) ? 2 : 4);
+ + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4);
if (STRING_MULTIBYTE (string))
val = make_uninit_multibyte_string (len + adjust,
SBYTES (string)
@@ -2162,7 +2161,7 @@ (at your option) any later version.
prev_c = c;
}
- if (!lax || whitespace_at_end)
+ if (NILP (lax) || whitespace_at_end)
{
*o++ = '\\';
*o++ = 'b';
@@ -2220,7 +2219,7 @@ (at your option) any later version.
Optional fourth argument is repeat count--search for successive occurrences. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (wordify (string, 0), bound, noerror, count, -1, 1, 0);
+ return search_command (Fwordify (string, Qnil), bound, noerror, count, -1, 1, 0);
}
DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
@@ -2234,7 +2233,7 @@ (at your option) any later version.
Optional fourth argument is repeat count--search for successive occurrences. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (wordify (string, 0), bound, noerror, count, 1, 1, 0);
+ return search_command (Fwordify (string, Qnil), bound, noerror, count, 1, 1, 0);
}
DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4,
@@ -2252,7 +2251,7 @@ (at your option) any later version.
Optional fourth argument is repeat count--search for successive occurrences. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (wordify (string, 1), bound, noerror, count, -1, 1, 0);
+ return search_command (Fwordify (string, Qt), bound, noerror, count, -1, 1, 0);
}
DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4,
@@ -2270,7 +2269,7 @@ (at your option) any later version.
Optional fourth argument is repeat count--search for successive occurrences. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (wordify (string, 1), bound, noerror, count, 1, 1, 0);
+ return search_command (Fwordify (string, Qt), bound, noerror, count, 1, 1, 0);
}
DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
@@ -3229,6 +3228,7 @@ (at your option) any later version.
defsubr (&Sposix_string_match);
defsubr (&Ssearch_forward);
defsubr (&Ssearch_backward);
+ defsubr (&Swordify);
defsubr (&Sword_search_forward);
defsubr (&Sword_search_backward);
defsubr (&Sword_search_forward_lax);
Actually there are more places that require the Lisp call to `wordify'
like in `isearch-occur':
=== modified file 'lisp/isearch.el'
--- lisp/isearch.el 2011-11-28 06:59:03 +0000
+++ lisp/isearch.el 2011-11-29 00:30:33 +0000
@@ -1447,12 +1447,7 @@ (defun isearch-occur (regexp &optional n
(interactive
(list
(cond
- (isearch-word (concat "\\b" (replace-regexp-in-string
- "\\W+" "\\W+"
- (replace-regexp-in-string
- "^\\W+\\|\\W+$" "" isearch-string)
- nil t)
- "\\b"))
+ (isearch-word (wordify isearch-string))
(isearch-regexp isearch-string)
(t (regexp-quote isearch-string)))
(if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
next prev parent reply other threads:[~2011-11-29 0:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-26 20:26 bug#10145: 24.0.91; Word Isearch backward Dani Moncayo
2011-11-29 0:33 ` Juri Linkov [this message]
2011-11-29 8:40 ` Andreas Schwab
2011-11-30 9:46 ` Juri Linkov
2011-11-30 14:02 ` Stefan Monnier
2011-11-30 15:32 ` Juri Linkov
2011-11-30 19:11 ` Stefan Monnier
2011-12-01 7:27 ` Juri Linkov
2011-12-01 16:00 ` Stefan Monnier
2011-12-02 10:22 ` Juri Linkov
2011-12-02 10:48 ` Eli Zaretskii
2011-12-02 14:38 ` Stefan Monnier
2011-12-02 17:11 ` 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=87k46jyd79.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=10145@debbugs.gnu.org \
--cc=dmoncayo@gmail.com \
/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).