From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#11381: 23.3; isearch-search-and-update issue? Date: Mon, 28 May 2012 00:48:19 -0400 Message-ID: References: <4F9DC154.2000605@groveronline.com> <87ipgggtmw.fsf@mail.jurta.org> <878vhcc4nl.fsf@mail.jurta.org> <87vcjxdt5p.fsf@mail.jurta.org> <87vcjvwtxa.fsf@mail.jurta.org> <87r4ufhfmi.fsf@mail.jurta.org> <87mx4u0xiu.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1338180536 9657 80.91.229.3 (28 May 2012 04:48:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 May 2012 04:48:56 +0000 (UTC) Cc: 11381@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 28 06:48:55 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 1SYrt0-0004Wz-4F for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 May 2012 06:48:54 +0200 Original-Received: from localhost ([::1]:50371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYrsz-0001s1-R8 for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 May 2012 00:48:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYrsw-0001rw-0h for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 00:48:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SYrst-0003Ju-Ns for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 00:48:49 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36486) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYrst-0003Jq-Jh for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 00:48:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SYru6-00019F-IT for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 00:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 May 2012 04:50:02 +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.13381805854386 (code B ref 11381); Mon, 28 May 2012 04:50:02 +0000 Original-Received: (at 11381) by debbugs.gnu.org; 28 May 2012 04:49:45 +0000 Original-Received: from localhost ([127.0.0.1]:46032 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SYrto-00018g-6y for submit@debbugs.gnu.org; Mon, 28 May 2012 00:49:44 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:36625) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SYrtl-00018U-OH for 11381@debbugs.gnu.org; Mon, 28 May 2012 00:49:42 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09MCpYd/2dsb2JhbABEtBGBCIIVAQEEAVYjBQsLNBIUGA0kE4gJBboJkEQDozOBWIMF X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="183056971" Original-Received: from 76-10-150-29.dsl.teksavvy.com (HELO ceviche.home) ([76.10.150.29]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 28 May 2012 00:48:20 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 1A0C4660E0; Mon, 28 May 2012 00:48:19 -0400 (EDT) In-Reply-To: <87mx4u0xiu.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 27 May 2012 12:43:37 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) 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:60411 Archived-At: >>>>> "Juri" == Juri Linkov writes: >>>> @@ -1425,7 +1445,11 @@ (defun word-search-backward (string &opt >>>> 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)) >>>> + (re-search-backward >>>> + (if (functionp isearch-word) >>>> + (funcall isearch-word string nil) >>>> + (word-search-regexp string nil)) >>>> + bound noerror count)) >>> This doesn't sound right. >> >> I guess I was a bit terse here: what I meant is that changing the >> behavior depending on isearch-* variables is OK for a function named >> isearch-foo but not word-search-*ward. > Agreed. This patch adds 4 new functions `isearch-word-search-*'. Do we really need those 4? I think we can just get away with symbol-search-regexp (whose name also needs to start with "isearch-"). > Also it splits the standard default part of `isearch-search-fun' You could actually set isearch-search-fun-function's default to isearch-search-fun-default so we can just unconditionally call isearch-search-fun-function's. > into a separate function `isearch-search-fun-default' that can be > used to obtain the default search function in any special search > function that overrides `isearch-search-fun' like is is demonstrated > in the second patch for `minibuffer-history-isearch-search' below. > Additionally it enables the word search in the minibuffer with no effort > (the key clash with `M-s w' in the minibuffer is another issue). > I'll also go through other search functions and enable word/symbol search > in them as well. > === modified file 'lisp/isearch.el' > --- lisp/isearch.el 2012-05-17 00:03:49 +0000 > +++ lisp/isearch.el 2012-05-27 09:43:07 +0000 > @@ -1468,6 +1500,62 @@ (defun word-search-forward-lax (string & > (interactive "sWord search: ") > (re-search-forward (word-search-regexp string t) bound noerror count)) > +;; General word-like regexp-based search. > + > +(defun isearch-word-search-backward (string &optional bound noerror count) > + "Search backward from point for STRING, converted to regexp. > +Like `word-search-backward', but uses a function from the variable > +`isearch-word' to convert STRING to the regexp." > + (re-search-backward > + (if (functionp isearch-word) > + (funcall isearch-word string nil) > + (word-search-regexp string nil)) > + bound noerror count)) > + > +(defun isearch-word-search-forward (string &optional bound noerror count) > + "Search forward from point for STRING, converted to regexp. > +Like `word-search-forward', but uses a function from the variable > +`isearch-word' to convert STRING to the regexp." > + (re-search-forward > + (if (functionp isearch-word) > + (funcall isearch-word string nil) > + (word-search-regexp string nil)) > + bound noerror count)) > + > +(defun isearch-word-search-backward-lax (string &optional bound noerror count) > + "Search backward from point for STRING, converted to regexp. > +Like `word-search-backward-lax', but uses a function from the variable > +`isearch-word' to convert STRING to the regexp." > + (re-search-backward > + (if (functionp isearch-word) > + (funcall isearch-word string t) > + (word-search-regexp string t)) > + bound noerror count)) > + > +(defun isearch-word-search-forward-lax (string &optional bound noerror count) > + "Search forward from point for STRING, converted to regexp. > +Like `word-search-forward-lax', but uses a function from the variable > +`isearch-word' to convert STRING to the regexp." > + (re-search-forward > + (if (functionp isearch-word) > + (funcall isearch-word string t) > + (word-search-regexp string t)) > + bound noerror count)) > + > +;; Symbol search > + > +(defun symbol-search-regexp (string &optional lax) > + "Return a regexp which matches STRING as a symbol. > +Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>. > +If LAX is non-nil, the end of the string need not match a symbol > +boundary unless it ends in whitespace." > + (concat > + "\\_<" > + (regexp-quote string) > + (if (or (not lax) (string-match-p "\\W$" string)) "\\_>"))) > + > +(put 'symbol-search-regexp 'isearch-message-prefix "symbol ") > + > > (defun isearch-query-replace (&optional delimited regexp-flag) > "Start `query-replace' with string to replace from last search string. > @@ -2370,20 +2473,23 @@ (defun isearch-search-fun () > Can be changed via `isearch-search-fun-function' for special needs." > (if isearch-search-fun-function > (funcall isearch-search-fun-function) > - (cond > - (isearch-word > - ;; Use lax versions to not fail at the end of the word while > - ;; the user adds and removes characters in the search string > - ;; (or when using nonincremental word isearch) > - (if (or isearch-nonincremental > - (eq (length isearch-string) > - (length (isearch-string-state (car isearch-cmds))))) > - (if isearch-forward 'word-search-forward 'word-search-backward) > - (if isearch-forward 'word-search-forward-lax 'word-search-backward-lax))) > - (isearch-regexp > - (if isearch-forward 're-search-forward 're-search-backward)) > - (t > - (if isearch-forward 'search-forward 'search-backward))))) > + (isearch-search-fun-default))) > + > +(defun isearch-search-fun-default () > + (cond > + (isearch-word > + ;; Use lax versions to not fail at the end of the word while > + ;; the user adds and removes characters in the search string > + ;; (or when using nonincremental word isearch) > + (if (or isearch-nonincremental > + (eq (length isearch-string) > + (length (isearch-string-state (car isearch-cmds))))) > + (if isearch-forward 'isearch-word-search-forward 'isearch-word-search-backward) If we inline your defs, this turns into: (if isearch-forward (lambda (string &optional bound noerror count) (re-search-forward (if (functionp isearch-word) (funcall isearch-word string nil) (word-search-regexp string nil)) bound noerror count)) (lambda (string &optional bound noerror count) (re-search-backward (if (functionp isearch-word) (funcall isearch-word string nil) (word-search-regexp string nil)) bound noerror count))) which can be simplified to (lambda (string &optional bound noerror count) (if isearch-forward (re-search-forward (if (functionp isearch-word) (funcall isearch-word string nil) (word-search-regexp string nil)) bound noerror count)) (re-search-backward (if (functionp isearch-word) (funcall isearch-word string nil) (word-search-regexp string nil)) bound noerror count))) and then (lambda (string &optional bound noerror count) (funcall (if isearch-forward #'re-search-forward #'re-search-backward) (if (functionp isearch-word) (funcall isearch-word string nil) (word-search-regexp string nil)) bound noerror count)) -- Stefan