From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#11381: 23.3; isearch-search-and-update issue? Date: Wed, 16 May 2012 00:35:30 +0300 Organization: JURTA Message-ID: <87vcjxdt5p.fsf@mail.jurta.org> References: <4F9DC154.2000605@groveronline.com> <87ipgggtmw.fsf@mail.jurta.org> <878vhcc4nl.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1337118009 27083 80.91.229.3 (15 May 2012 21:40:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 15 May 2012 21:40:09 +0000 (UTC) To: 11381@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 15 23:40:08 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SUPTQ-00065o-Db for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 May 2012 23:40:04 +0200 Original-Received: from localhost ([::1]:37724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUPTP-0000UX-Rd for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 May 2012 17:40:03 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUPTL-0000TK-JT for bug-gnu-emacs@gnu.org; Tue, 15 May 2012 17:40:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUPTI-0002ZD-Je for bug-gnu-emacs@gnu.org; Tue, 15 May 2012 17:39:59 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUPTI-0002Z3-Fc for bug-gnu-emacs@gnu.org; Tue, 15 May 2012 17:39:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SUPTN-0007Jp-Ky for bug-gnu-emacs@gnu.org; Tue, 15 May 2012 17:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 May 2012 21:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11381 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11381-submit@debbugs.gnu.org id=B11381.133711798028100 (code B ref 11381); Tue, 15 May 2012 21:40:01 +0000 Original-Received: (at 11381) by debbugs.gnu.org; 15 May 2012 21:39:40 +0000 Original-Received: from localhost ([127.0.0.1]:56734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SUPT1-0007JA-IP for submit@debbugs.gnu.org; Tue, 15 May 2012 17:39:40 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:58285 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SUPSx-0007Iz-Rm for 11381@debbugs.gnu.org; Tue, 15 May 2012 17:39:37 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id AB6F4451C9FB for <11381@debbugs.gnu.org>; Tue, 15 May 2012 14:39:27 -0700 (PDT) In-Reply-To: <878vhcc4nl.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 01 May 2012 18:17:02 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60047 Archived-At: > `isearch-word' binds the search function to `word-search-forward' > and `word-search-backward', so perhaps new functions > `symbol-search-forward' and `symbol-search-backward' > will be necessary too. Before trying to implement `symbol-search-forward', word-search-{for,back}ward{-lax,} need to be moved to Elisp as Stefan asked to do for 24.2 in bug#10145. Below is a complete patch that moves them to Elisp: === modified file 'lisp/isearch.el' --- lisp/isearch.el 2012-02-23 00:36:49 +0000 +++ lisp/isearch.el 2012-05-15 21:27:45 +0000 @@ -1381,6 +1393,94 @@ (defun isearch-toggle-case-fold () (sit-for 1) (isearch-update)) + +;; Word search + +(defun word-search-regexp (string &optional lax) + "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. + +Used in `word-search-forward', `word-search-backward', +`word-search-forward-lax', `word-search-backward-lax'." + (if (string-match-p "^\\W*$" string) + "" + (concat + "\\b" + (mapconcat 'identity (split-string string "\\W+" t) "\\W+") + (if (or (not lax) (string-match-p "\\W$" string)) "\\b")))) + +(defun word-search-backward (string &optional bound noerror count) + "Search backward from point for STRING, ignoring differences in punctuation. +Set point to the beginning of the occurrence found, and return point. +An optional second argument bounds the search; it is a buffer position. +The match found must not extend before that position. +Optional third argument, if t, means if fail just return nil (no error). + If not nil and not t, move to limit of search and return nil. +Optional fourth argument is repeat count--search for successive occurrences. + +Relies on the function `word-search-regexp' to convert a sequence +of words in STRING to a regexp used to search words without regard +to punctuation." + (interactive "sWord search backward: ") + (re-search-backward (word-search-regexp string nil) bound noerror count)) + +(defun word-search-forward (string &optional bound noerror count) + "Search forward from point for STRING, ignoring differences in punctuation. +Set point to the end of the occurrence found, and return point. +An optional second argument bounds the search; it is a buffer position. +The match found must not extend after that position. +Optional third argument, if t, means if fail just return nil (no error). + If not nil and not t, move to limit of search and return nil. +Optional fourth argument is repeat count--search for successive occurrences. + +Relies on the function `word-search-regexp' to convert a sequence +of words in STRING to a regexp used to search words without regard +to punctuation." + (interactive "sWord search: ") + (re-search-forward (word-search-regexp string nil) bound noerror count)) + +(defun word-search-backward-lax (string &optional bound noerror count) + "Search backward from point for STRING, ignoring differences in punctuation. +Set point to the beginning of the occurrence found, and return point. + +Unlike `word-search-backward', the end of STRING need not match a word +boundary, unless STRING ends in whitespace. + +An optional second argument bounds the search; it is a buffer position. +The match found must not extend before that position. +Optional third argument, if t, means if fail just return nil (no error). + If not nil and not t, move to limit of search and return nil. +Optional fourth argument is repeat count--search for successive occurrences. + +Relies on the function `word-search-regexp' to convert a sequence +of words in STRING to a regexp used to search words without regard +to punctuation." + (interactive "sWord search backward: ") + (re-search-backward (word-search-regexp string t) bound noerror count)) + +(defun word-search-forward-lax (string &optional bound noerror count) + "Search forward from point for STRING, ignoring differences in punctuation. +Set point to the end of the occurrence found, and return point. + +Unlike `word-search-forward', the end of STRING need not match a word +boundary, unless STRING ends in whitespace. + +An optional second argument bounds the search; it is a buffer position. +The match found must not extend after that position. +Optional third argument, if t, means if fail just return nil (no error). + If not nil and not t, move to limit of search and return nil. +Optional fourth argument is repeat count--search for successive occurrences. + +Relies on the function `word-search-regexp' to convert a sequence +of words in STRING to a regexp used to search words without regard +to punctuation." + (interactive "sWord search: ") + (re-search-forward (word-search-regexp string t) bound noerror count)) + + (defun isearch-query-replace (&optional delimited regexp-flag) "Start `query-replace' with string to replace from last search string. The arg DELIMITED (prefix arg if interactive), if non-nil, means replace === modified file 'src/search.c' --- src/search.c 2012-03-27 06:46:42 +0000 +++ src/search.c 2012-05-15 21:27:00 +0000 @@ -2078,102 +2078,6 @@ (at your option) any later version. XSETBUFFER (last_thing_searched, current_buffer); } -DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_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. - -Used in `word-search-forward', `word-search-backward', -`word-search-forward-lax', `word-search-backward-lax'. */) - (Lisp_Object string, Lisp_Object lax) -{ - register unsigned char *o; - register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0; - Lisp_Object val; - int prev_c = 0; - EMACS_INT adjust; - int whitespace_at_end; - - CHECK_STRING (string); - len = SCHARS (string); - - for (i = 0, i_byte = 0; i < len; ) - { - int c; - - FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); - - if (SYNTAX (c) != Sword) - { - punct_count++; - if (SYNTAX (prev_c) == Sword) - word_count++; - } - - prev_c = c; - } - - if (SYNTAX (prev_c) == Sword) - { - word_count++; - whitespace_at_end = 0; - } - else - { - whitespace_at_end = 1; - if (!word_count) - return empty_unibyte_string; - } - - adjust = - punct_count + 5 * (word_count - 1) - + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4); - if (STRING_MULTIBYTE (string)) - val = make_uninit_multibyte_string (len + adjust, - SBYTES (string) - + adjust); - else - val = make_uninit_string (len + adjust); - - o = SDATA (val); - *o++ = '\\'; - *o++ = 'b'; - prev_c = 0; - - for (i = 0, i_byte = 0; i < len; ) - { - int c; - EMACS_INT i_byte_orig = i_byte; - - FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); - - if (SYNTAX (c) == Sword) - { - memcpy (o, SDATA (string) + i_byte_orig, i_byte - i_byte_orig); - o += i_byte - i_byte_orig; - } - else if (SYNTAX (prev_c) == Sword && --word_count) - { - *o++ = '\\'; - *o++ = 'W'; - *o++ = '\\'; - *o++ = 'W'; - *o++ = '*'; - } - - prev_c = c; - } - - if (NILP (lax) || whitespace_at_end) - { - *o++ = '\\'; - *o++ = 'b'; - } - - return val; -} - DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, "MSearch backward: ", doc: /* Search backward from point for STRING. @@ -2216,86 +2120,6 @@ (at your option) any later version. return search_command (string, bound, noerror, count, 1, 0, 0); } -DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4, - "sWord search backward: ", - doc: /* Search backward from point for STRING, ignoring differences in punctuation. -Set point to the beginning of the occurrence found, and return point. -An optional second argument bounds the search; it is a buffer position. -The match found must not extend before that position. -Optional third argument, if t, means if fail just return nil (no error). - If not nil and not t, move to limit of search and return nil. -Optional fourth argument is repeat count--search for successive occurrences. - -Relies on the function `word-search-regexp' to convert a sequence -of words in STRING to a regexp used to search words without regard -to punctuation. */) - (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) -{ - return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0); -} - -DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, - "sWord search: ", - doc: /* Search forward from point for STRING, ignoring differences in punctuation. -Set point to the end of the occurrence found, and return point. -An optional second argument bounds the search; it is a buffer position. -The match found must not extend after that position. -Optional third argument, if t, means if fail just return nil (no error). - If not nil and not t, move to limit of search and return nil. -Optional fourth argument is repeat count--search for successive occurrences. - -Relies on the function `word-search-regexp' to convert a sequence -of words in STRING to a regexp used to search words without regard -to punctuation. */) - (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) -{ - return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0); -} - -DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, - "sWord search backward: ", - doc: /* Search backward from point for STRING, ignoring differences in punctuation. -Set point to the beginning of the occurrence found, and return point. - -Unlike `word-search-backward', the end of STRING need not match a word -boundary, unless STRING ends in whitespace. - -An optional second argument bounds the search; it is a buffer position. -The match found must not extend before that position. -Optional third argument, if t, means if fail just return nil (no error). - If not nil and not t, move to limit of search and return nil. -Optional fourth argument is repeat count--search for successive occurrences. - -Relies on the function `word-search-regexp' to convert a sequence -of words in STRING to a regexp used to search words without regard -to punctuation. */) - (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) -{ - return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0); -} - -DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, - "sWord search: ", - doc: /* Search forward from point for STRING, ignoring differences in punctuation. -Set point to the end of the occurrence found, and return point. - -Unlike `word-search-forward', the end of STRING need not match a word -boundary, unless STRING ends in whitespace. - -An optional second argument bounds the search; it is a buffer position. -The match found must not extend after that position. -Optional third argument, if t, means if fail just return nil (no error). - If not nil and not t, move to limit of search and return nil. -Optional fourth argument is repeat count--search for successive occurrences. - -Relies on the function `word-search-regexp' to convert a sequence -of words in STRING to a regexp used to search words without regard -to punctuation. */) - (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) -{ - return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0); -} - DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, "sRE search backward: ", doc: /* Search backward from point for match for regular expression REGEXP. @@ -3252,11 +3076,6 @@ (at your option) any later version. defsubr (&Sposix_string_match); defsubr (&Ssearch_forward); defsubr (&Ssearch_backward); - defsubr (&Sword_search_regexp); - defsubr (&Sword_search_forward); - defsubr (&Sword_search_backward); - defsubr (&Sword_search_forward_lax); - defsubr (&Sword_search_backward_lax); defsubr (&Sre_search_forward); defsubr (&Sre_search_backward); defsubr (&Sposix_search_forward);