[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#10145: 24.0.91; Word Isearch backward
From: |
Juri Linkov |
Subject: |
bug#10145: 24.0.91; Word Isearch backward |
Date: |
Wed, 30 Nov 2011 11:46:38 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (x86_64-pc-linux-gnu) |
>> + doc: /* Given STRING, a string of words separated by word delimiters,
>
> The first line needs to be a complete sentence.
In the patch below the first line is a complete sentence,
and `wordify' is renamed to a better and more correct name
`word-regexp':
=== modified file 'src/search.c'
--- src/search.c 2011-11-27 18:17:40 +0000
+++ src/search.c 2011-11-30 09:41:35 +0000
@@ -2078,13 +2078,13 @@ (at your option) any later version.
XSETBUFFER (last_thing_searched, current_buffer);
}
-/* 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 ("word-regexp", Fword_regexp, Sword_regexp, 1, 2, 0,
+ doc: /* Return a regexp which matches words, ignoring punctuation.
+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 +2125,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 +2162,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 +2220,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 (Fword_regexp (string, Qnil), bound, noerror, count,
-1, 1, 0);
}
DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
@@ -2234,7 +2234,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 (Fword_regexp (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 +2252,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 (Fword_regexp (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 +2270,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 (Fword_regexp (string, Qt), bound, noerror, count, 1,
1, 0);
}
DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
@@ -3229,6 +3229,7 @@ (at your option) any later version.
defsubr (&Sposix_string_match);
defsubr (&Ssearch_forward);
defsubr (&Ssearch_backward);
+ defsubr (&Sword_regexp);
defsubr (&Sword_search_forward);
defsubr (&Sword_search_backward);
defsubr (&Sword_search_forward_lax);
=== modified file 'lisp/isearch.el'
--- lisp/isearch.el 2011-11-29 18:39:16 +0000
+++ lisp/isearch.el 2011-11-30 09:41:35 +0000
@@ -1438,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 (word-regexp isearch-string))
(isearch-regexp isearch-string)
(t (regexp-quote isearch-string)))
(if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
@@ -1642,8 +1646,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 (word-regexp isearch-string t))
+ (t (regexp-quote isearch-string)))))
(error nil))
(or isearch-yank-flag
(<= (match-end 0)