unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Juri Linkov <juri@jurta.org>
Cc: 11381@debbugs.gnu.org
Subject: bug#11381: 23.3; isearch-search-and-update issue?
Date: Mon, 28 May 2012 00:48:19 -0400	[thread overview]
Message-ID: <jwv62bhue6i.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87mx4u0xiu.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 27 May 2012 12:43:37 +0300")

>>>>> "Juri" == Juri Linkov <juri@jurta.org> 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 ")
> +
>  \f
>  (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





  reply	other threads:[~2012-05-28  4:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-29 22:31 bug#11381: 23.3; isearch-search-and-update issue? Andy Grover
2012-04-30  0:27 ` Juri Linkov
2012-05-01  9:03 ` Juri Linkov
2012-05-01 13:08   ` Stefan Monnier
2012-05-01 15:17     ` Juri Linkov
2012-05-15 21:35       ` Juri Linkov
2012-05-16  2:35         ` Stefan Monnier
2012-05-17  0:08           ` Juri Linkov
2012-05-20  0:15             ` Juri Linkov
2012-05-21  1:36               ` Stefan Monnier
2012-05-21  2:23                 ` Stefan Monnier
2012-05-27  9:43                   ` Juri Linkov
2012-05-28  4:48                     ` Stefan Monnier [this message]
2012-05-28  8:55                       ` Juri Linkov
2012-05-28 14:08                         ` Stefan Monnier
2012-05-29  9:49                           ` Juri Linkov
2012-05-29 13:34                             ` Stefan Monnier
2012-05-27  9:35                 ` Juri Linkov
2012-05-28  4:23                   ` Stefan Monnier
2012-05-28 15:44                     ` Eli Zaretskii
2012-05-28 17:34                       ` bug#11381: use and doc of function symbol properties [was: bug#11381: 23.3; isearch-search-and-update issue?] Drew Adams
2012-05-28 19:34                       ` bug#11381: 23.3; isearch-search-and-update issue? Stefan Monnier
2012-05-29  0:27                         ` Juri Linkov
2012-05-29  1:26                           ` Stefan Monnier

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=jwv62bhue6i.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=11381@debbugs.gnu.org \
    --cc=juri@jurta.org \
    /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).