+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.
(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.
;; 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)
;; "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
(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)))))
(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)))))
(< (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 "")
"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