* lisp/isearch.el (isearch-word): Add docstring.
authorJuri Linkov <juri@jurta.org>
Tue, 29 May 2012 09:27:39 +0000 (12:27 +0300)
committerJuri Linkov <juri@jurta.org>
Tue, 29 May 2012 09:27:39 +0000 (12:27 +0300)
(isearch-occur, isearch-search-and-update): If `isearch-word' is
a function, call it to get the regexp.
(isearch-message-prefix): If `isearch-word' holds a symbol, use its
property `isearch-message-prefix' instead of the string "word ".
(isearch-search-fun-default): For the case of `isearch-word',
return a lambda that calls re-search-forward/re-search-backward
with a regexp returned by `word-search-regexp' or by the function
in `isearch-word'.

Fixes: debbugs:11381

lisp/ChangeLog
lisp/isearch.el

index c155b0a..ae410d5 100644 (file)
@@ -1,3 +1,15 @@
+2012-05-29  Juri Linkov  <juri@jurta.org>
+
+       * isearch.el (isearch-word): Add docstring.  (Bug#11381)
+       (isearch-occur, isearch-search-and-update): If `isearch-word' is
+       a function, call it to get the regexp.
+       (isearch-message-prefix): If `isearch-word' holds a symbol, use its
+       property `isearch-message-prefix' instead of the string "word ".
+       (isearch-search-fun-default): For the case of `isearch-word',
+       return a lambda that calls re-search-forward/re-search-backward
+       with a regexp returned by `word-search-regexp' or by the function
+       in `isearch-word'.
+
 2012-05-29  Juri Linkov  <juri@jurta.org>
 
        * isearch.el (isearch-search-fun-default): New function.
index 2fcd2d5..8564a39 100644 (file)
@@ -530,8 +530,13 @@ This is like `describe-bindings', but displays only Isearch keys."
 
 (defvar isearch-forward nil)   ; Searching in the forward direction.
 (defvar isearch-regexp nil)    ; Searching for a regexp.
-(defvar isearch-word nil)      ; Searching for words.
-(defvar isearch-hidden nil) ; Non-nil if the string exists but is invisible.
+(defvar isearch-word nil
+  "Regexp-based search mode for words.
+If t, do incremental search for a sequence of words, ignoring punctuation.
+If the value is a function, it is called to convert the search string
+to a regexp used by regexp search functions.  The property
+`isearch-message-prefix' put on this function specifies the
+prefix string displyed in the search message.")
 
 (defvar isearch-cmds nil
   "Stack of search status sets.
@@ -592,6 +597,9 @@ Each set is a vector of the form:
 ;; Accumulate here the overlays opened during searching.
 (defvar isearch-opened-overlays nil)
 
+;; Non-nil if the string exists but is invisible.
+(defvar isearch-hidden nil)
+
 ;; The value of input-method-function when isearch is invoked.
 (defvar isearch-input-method-function nil)
 
@@ -747,14 +755,14 @@ as a regexp.  See the command `isearch-forward' for more information."
 ;;  "List of commands for which isearch-mode does not recursive-edit.")
 
 
-(defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
+(defun isearch-mode (forward &optional regexp op-fun recursive-edit word)
   "Start Isearch minor mode.
 It is called by the function `isearch-forward' and other related functions."
 
   ;; Initialize global vars.
   (setq isearch-forward forward
        isearch-regexp regexp
-       isearch-word word-p
+       isearch-word word
        isearch-op-fun op-fun
        isearch-last-case-fold-search isearch-case-fold-search
        isearch-case-fold-search case-fold-search
@@ -1534,6 +1542,8 @@ characters in that string."
   (interactive
    (let* ((perform-collect (consp current-prefix-arg))
          (regexp (cond
+                  ((functionp isearch-word)
+                   (funcall isearch-word isearch-string))
                   (isearch-word (word-search-regexp isearch-string))
                   (isearch-regexp isearch-string)
                   (t (regexp-quote isearch-string)))))
@@ -1749,6 +1759,8 @@ Subword is used when `subword-mode' is activated. "
                       (setq case-fold-search
                             (isearch-no-upper-case-p isearch-string isearch-regexp)))
                   (looking-at (cond
+                               ((functionp isearch-word)
+                                (funcall isearch-word isearch-string t))
                                (isearch-word (word-search-regexp isearch-string t))
                                (isearch-regexp isearch-string)
                                (t (regexp-quote isearch-string)))))
@@ -2329,7 +2341,11 @@ If there is no completion possible, say so and continue searching."
                              (< (point) isearch-opoint)))
                       "over")
                   (if isearch-wrapped "wrapped ")
-                  (if isearch-word "word " "")
+                  (if isearch-word
+                      (or (and (symbolp isearch-word)
+                               (get isearch-word 'isearch-message-prefix))
+                          "word ")
+                    "")
                   (if isearch-regexp "regexp " "")
                   (if multi-isearch-next-buffer-current-function "multi " "")
                   (or isearch-message-prefix-add "")
@@ -2374,14 +2390,19 @@ Can be changed via `isearch-search-fun-function' for special needs."
   "Return default functions to use for the search."
   (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)))
+    (lambda (string &optional bound noerror count)
+      ;; 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)
+      (let ((lax (not (or isearch-nonincremental
+                         (eq (length isearch-string)
+                             (length (isearch-string-state (car isearch-cmds))))))))
+       (funcall
+        (if isearch-forward #'re-search-forward #'re-search-backward)
+        (if (functionp isearch-word)
+            (funcall isearch-word string lax)
+          (word-search-regexp string lax))
+        bound noerror count))))
    (isearch-regexp
     (if isearch-forward 're-search-forward 're-search-backward))
    (t