Add arch tagline
[bpt/emacs.git] / lisp / isearch.el
index f246de1..7c5585d 100644 (file)
@@ -11,7 +11,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -159,10 +159,14 @@ command history."
 (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'
-is non-nil if the user quit the search.")
+is non-nil if the user quits the search.")
 
 (defvar isearch-mode-end-hook-quit nil
-  "Non-nil while running `isearch-mode-end-hook' if user quit the search.")
+  "Non-nil while running `isearch-mode-end-hook' if the user quits the search.")
+
+(defvar isearch-message-function nil
+  "Function to call to display the search prompt.
+If nil, use `isearch-message'.")
 
 (defvar isearch-wrap-function nil
   "Function to call to wrap the search when search is failed.
@@ -715,7 +719,9 @@ is treated as a regexp.  See \\[isearch-forward] for more info."
           (null executing-kbd-macro))
       (progn
         (if (not (input-pending-p))
-            (isearch-message))
+           (if isearch-message-function
+               (funcall isearch-message-function)
+             (isearch-message)))
         (if (and isearch-slow-terminal-mode
                  (not (or isearch-small-window
                           (pos-visible-in-window-p))))
@@ -819,7 +825,7 @@ NOPUSH is t and EDIT is t."
     (run-hooks 'isearch-mode-end-hook))
 
   ;; If there was movement, mark the starting position.
-  ;; Maybe should test difference between and set mark iff > threshold.
+  ;; Maybe should test difference between and set mark only if > threshold.
   (if (/= (point) isearch-opoint)
       (or (and transient-mark-mode mark-active)
          (progn
@@ -992,7 +998,7 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
               isearch-original-minibuffer-message-timeout)
              (isearch-original-minibuffer-message-timeout
               isearch-original-minibuffer-message-timeout)
-             )
+             old-point old-other-end)
 
          ;; Actually terminate isearching until editing is done.
          ;; This is so that the user can do anything without failure,
@@ -1001,6 +1007,10 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
              (isearch-done t t)
            (exit nil))                 ; was recursive editing
 
+         ;; Save old point and isearch-other-end before reading from minibuffer
+         ;; that can change their values.
+         (setq old-point (point) old-other-end isearch-other-end)
+
          (isearch-message) ;; for read-char
          (unwind-protect
              (let* (;; Why does following read-char echo?
@@ -1036,6 +1046,14 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
                      isearch-new-message
                      (mapconcat 'isearch-text-char-description
                                 isearch-new-string "")))
+
+           ;; Set point at the start (end) of old match if forward (backward),
+           ;; so after exiting minibuffer isearch resumes at the start (end)
+           ;; of this match and can find it again.
+           (if (and old-other-end (eq old-point (point))
+                    (eq isearch-forward isearch-new-forward))
+               (goto-char old-other-end))
+
            ;; Always resume isearching by restarting it.
            (isearch-mode isearch-forward
                          isearch-regexp
@@ -1069,6 +1087,7 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
 
        ;; Reinvoke the pending search.
        (isearch-search)
+       (isearch-push-state)
        (isearch-update)
        (if isearch-nonincremental
            (progn
@@ -1259,10 +1278,13 @@ If search string is empty, just beep."
       (ding)
     (setq isearch-string (substring isearch-string 0 (- (or arg 1)))
           isearch-message (mapconcat 'isearch-text-char-description
-                                     isearch-string "")
-          ;; Don't move cursor in reverse search.
-          isearch-yank-flag t))
-  (isearch-search-and-update))
+                                     isearch-string "")))
+  ;; Use the isearch-other-end as new starting point to be able
+  ;; to find the remaining part of the search string again.
+  (if isearch-other-end (goto-char isearch-other-end))
+  (isearch-search)
+  (isearch-push-state)
+  (isearch-update))
 
 (defun isearch-yank-string (string)
   "Pull STRING into search string."
@@ -1716,6 +1738,12 @@ Isearch mode."
                  (isearch-back-into-window (eq ab-bel 'above) isearch-point)
                (goto-char isearch-point)))
            (isearch-update))
+         ;; A mouse click on the isearch message starts editing the search string
+         ((and (eq (car-safe main-event) 'down-mouse-1)
+               (window-minibuffer-p (posn-window (event-start main-event))))
+          ;; Swallow the up-event.
+          (read-event)
+          (isearch-edit-string))
          (search-exit-option
           (let (window)
              (isearch-unread-key-sequence keylist)
@@ -2013,13 +2041,20 @@ Can be changed via `isearch-search-fun-function' for special needs."
                           (if isearch-forward (< pos2 pos1) (> pos2 pos1))))
              (setq pos1 pos2)
              (set-match-data match-data)))))
-    (if pos1
-       (goto-char pos1))
+    (when pos1
+      ;; When using multiple buffers isearch, switch to the new buffer here,
+      ;; because `save-excursion' above doesn't allow doing it inside funcall.
+      (if (and isearch-buffers-next-buffer-function
+              (buffer-live-p isearch-buffers-current-buffer))
+         (switch-to-buffer isearch-buffers-current-buffer))
+      (goto-char pos1))
     pos1))
 
 (defun isearch-search ()
   ;; Do the search with the current search string.
-  (isearch-message nil t)
+  (if isearch-message-function
+      (funcall isearch-message-function nil t)
+    (isearch-message nil t))
   (if (and (eq isearch-case-fold-search t) search-upper-case)
       (setq isearch-case-fold-search
            (isearch-no-upper-case-p isearch-string isearch-regexp)))
@@ -2305,7 +2340,7 @@ since they have special meaning in a regexp."
 ;;  - the direction of the current search is expected to be given by
 ;;    `isearch-forward';
 ;;  - the variable `isearch-error' is expected to be true
-;;    iff `isearch-string' is an invalid regexp.
+;;    only if `isearch-string' is an invalid regexp.
 
 (defvar isearch-lazy-highlight-overlays nil)
 (defvar isearch-lazy-highlight-wrapped nil)
@@ -2470,19 +2505,20 @@ Attempt to do the search exactly the way the pending isearch would."
                    (run-at-time lazy-highlight-interval nil
                                 'isearch-lazy-highlight-update)))))))))
 
-(defun isearch-resume (search regexp word forward message case-fold)
+(defun isearch-resume (string regexp word forward message case-fold)
   "Resume an incremental search.
-SEARCH is the string or regexp searched for.
+STRING is the string or regexp searched for.
 REGEXP non-nil means the resumed search was a regexp search.
 WORD non-nil means resume a word search.
 FORWARD non-nil means resume a forward search.
 MESSAGE is the echo-area message recorded for the search resumed.
 CASE-FOLD non-nil means the search was case-insensitive."
   (isearch-mode forward regexp nil nil word)
-  (setq isearch-string search
+  (setq isearch-string string
        isearch-message message
        isearch-case-fold-search case-fold)
-  (isearch-search))
+  (isearch-search)
+  (isearch-update))
 
 ;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675
 ;;; isearch.el ends here