Fix X11 compilation failure.
[bpt/emacs.git] / lisp / isearch.el
index ab40678..7fd96df 100644 (file)
@@ -1,12 +1,13 @@
 ;;; isearch.el --- incremental search minor mode
 
 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
-;;   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;;   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ;;   Free Software Foundation, Inc.
 
 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
 ;; Maintainer: FSF
 ;; Keywords: matching
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
@@ -156,6 +157,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'
@@ -235,7 +239,7 @@ Default value, nil, means edit the string instead."
   "Face for highlighting Isearch matches."
   :group 'isearch
   :group 'basic-faces)
-(defvar isearch 'isearch)
+(defvar isearch-face 'isearch)
 
 (defface isearch-fail
   '((((class color) (min-colors 88) (background light))
@@ -271,30 +275,37 @@ and `lazy-highlight-interval')."
   :group 'isearch
   :group 'matching)
 
+(define-obsolete-variable-alias 'isearch-lazy-highlight-cleanup
+                                'lazy-highlight-cleanup
+                                "22.1")
+
 (defcustom lazy-highlight-cleanup t
   "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
   :group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-cleanup
-                                'lazy-highlight-cleanup
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-initial-delay
+                                'lazy-highlight-initial-delay
                                 "22.1")
 
 (defcustom lazy-highlight-initial-delay 0.25
   "Seconds to wait before beginning to lazily highlight all matches."
   :type 'number
   :group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-initial-delay
-                                'lazy-highlight-initial-delay
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-interval
+                                'lazy-highlight-interval
                                 "22.1")
 
 (defcustom lazy-highlight-interval 0 ; 0.0625
   "Seconds between lazily highlighting successive matches."
   :type 'number
   :group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-interval
-                                'lazy-highlight-interval
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-max-at-a-time
+                                'lazy-highlight-max-at-a-time
                                 "22.1")
 
 (defcustom lazy-highlight-max-at-a-time 20
@@ -305,9 +316,6 @@ A value of nil means highlight all matches."
   :type '(choice (const :tag "All" nil)
                 (integer :tag "Some"))
   :group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-max-at-a-time
-                                'lazy-highlight-max-at-a-time
-                                "22.1")
 
 (defface lazy-highlight
   '((((class color) (min-colors 88) (background light))
@@ -323,10 +331,10 @@ A value of nil means highlight all matches."
   :group 'lazy-highlight
   :group 'basic-faces)
 (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
                                 "22.1")
+(defvar lazy-highlight-face 'lazy-highlight)
 \f
 ;; Define isearch help map.
 
@@ -460,7 +468,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)
@@ -868,7 +878,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.
@@ -1233,9 +1244,9 @@ Use `isearch-exit' to quit without signaling."
   (interactive)
 ;;  (ding)  signal instead below, if quitting
   (discard-input)
-  (if isearch-success
-      ;; If search is successful, move back to starting point
-      ;; and really do quit.
+  (if (and isearch-success (not isearch-error))
+      ;; If search is successful and has no incomplete regexp,
+      ;; move back to starting point and really do quit.
       (progn
         (setq isearch-success nil)
         (isearch-cancel))
@@ -1476,14 +1487,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."
@@ -1538,14 +1545,18 @@ or it might return the position of the end of the line."
   (interactive "p")
   (isearch-yank-internal (lambda () (forward-char arg) (point))))
 
+(declare-function subword-forward "subword" (&optional arg))
 (defun isearch-yank-word-or-char ()
-  "Pull next character or word from buffer into search string."
+  "Pull next character, subword or word from buffer into search string.
+Subword is used when `subword-mode' is activated. "
   (interactive)
   (isearch-yank-internal
    (lambda ()
      (if (or (= (char-syntax (or (char-after) 0)) ?w)
              (= (char-syntax (or (char-after (1+ (point))) 0)) ?w))
-         (forward-word 1)
+        (if (and (boundp 'subword-mode) subword-mode)
+            (subword-forward 1)
+          (forward-word 1))
        (forward-char 1)) (point))))
 
 (defun isearch-yank-word ()
@@ -1708,9 +1719,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 +1739,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 +1765,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 +1832,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)
@@ -1979,12 +1994,6 @@ Isearch mode."
           (setq char (unibyte-char-to-multibyte char)))
       (isearch-process-search-char char))))
 
-(defun isearch-return-char ()
-  "Convert return into newline for incremental search."
-  (interactive)
-  (isearch-process-search-char ?\n))
-(make-obsolete 'isearch-return-char 'isearch-printing-char "19.7")
-
 (defun isearch-printing-char ()
   "Add this ordinary printing character to the search string and search."
   (interactive)
@@ -2526,7 +2535,7 @@ since they have special meaning in a regexp."
        (setq isearch-overlay (make-overlay beg end))
        ;; 1001 is higher than lazy's 1000 and ediff's 100+
        (overlay-put isearch-overlay 'priority 1001)
-       (overlay-put isearch-overlay 'face isearch))))
+       (overlay-put isearch-overlay 'face isearch-face))))
 
 (defun isearch-dehighlight ()
   (when isearch-overlay
@@ -2571,6 +2580,8 @@ 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-forward nil)
+(defvar isearch-lazy-highlight-error nil)
 
 (defun lazy-highlight-cleanup (&optional force)
   "Stop lazy highlighting and remove extra highlighting from current buffer.
@@ -2610,9 +2621,15 @@ by other Emacs features."
                  (not (= (window-start)
                          isearch-lazy-highlight-window-start))
                  (not (= (window-end)   ; Window may have been split/joined.
-                         isearch-lazy-highlight-window-end))))
+                        isearch-lazy-highlight-window-end))
+                (not (eq isearch-forward
+                         isearch-lazy-highlight-forward))
+                ;; In case we are recovering from an error.
+                (not (equal isearch-error
+                            isearch-lazy-highlight-error))))
     ;; something important did indeed change
     (lazy-highlight-cleanup t) ;kill old loop & remove overlays
+    (setq isearch-lazy-highlight-error isearch-error)
     (when (not isearch-error)
       (setq isearch-lazy-highlight-start-limit beg
            isearch-lazy-highlight-end-limit end)
@@ -2625,7 +2642,8 @@ by other Emacs features."
            isearch-lazy-highlight-case-fold-search isearch-case-fold-search
            isearch-lazy-highlight-regexp       isearch-regexp
             isearch-lazy-highlight-wrapped      nil
-           isearch-lazy-highlight-space-regexp search-whitespace-regexp)
+           isearch-lazy-highlight-space-regexp search-whitespace-regexp
+           isearch-lazy-highlight-forward      isearch-forward)
       (unless (equal isearch-string "")
        (setq isearch-lazy-highlight-timer
              (run-with-idle-timer lazy-highlight-initial-delay nil
@@ -2641,7 +2659,8 @@ Attempt to do the search exactly the way the pending Isearch would."
            (search-invisible nil)      ; don't match invisible text
            (retry t)
            (success nil)
-           (bound (if isearch-forward
+           (isearch-forward isearch-lazy-highlight-forward)
+           (bound (if isearch-lazy-highlight-forward
                       (min (or isearch-lazy-highlight-end-limit (point-max))
                            (if isearch-lazy-highlight-wrapped
                                isearch-lazy-highlight-start
@@ -2657,6 +2676,8 @@ Attempt to do the search exactly the way the pending Isearch would."
          ;; Clear RETRY unless the search predicate says
          ;; to skip this search hit.
          (if (or (not success)
+                 (= (point) bound) ; like (bobp) (eobp) in `isearch-search'.
+                 (= (match-beginning 0) (match-end 0))
                  (funcall isearch-filter-predicate
                           (match-beginning 0) (match-end 0)))
              (setq retry nil)))
@@ -2675,7 +2696,7 @@ Attempt to do the search exactly the way the pending Isearch would."
            (select-window isearch-lazy-highlight-window))
        (save-excursion
          (save-match-data
-           (goto-char (if isearch-forward
+           (goto-char (if isearch-lazy-highlight-forward
                           isearch-lazy-highlight-end
                         isearch-lazy-highlight-start))
            (while looping
@@ -2688,7 +2709,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                    (let ((mb (match-beginning 0))
                          (me (match-end 0)))
                      (if (= mb me)     ;zero-length match
-                         (if isearch-forward
+                         (if isearch-lazy-highlight-forward
                              (if (= mb (if isearch-lazy-highlight-wrapped
                                            isearch-lazy-highlight-start
                                          (window-end)))
@@ -2708,7 +2729,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                          (overlay-put ov 'priority 1000)
                          (overlay-put ov 'face lazy-highlight-face)
                          (overlay-put ov 'window (selected-window))))
-                     (if isearch-forward
+                     (if isearch-lazy-highlight-forward
                          (setq isearch-lazy-highlight-end (point))
                        (setq isearch-lazy-highlight-start (point)))))
 
@@ -2718,7 +2739,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                        (setq looping nil
                              nomore  t)
                      (setq isearch-lazy-highlight-wrapped t)
-                     (if isearch-forward
+                     (if isearch-lazy-highlight-forward
                          (progn
                            (setq isearch-lazy-highlight-end (window-start))
                            (goto-char (max (or isearch-lazy-highlight-start-limit (point-min))
@@ -2746,5 +2767,4 @@ CASE-FOLD non-nil means the search was case-insensitive."
   (isearch-search)
   (isearch-update))
 
-;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675
 ;;; isearch.el ends here