* isearch.el (isearch-update-post-hook): New hook.
[bpt/emacs.git] / lisp / isearch.el
index 0a86834..c44238e 100644 (file)
@@ -1,7 +1,8 @@
 ;;; isearch.el --- incremental search minor mode
 
-;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000,
-;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
+;;   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation, Inc.
 
 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
 ;; Maintainer: FSF
 
 
 (defcustom search-exit-option t
-  "*Non-nil means random control characters terminate incremental search."
+  "Non-nil means random control characters terminate incremental search."
   :type 'boolean
   :group 'isearch)
 
 (defcustom search-slow-window-lines 1
-  "*Number of lines in slow search display windows.
+  "Number of lines in slow search display windows.
 These are the short windows used during incremental search on slow terminals.
 Negative means put the slow search window at the top (normally it's at bottom)
 and the value is minus the number of lines."
@@ -83,14 +84,14 @@ and the value is minus the number of lines."
   :group 'isearch)
 
 (defcustom search-slow-speed 1200
-  "*Highest terminal speed at which to use \"slow\" style incremental search.
+  "Highest terminal speed at which to use \"slow\" style incremental search.
 This is the style where a one-line window is created to show the line
 that the search has reached."
   :type 'integer
   :group 'isearch)
 
 (defcustom search-upper-case 'not-yanks
-  "*If non-nil, upper case chars disable case fold searching.
+  "If non-nil, upper case chars disable case fold searching.
 That is, upper and lower case chars must match exactly.
 This applies no matter where the chars come from, but does not
 apply to chars in regexps that are prefixed with `\\'.
@@ -102,14 +103,14 @@ in Isearch mode is always downcased."
   :group 'isearch)
 
 (defcustom search-nonincremental-instead t
-  "*If non-nil, do a nonincremental search instead if exiting immediately.
+  "If non-nil, do a nonincremental search instead if exiting immediately.
 Actually, `isearch-edit-string' is called to let you enter the search
 string, and RET terminates editing and does a nonincremental search."
   :type 'boolean
   :group 'isearch)
 
-(defcustom search-whitespace-regexp "\\s-+"
-  "*If non-nil, regular expression to match a sequence of whitespace chars.
+(defcustom search-whitespace-regexp (purecopy "\\s-+")
+  "If non-nil, regular expression to match a sequence of whitespace chars.
 This applies to regular expression incremental search.
 When you put a space or spaces in the incremental regexp, it stands for
 this, unless it is inside of a regexp construct such as [...] or *, + or ?.
@@ -146,8 +147,8 @@ Ordinarily the text becomes invisible again at the end of the search."
   :group 'isearch)
 
 (defcustom isearch-resume-in-command-history nil
-  "*If non-nil, `isearch-resume' commands are added to the command history.
-This allows you to resume earlier isearch sessions through the
+  "If non-nil, `isearch-resume' commands are added to the command history.
+This allows you to resume earlier Isearch sessions through the
 command history."
   :type 'boolean
   :group 'isearch)
@@ -155,6 +156,9 @@ command history."
 (defvar isearch-mode-hook nil
   "Function(s) to call after starting up an incremental search.")
 
+(defvar isearch-update-post-hook nil
+  "Function(s) to call after isearch has found matches in the buffer.")
+
 (defvar isearch-mode-end-hook nil
   "Function(s) to call after terminating an incremental search.
 When these functions are called, `isearch-mode-end-hook-quit'
@@ -173,10 +177,10 @@ If nil, move point to the beginning of the buffer for a forward search,
 or to the end of the buffer for a backward search.")
 
 (defvar isearch-push-state-function nil
-  "Function to save a function restoring the mode-specific isearch state
+  "Function to save a function restoring the mode-specific Isearch state
 to the search status stack.")
 
-(defvar isearch-filter-predicate 'isearch-filter-invisible
+(defvar isearch-filter-predicate 'isearch-filter-visible
   "Predicate that filters the search hits that would normally be available.
 Search hits that dissatisfy the predicate are skipped.  The function
 has two arguments: the positions of start and end of text matched by
@@ -191,11 +195,11 @@ stopping at this match.")
   "List of regular expression search string sequences.")
 
 (defcustom search-ring-max 16
-  "*Maximum length of search ring before oldest elements are thrown away."
+  "Maximum length of search ring before oldest elements are thrown away."
   :type 'integer
   :group 'isearch)
 (defcustom regexp-search-ring-max 16
-  "*Maximum length of regexp search ring before oldest elements are thrown away."
+  "Maximum length of regexp search ring before oldest elements are thrown away."
   :type 'integer
   :group 'isearch)
 
@@ -207,7 +211,7 @@ It is nil if none yet.")
 It is nil if none yet.")
 
 (defcustom search-ring-update nil
-  "*Non-nil if advancing or retreating in the search ring should cause search.
+  "Non-nil if advancing or retreating in the search ring should cause search.
 Default value, nil, means edit the string instead."
   :type 'boolean
   :group 'isearch)
@@ -215,7 +219,7 @@ Default value, nil, means edit the string instead."
 ;;; isearch highlight customization.
 
 (defcustom search-highlight t
-  "*Non-nil means incremental search highlights the current match."
+  "Non-nil means incremental search highlights the current match."
   :type 'boolean
   :group 'isearch)
 
@@ -253,7 +257,7 @@ Default value, nil, means edit the string instead."
   :group 'isearch)
 
 (defcustom isearch-lazy-highlight t
-  "*Controls the lazy-highlighting during incremental search.
+  "Controls the lazy-highlighting during incremental search.
 When non-nil, all text in the buffer matching the current search
 string is highlighted lazily (see `lazy-highlight-initial-delay'
 and `lazy-highlight-interval')."
@@ -271,7 +275,7 @@ and `lazy-highlight-interval')."
   :group 'matching)
 
 (defcustom lazy-highlight-cleanup t
-  "*Controls whether to remove extra highlighting after a search.
+  "Controls whether to remove extra highlighting after a search.
 If this is nil, extra highlighting can be \"manually\" removed with
 \\[lazy-highlight-cleanup]."
   :type 'boolean
@@ -281,7 +285,7 @@ If this is nil, extra highlighting can be \"manually\" removed with
                                 "22.1")
 
 (defcustom lazy-highlight-initial-delay 0.25
-  "*Seconds to wait before beginning to lazily highlight all matches."
+  "Seconds to wait before beginning to lazily highlight all matches."
   :type 'number
   :group 'lazy-highlight)
 (define-obsolete-variable-alias 'isearch-lazy-highlight-initial-delay
@@ -289,7 +293,7 @@ If this is nil, extra highlighting can be \"manually\" removed with
                                 "22.1")
 
 (defcustom lazy-highlight-interval 0 ; 0.0625
-  "*Seconds between lazily highlighting successive matches."
+  "Seconds between lazily highlighting successive matches."
   :type 'number
   :group 'lazy-highlight)
 (define-obsolete-variable-alias 'isearch-lazy-highlight-interval
@@ -297,8 +301,8 @@ If this is nil, extra highlighting can be \"manually\" removed with
                                 "22.1")
 
 (defcustom lazy-highlight-max-at-a-time 20
-  "*Maximum matches to highlight at a time (for `lazy-highlight').
-Larger values may reduce isearch's responsiveness to user input;
+  "Maximum matches to highlight at a time (for `lazy-highlight').
+Larger values may reduce Isearch's responsiveness to user input;
 smaller values make matches highlight slowly.
 A value of nil means highlight all matches."
   :type '(choice (const :tag "All" nil)
@@ -321,7 +325,7 @@ A value of nil means highlight all matches."
   "Face for lazy highlighting of matches other than the current one."
   :group 'lazy-highlight
   :group 'basic-faces)
-(put 'isearch-lazy-highlight-face 'face-alias 'lazy-highlight)
+(define-obsolete-face-alias 'isearch-lazy-highlight-face 'lazy-highlight "22.1")
 (defvar lazy-highlight-face 'lazy-highlight)
 (define-obsolete-variable-alias 'isearch-lazy-highlight-face
                                 'lazy-highlight-face
@@ -330,8 +334,7 @@ A value of nil means highlight all matches."
 ;; Define isearch help map.
 
 (defvar isearch-help-map
-  (let ((i 0)
-       (map (make-sparse-keymap)))
+  (let ((map (make-sparse-keymap)))
     (define-key map [t] 'isearch-other-control-char)
     (define-key map (char-to-string help-char) 'isearch-help-for-help)
     (define-key map [help] 'isearch-help-for-help)
@@ -342,34 +345,34 @@ A value of nil means highlight all matches."
     (define-key map "m" 'isearch-describe-mode)
     (define-key map "q" 'help-quit)
     map)
-  "Keymap for characters following the Help key for isearch mode.")
+  "Keymap for characters following the Help key for Isearch mode.")
 
 (eval-when-compile (require 'help-macro))
 
 (make-help-screen isearch-help-for-help-internal
-  "Type a help option: [bkm] or ?"
+  (purecopy "Type a help option: [bkm] or ?")
   "You have typed %THIS-KEY%, the help character.  Type a Help option:
 \(Type \\<help-map>\\[help-quit] to exit the Help command.)
 
-b           Display all isearch key bindings.
-k KEYS      Display full documentation of isearch key sequence.
-m           Display documentation of isearch mode.
+b           Display all Isearch key bindings.
+k KEYS      Display full documentation of Isearch key sequence.
+m           Display documentation of Isearch mode.
 
 You can't type here other help keys available in the global help map,
-but outise of this help window when you type them in isearch mode,
-they exit isearch mode before displaying global help."
+but outside of this help window when you type them in Isearch mode,
+they exit Isearch mode before displaying global help."
   isearch-help-map)
 
 (defun isearch-help-for-help ()
-  "Display isearch help menu."
+  "Display Isearch help menu."
   (interactive)
   (let (same-window-buffer-names same-window-regexps)
     (isearch-help-for-help-internal))
   (isearch-update))
 
 (defun isearch-describe-bindings ()
-  "Show a list of all keys defined in isearch mode, and their definitions.
-This is like `describe-bindings', but displays only isearch keys."
+  "Show a list of all keys defined in Isearch mode, and their definitions.
+This is like `describe-bindings', but displays only Isearch keys."
   (interactive)
   (let (same-window-buffer-names same-window-regexps)
     (with-help-window "*Help*"
@@ -385,7 +388,7 @@ This is like `describe-bindings', but displays only isearch keys."
   (isearch-update))
 
 (defun isearch-describe-mode ()
-  "Display documentation of isearch mode."
+  "Display documentation of Isearch mode."
   (interactive)
   (let (same-window-buffer-names same-window-regexps)
     (describe-function 'isearch-forward))
@@ -397,8 +400,8 @@ This is like `describe-bindings', but displays only isearch keys."
 ;; Define isearch-mode keymap.
 
 (defvar isearch-mode-map
-  (let* ((i 0)
-        (map (make-keymap)))
+  (let ((i 0)
+       (map (make-keymap)))
     (or (char-table-p (nth 1 map))
        (error "The initialization of isearch-mode-map must be updated"))
     ;; Make all multibyte characters search for themselves.
@@ -460,7 +463,9 @@ This is like `describe-bindings', but displays only isearch keys."
     (define-key map "\M-\C-y" 'isearch-yank-char)
     (define-key map    "\C-y" 'isearch-yank-line)
 
-    (define-key map "\C-h" isearch-help-map)
+    (define-key map (char-to-string help-char) isearch-help-map)
+    (define-key map [help] isearch-help-map)
+    (define-key map [f1] isearch-help-map)
 
     (define-key map "\M-n" 'isearch-ring-advance)
     (define-key map "\M-p" 'isearch-ring-retreat)
@@ -510,11 +515,10 @@ This is like `describe-bindings', but displays only isearch keys."
     (define-key map "\M-\t" 'isearch-complete-edit)
     (define-key map "\C-s"  'isearch-forward-exit-minibuffer)
     (define-key map "\C-r"  'isearch-reverse-exit-minibuffer)
-    (define-key map "\C-w"  'isearch-edit-string-set-word)
     (define-key map "\C-f"  'isearch-yank-char-in-minibuffer)
     (define-key map [right] 'isearch-yank-char-in-minibuffer)
     map)
-  "Keymap for editing isearch strings in the minibuffer.")
+  "Keymap for editing Isearch strings in the minibuffer.")
 
 ;; Internal variables declared globally for byte-compiler.
 ;; These are all set with setq while isearching
@@ -545,9 +549,9 @@ Each set is a vector of the form:
 (defvar isearch-just-started nil)
 (defvar isearch-start-hscroll 0)       ; hscroll when starting the search.
 
-; case-fold-search while searching.
-;   either nil, t, or 'yes.  'yes means the same as t except that mixed
-;   case in the search string is ignored.
+;; case-fold-search while searching.
+;;   either nil, t, or 'yes.  'yes means the same as t except that mixed
+;;   case in the search string is ignored.
 (defvar isearch-case-fold-search nil)
 
 (defvar isearch-last-case-fold-search nil)
@@ -659,18 +663,19 @@ Type \\[isearch-occur] to run `occur' that shows\
 Type \\[isearch-highlight-regexp] to run `highlight-regexp'\
  that highlights the last search string.
 
-Type \\[isearch-describe-bindings] to display all isearch key bindings.
-Type \\[isearch-describe-key] to display documentation of isearch key.
-Type \\[isearch-describe-mode] to display documentation of isearch mode.
+Type \\[isearch-describe-bindings] to display all Isearch key bindings.
+Type \\[isearch-describe-key] to display documentation of Isearch key.
+Type \\[isearch-describe-mode] to display documentation of Isearch mode.
 
 If an input method is turned on in the current buffer, that input
-method is also active while you are typing characters to search.  To
-toggle the input method, type \\[isearch-toggle-input-method].  It
-also toggles the input method in the current buffer.
+method is also active while you are typing characters to search.
+To toggle the input method, type \\[isearch-toggle-input-method].  \
+It also toggles the input
+method in the current buffer.
 
-To use a different input method for searching, type
-\\[isearch-toggle-specified-input-method], and specify an input method
-you want to use.
+To use a different input method for searching, type \
+\\[isearch-toggle-specified-input-method],
+and specify an input method you want to use.
 
 The above keys, bound in `isearch-mode-map', are often controlled by
  options; do \\[apropos] on search-.* to find them.
@@ -736,7 +741,7 @@ as a regexp.  See the command `isearch-forward' for more information."
 
 
 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
-  "Start isearch minor mode.
+  "Start Isearch minor mode.
 It is called by the function `isearch-forward' and other related functions."
 
   ;; Initialize global vars.
@@ -798,11 +803,15 @@ It is called by the function `isearch-forward' and other related functions."
   (setq        isearch-mode " Isearch")  ;; forward? regexp?
   (force-mode-line-update)
 
+  (setq overriding-terminal-local-map isearch-mode-map)
+  (run-hooks 'isearch-mode-hook)
+
+  ;; Pushing the initial state used to be before running isearch-mode-hook,
+  ;; but a hook might set `isearch-push-state-function' used in
+  ;; `isearch-push-state' to save mode-specific initial state.  (Bug#4994)
   (isearch-push-state)
 
-  (setq overriding-terminal-local-map isearch-mode-map)
   (isearch-update)
-  (run-hooks 'isearch-mode-hook)
 
   (add-hook 'mouse-leave-buffer-hook 'isearch-done)
   (add-hook 'kbd-macro-termination-hook 'isearch-done)
@@ -864,7 +873,8 @@ It is called by the function `isearch-forward' and other related functions."
     (isearch-lazy-highlight-new-loop))
   ;; We must prevent the point moving to the end of composition when a
   ;; part of the composition has just been searched.
-  (setq disable-point-adjustment t))
+  (setq disable-point-adjustment t)
+  (run-hooks 'isearch-update-post-hook))
 
 (defun isearch-done (&optional nopush edit)
   "Exit Isearch mode.
@@ -955,7 +965,7 @@ REGEXP if non-nil says use the regexp search ring."
 ;;   ;; First terminate isearch-mode.
 ;;   (isearch-done)
 ;;   (isearch-clean-overlays)
-;;   (handle-switch-frame (car (cdr last-command-char))))
+;;   (handle-switch-frame (car (cdr last-command-event))))
 
 \f
 ;; The search status structure and stack.
@@ -994,7 +1004,7 @@ REGEXP if non-nil says use the regexp search ring."
   "Return the case-folding flag in FRAME."
   (aref frame 10))
 (defsubst isearch-pop-fun-state (frame)
-  "Return the function restoring the mode-specific isearch state in FRAME."
+  "Return the function restoring the mode-specific Isearch state in FRAME."
   (aref frame 11))
 
 (defun isearch-top-state ()
@@ -1194,15 +1204,6 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
      (isearch-abort)  ;; outside of let to restore outside global values
      )))
 
-;; Obsolete usage of `C-s M-e C-w'.  Remove after 23.1.
-(defvar isearch-new-word)
-(defun isearch-edit-string-set-word ()
-  "Do word search after exiting `isearch-edit-string'."
-  (interactive)
-  (message "This feature is obsolete since 23.1; use `M-s w' instead.")
-  (setq isearch-word t isearch-new-word t))
-
-
 (defun isearch-nonincremental-exit-minibuffer ()
   (interactive)
   (setq isearch-nonincremental t)
@@ -1221,10 +1222,12 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
 (defun isearch-cancel ()
   "Terminate the search and go back to the starting point."
   (interactive)
-  (if (functionp (isearch-pop-fun-state (car (last isearch-cmds))))
-      (funcall (isearch-pop-fun-state (car (last isearch-cmds)))
-               (car (last isearch-cmds))))
-  (goto-char isearch-opoint)
+  (if (and isearch-push-state-function isearch-cmds)
+      ;; For defined push-state function, restore the first state.
+      ;; This calls pop-state function and restores original point.
+      (let ((isearch-cmds (last isearch-cmds)))
+       (isearch-top-state))
+    (goto-char isearch-opoint))
   (isearch-done t)                      ; exit isearch
   (isearch-clean-overlays)
   (signal 'quit nil))                   ; and pass on quit signal
@@ -1395,7 +1398,12 @@ string.  NLINES has the same meaning as in `occur'."
   (interactive
    (list
     (cond
-     (isearch-word (concat "\\b" (regexp-quote isearch-string) "\\b"))
+     (isearch-word (concat "\\b" (replace-regexp-in-string
+                                 "\\W+" "\\W+"
+                                 (replace-regexp-in-string
+                                  "^\\W+\\|\\W+$" "" isearch-string)
+                                 nil t)
+                          "\\b"))
      (isearch-regexp isearch-string)
      (t (regexp-quote isearch-string)))
     (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
@@ -1405,7 +1413,6 @@ string.  NLINES has the same meaning as in `occur'."
        (search-upper-case nil))
     (occur regexp nlines)))
 
-(declare-function hi-lock-regexp-okay "hi-lock" (regexp))
 (declare-function hi-lock-read-face-name "hi-lock" ())
 
 (defun isearch-highlight-regexp ()
@@ -1475,14 +1482,10 @@ If search string is empty, just beep."
           (eq 'not-yanks search-upper-case))
       (setq string (downcase string)))
   (if isearch-regexp (setq string (regexp-quote string)))
-  (setq isearch-string (concat isearch-string string)
-       isearch-message
-       (concat isearch-message
-               (mapconcat 'isearch-text-char-description
-                          string ""))
-       ;; Don't move cursor in reverse search.
-       isearch-yank-flag t)
-  (isearch-search-and-update))
+  ;; Don't move cursor in reverse search.
+  (setq isearch-yank-flag t)
+  (isearch-process-search-string
+   string (mapconcat 'isearch-text-char-description string "")))
 
 (defun isearch-yank-kill ()
   "Pull string from kill ring into search string."
@@ -1512,10 +1515,10 @@ is bound to outside of Isearch."
 
 (defun isearch-yank-internal (jumpform)
   "Pull the text from point to the point reached by JUMPFORM.
-JUMPFORM is a lambda expression that takes no arguments and returns a
-buffer position, possibly having moved point to that position.  For
-example, it might move point forward by a word and return point, or it
-might return the position of the end of the line."
+JUMPFORM is a lambda expression that takes no arguments and returns
+a buffer position, possibly having moved point to that position.
+For example, it might move point forward by a word and return point,
+or it might return the position of the end of the line."
   (isearch-yank-string
    (save-excursion
      (and (not isearch-forward) isearch-other-end
@@ -1527,8 +1530,7 @@ might return the position of the end of the line."
   (interactive "p")
   (if (eobp)
       (insert
-       (save-excursion
-         (set-buffer (cadr (buffer-list)))
+       (with-current-buffer (cadr (buffer-list))
          (buffer-substring-no-properties
           (point) (progn (forward-char arg) (point)))))
     (forward-char arg)))
@@ -1619,7 +1621,7 @@ might return the position of the end of the line."
 (defun isearch-fallback (want-backslash &optional allow-invalid to-barrier)
   "Return point to previous successful match to allow regexp liberalization.
 \\<isearch-mode-map>
-Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by
+Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by \
 stopping at `isearch-barrier' as needed.
 
 Do nothing if a backslash is escaping the liberalizing character.
@@ -1708,9 +1710,10 @@ Scroll-bar or mode-line events are processed appropriately."
 ;; attempts this, we scroll the text back again.
 ;;
 ;; We implement this feature with a property called `isearch-scroll'.
-;; If a command's symbol has the value t for this property it is a
-;; scrolling command.  The feature needs to be enabled by setting the
-;; customizable variable `isearch-allow-scroll' to a non-nil value.
+;; If a command's symbol has the value t for this property or for the
+;; `scroll-command' property, it is a scrolling command.  The feature
+;; needs to be enabled by setting the customizable variable
+;; `isearch-allow-scroll' to a non-nil value.
 ;;
 ;; The universal argument commands (e.g. C-u) in simple.el are marked
 ;; as scrolling commands, and isearch.el has been amended to allow
@@ -1727,12 +1730,11 @@ Scroll-bar or mode-line events are processed appropriately."
 (if (fboundp 'w32-handle-scroll-bar-event)
     (put 'w32-handle-scroll-bar-event 'isearch-scroll t))
 
-;; Commands which scroll the window:
+;; Commands which scroll the window (some scroll commands
+;; already have the `scroll-command' property on them):
 (put 'recenter 'isearch-scroll t)
 (put 'recenter-top-bottom 'isearch-scroll t)
 (put 'reposition-window 'isearch-scroll t)
-(put 'scroll-up 'isearch-scroll t)
-(put 'scroll-down 'isearch-scroll t)
 
 ;; Commands which act on the other window
 (put 'list-buffers 'isearch-scroll t)
@@ -1754,7 +1756,10 @@ Scroll-bar or mode-line events are processed appropriately."
 (put 'digit-argument 'isearch-scroll t)
 
 (defcustom isearch-allow-scroll nil
-  "If non-nil, scrolling commands are allowed during incremental search."
+  "Whether scrolling is allowed during incremental search.
+If non-nil, scrolling commands can be used in Isearch mode.
+However, the current match will never scroll offscreen.
+If nil, scrolling commands will first cancel Isearch mode."
   :type 'boolean
   :group 'isearch)
 
@@ -1818,7 +1823,8 @@ Otherwise return nil."
   (let* ((overriding-terminal-local-map nil)
          (binding (key-binding key-seq)))
     (and binding (symbolp binding) (commandp binding)
-         (eq (get binding 'isearch-scroll) t)
+         (or (eq (get binding 'isearch-scroll) t)
+            (eq (get binding 'scroll-command) t))
          binding)))
 
 (defalias 'isearch-other-control-char 'isearch-other-meta-char)
@@ -1953,8 +1959,7 @@ Isearch mode."
                      (windowp window)
                      (or (> (minibuffer-depth) 0)
                          (not (window-minibuffer-p window))))
-                (save-excursion
-                  (set-buffer (window-buffer window))
+                (with-current-buffer (window-buffer window)
                   (isearch-done)
                   (isearch-clean-overlays))
               (isearch-done)
@@ -1989,7 +1994,7 @@ Isearch mode."
 (defun isearch-printing-char ()
   "Add this ordinary printing character to the search string and search."
   (interactive)
-  (let ((char last-command-char))
+  (let ((char last-command-event))
     (if (= char ?\S-\ )
        (setq char ?\s))
     (if current-input-method
@@ -2189,7 +2194,7 @@ If there is no completion possible, say so and continue searching."
 
 (defvar isearch-search-fun-function nil
   "Override `isearch-search-fun'.
-This function should return the search function for isearch to use.
+This function should return the search function for Isearch to use.
 It will call this function with three arguments
 as if it were `search-forward'.")
 
@@ -2200,32 +2205,42 @@ Can be changed via `isearch-search-fun-function' for special needs."
       (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
-      (if (not (eq (length isearch-string)
-                  (length (isearch-string-state (car isearch-cmds)))))
-         (if isearch-forward 'word-search-forward-lax 'word-search-backward-lax)
-       (if isearch-forward 'word-search-forward 'word-search-backward)))
+      ;; 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)))))
 
 (defun isearch-search-string (string bound noerror)
-  "Search for the first occurance of STRING or its translation.  If
-found, move point to the end of the occurance, update
-isearch-match-beg and isearch-match-end, and return point."
+  "Search for the first occurrence of STRING or its translation.
+If found, move point to the end of the occurrence,
+update the match data, and return point."
   (let* ((func (isearch-search-fun))
          (pos1 (save-excursion (funcall func string bound noerror)))
          pos2)
-    (when (and (char-table-p translation-table-for-input)
-               (multibyte-string-p string)
-               ;; Minor optimization.
-               (string-match-p "[^[:ascii:]]" string))
+    (when (and
+          ;; Avoid "obsolete" warnings for translation-table-for-input.
+          (with-no-warnings
+            (char-table-p translation-table-for-input))
+          (multibyte-string-p string)
+          ;; Minor optimization.
+          (string-match-p "[^[:ascii:]]" string))
       (let ((translated
              (apply 'string
                     (mapcar (lambda (c)
-                              (or (aref translation-table-for-input c) c))
+                              (or
+                              ;; Avoid "obsolete" warnings for
+                              ;; translation-table-for-input.
+                              (with-no-warnings
+                                (aref translation-table-for-input c))
+                              c))
                             string)))
             match-data)
         (when translated
@@ -2257,7 +2272,7 @@ isearch-match-beg and isearch-match-end, and return point."
            (isearch-no-upper-case-p isearch-string isearch-regexp)))
   (condition-case lossage
       (let ((inhibit-point-motion-hooks
-            (and (eq isearch-filter-predicate 'isearch-filter-invisible)
+            (and (eq isearch-filter-predicate 'isearch-filter-visible)
                  search-invisible))
            (inhibit-quit nil)
            (case-fold-search isearch-case-fold-search)
@@ -2451,10 +2466,11 @@ isearch-match-beg and isearch-match-end, and return point."
                  nil)
              (setq isearch-hidden t)))))))
 
-(defun isearch-filter-invisible (beg end)
-  "Default predicate to filter out invisible text.
-It filters search hits to those that are visible (at least partially),
-unless invisible text too can be searched."
+(defun isearch-filter-visible (beg end)
+  "Test whether the current search hit is visible at least partially.
+Return non-nil if the text from BEG to END is visible to Isearch as
+determined by `isearch-range-invisible' unless invisible text can be
+searched too when `search-invisible' is t."
   (or (eq search-invisible t)
       (not (isearch-range-invisible beg end))))
 
@@ -2491,8 +2507,8 @@ since they have special meaning in a regexp."
 
 (defun isearch-text-char-description (c)
   (cond
-   ((< c ?\s) (format "^%c" (+ c 64)))
-   ((= c ?\^?) "^?")
+   ((< c ?\s) (propertize (format "^%c" (+ c 64)) 'face 'escape-glyph))
+   ((= c ?\^?) (propertize "^?" 'face 'escape-glyph))
    (t (char-to-string c))))
 
 ;; General function to unread characters or events.
@@ -2623,7 +2639,7 @@ by other Emacs features."
 
 (defun isearch-lazy-highlight-search ()
   "Search ahead for the next or previous match, for lazy highlighting.
-Attempt to do the search exactly the way the pending isearch would."
+Attempt to do the search exactly the way the pending Isearch would."
   (condition-case nil
       (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
            (isearch-regexp isearch-lazy-highlight-regexp)