From d5e61c1c754a725dea0d7b949e705ce4a98789af Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 29 May 2012 12:27:39 +0300 Subject: [PATCH] * lisp/isearch.el (isearch-word): Add docstring. (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 | 12 ++++++++++++ lisp/isearch.el | 47 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c155b0a27c0..ae410d54075 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2012-05-29 Juri Linkov + + * 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 * isearch.el (isearch-search-fun-default): New function. diff --git a/lisp/isearch.el b/lisp/isearch.el index 2fcd2d53251..8564a390314 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -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 -- 2.39.2