Merge from trunk.
[bpt/emacs.git] / lisp / isearch.el
index 7f54067..977de6a 100644 (file)
@@ -542,8 +542,8 @@ Each set is a vector of the form:
 (defvar isearch-string "")  ; The current search string.
 (defvar isearch-message "") ; text-char-description version of isearch-string
 
-(defvar isearch-message-prefix-add nil) ; Additonal text for the message prefix
-(defvar isearch-message-suffix-add nil) ; Additonal text for the message suffix
+(defvar isearch-message-prefix-add nil) ; Additional text for the message prefix
+(defvar isearch-message-suffix-add nil) ; Additional text for the message suffix
 
 (defvar isearch-success t)     ; Searching is currently successful.
 (defvar isearch-error nil)     ; Error message for failed search.
@@ -1063,21 +1063,24 @@ nonincremental search instead via `isearch-edit-string'."
 
 (defvar minibuffer-history-symbol) ;; from external package gmhist.el
 
-(defun isearch-fail-pos ()
-  "Position of first mismatch in search string, or its length if none."
-  (let ((cmds isearch-cmds))
-    (if (and isearch-success (not isearch-error))
-        (length isearch-message)
+(defun isearch-fail-pos (&optional msg)
+  "Return position of first mismatch in search string, or nil if none.
+If MSG is non-nil, use `isearch-message', otherwise `isearch-string'."
+  (let ((cmds isearch-cmds)
+       (curr-msg (if msg isearch-message isearch-string))
+       succ-msg)
+    (when (or (not isearch-success) isearch-error)
       (while (or (not (isearch-success-state (car cmds)))
                  (isearch-error-state (car cmds)))
         (pop cmds))
-      (let ((succ-msg (and cmds (isearch-message-state (car cmds)))))
-        (if (and (stringp succ-msg)
-                 (< (length succ-msg) (length isearch-message))
-                 (equal succ-msg
-                        (substring isearch-message 0 (length succ-msg))))
-            (length succ-msg)
-          0)))))
+      (setq succ-msg (and cmds (if msg (isearch-message-state (car cmds))
+                                (isearch-string-state (car cmds)))))
+      (if (and (stringp succ-msg)
+              (< (length succ-msg) (length curr-msg))
+              (equal succ-msg
+                     (substring curr-msg 0 (length succ-msg))))
+         (length succ-msg)
+       0))))
 
 (defun isearch-edit-string ()
   "Edit the search string in the minibuffer.
@@ -1087,9 +1090,7 @@ The following additional command keys are active while editing.
 \\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
-\\[isearch-complete-edit] to complete the search string using the search ring.
-\\<isearch-mode-map>
-If first char entered is \\[isearch-yank-word-or-char], then do word search instead."
+\\[isearch-complete-edit] to complete the search string using the search ring."
 
   ;; This code is very hairy for several reasons, explained in the code.
   ;; Mainly, isearch-mode must be terminated while editing and then restarted.
@@ -1109,6 +1110,7 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
              (isearch-new-message isearch-message)
              (isearch-new-forward isearch-forward)
              (isearch-new-word isearch-word)
+             (isearch-new-case-fold isearch-case-fold-search)
 
              (isearch-regexp isearch-regexp)
              (isearch-op-fun isearch-op-fun)
@@ -1171,7 +1173,8 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
                (setq isearch-new-string
                       (read-from-minibuffer
                        (isearch-message-prefix nil nil isearch-nonincremental)
-                      (cons isearch-string (1+ (isearch-fail-pos)))
+                      (cons isearch-string (1+ (or (isearch-fail-pos)
+                                                   (length isearch-string))))
                        minibuffer-local-isearch-map nil
                        (if isearch-regexp
                           (cons 'regexp-search-ring
@@ -1201,7 +1204,8 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
            (setq isearch-string isearch-new-string
                  isearch-message isearch-new-message
                  isearch-forward isearch-new-forward
-                 isearch-word isearch-new-word))
+                 isearch-word isearch-new-word
+                 isearch-case-fold-search isearch-new-case-fold))
 
          ;; Empty isearch-string means use default.
          (when (= 0 (length isearch-string))
@@ -1381,8 +1385,8 @@ Use `isearch-exit' to quit without signaling."
   "Start `query-replace' with string to replace from last search string.
 The arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches surrounded by word boundaries.  Note that using the prefix arg
-is possible only when `isearch-allow-scroll' is non-nil, and it don't
-always provides the correct matches for `query-replace', so the preferred
+is possible only when `isearch-allow-scroll' is non-nil, and it doesn't
+always provide the correct matches for `query-replace', so the preferred
 way to run word replacements from Isearch is `M-s w ... M-%'."
   (interactive
    (list current-prefix-arg))
@@ -1448,7 +1452,7 @@ string.  NLINES has the same meaning as in `occur'."
        ;; Set `search-upper-case' to nil to not call
        ;; `isearch-no-upper-case-p' in `occur-1'.
        (search-upper-case nil)
-       (search-spaces-regexp search-whitespace-regexp))
+       (search-spaces-regexp (if isearch-regexp search-whitespace-regexp)))
     (occur regexp nlines)))
 
 (declare-function hi-lock-read-face-name "hi-lock" ())
@@ -1800,9 +1804,13 @@ Scroll-bar or mode-line events are processed appropriately."
 ;; Commands which change the window layout
 (put 'delete-other-windows 'isearch-scroll t)
 (put 'balance-windows 'isearch-scroll t)
+(put 'split-window-right 'isearch-scroll t)
+(put 'split-window-below 'isearch-scroll t)
+(put 'enlarge-window 'isearch-scroll t)
+
+;; Aliases for split-window-*
 (put 'split-window-vertically 'isearch-scroll t)
 (put 'split-window-horizontally 'isearch-scroll t)
-(put 'enlarge-window 'isearch-scroll t)
 
 ;; Universal argument commands
 (put 'universal-argument 'isearch-scroll t)
@@ -2176,22 +2184,11 @@ If there is no completion possible, say so and continue searching."
   ;; Generate and print the message string.
   (let ((cursor-in-echo-area ellipsis)
        (m isearch-message)
-       (cmds isearch-cmds)
-       succ-msg)
-    (when (or (not isearch-success) isearch-error)
-      ;; Highlight failed part
-      (while (or (not (isearch-success-state (car cmds)))
-                (isearch-error-state (car cmds)))
-       (pop cmds))
-      (setq succ-msg (and cmds (isearch-message-state (car cmds)))
-           m (copy-sequence m))
-      (add-text-properties
-       (if (and (stringp succ-msg)
-               (< (length succ-msg) (length m))
-               (equal succ-msg (substring m 0 (length succ-msg))))
-          (length succ-msg)
-        0)
-       (length m) '(face isearch-fail) m)
+       (fail-pos (isearch-fail-pos t)))
+    ;; Highlight failed part
+    (when fail-pos
+      (setq m (copy-sequence m))
+      (add-text-properties fail-pos (length m) '(face isearch-fail) m)
       ;; Highlight failed trailing whitespace
       (when (string-match " +$" m)
        (add-text-properties (match-beginning 0) (match-end 0)
@@ -2246,7 +2243,7 @@ If there is no completion possible, say so and continue searching."
 ;; Searching
 
 (defvar isearch-search-fun-function nil
-  "Overrides the default `isearch-search-fun' behaviour.
+  "Overrides the default `isearch-search-fun' behavior.
 This variable's value should be a function, which will be called
 with no arguments, and should return a function that takes three
 arguments: STRING, BOUND, and NOERROR.
@@ -2624,6 +2621,7 @@ since they have special meaning in a regexp."
 (defvar isearch-lazy-highlight-case-fold-search nil)
 (defvar isearch-lazy-highlight-regexp nil)
 (defvar isearch-lazy-highlight-space-regexp nil)
+(defvar isearch-lazy-highlight-word nil)
 (defvar isearch-lazy-highlight-forward nil)
 (defvar isearch-lazy-highlight-error nil)
 
@@ -2662,6 +2660,8 @@ by other Emacs features."
                          isearch-case-fold-search))
                 (not (eq isearch-lazy-highlight-regexp
                          isearch-regexp))
+                (not (eq isearch-lazy-highlight-word
+                         isearch-word))
                  (not (= (window-start)
                          isearch-lazy-highlight-window-start))
                  (not (= (window-end)   ; Window may have been split/joined.
@@ -2682,11 +2682,12 @@ by other Emacs features."
             isearch-lazy-highlight-window-end   (window-end)
             isearch-lazy-highlight-start        (point)
             isearch-lazy-highlight-end          (point)
+            isearch-lazy-highlight-wrapped      nil
             isearch-lazy-highlight-last-string  isearch-string
            isearch-lazy-highlight-case-fold-search isearch-case-fold-search
-           isearch-lazy-highlight-regexp       isearch-regexp
-            isearch-lazy-highlight-wrapped      nil
+           isearch-lazy-highlight-regexp       isearch-regexp
            isearch-lazy-highlight-space-regexp search-whitespace-regexp
+           isearch-lazy-highlight-word         isearch-word
            isearch-lazy-highlight-forward      isearch-forward)
       (unless (equal isearch-string "")
        (setq isearch-lazy-highlight-timer
@@ -2700,6 +2701,7 @@ Attempt to do the search exactly the way the pending Isearch would."
       (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
            (isearch-regexp isearch-lazy-highlight-regexp)
            (search-spaces-regexp isearch-lazy-highlight-space-regexp)
+           (isearch-word isearch-lazy-highlight-word)
            (search-invisible nil)      ; don't match invisible text
            (retry t)
            (success nil)