(vc-svn-admin-directory): New var.
[bpt/emacs.git] / lisp / isearch.el
index e82f47f..a7d239a 100644 (file)
@@ -830,22 +830,11 @@ NOPUSH is t and EDIT is t."
 
 (defun isearch-update-ring (string &optional regexp)
   "Add STRING to the beginning of the search ring.
-REGEXP says which ring to use."
-  (if regexp
-      (when (or (null regexp-search-ring)
-               (not (string= string (car regexp-search-ring))))
-       (when history-delete-duplicates
-         (setq regexp-search-ring (delete string regexp-search-ring)))
-       (push string regexp-search-ring)
-       (when (> (length regexp-search-ring) regexp-search-ring-max)
-         (setcdr (nthcdr (1- search-ring-max) regexp-search-ring) nil)))
-    (when (or (null search-ring)
-             (not (string= string (car search-ring))))
-      (when history-delete-duplicates
-       (setq search-ring (delete string search-ring)))
-      (push string search-ring)
-      (when (> (length search-ring) search-ring-max)
-       (setcdr (nthcdr (1- search-ring-max) search-ring) nil)))))
+REGEXP if non-nil says use the regexp search ring."
+  (add-to-history
+   (if regexp 'regexp-search-ring 'search-ring)
+   string
+   (if regexp regexp-search-ring-max search-ring-max)))
 
 ;; Switching buffers should first terminate isearch-mode.
 ;; ;; For Emacs 19, the frame switch event is handled.
@@ -1304,23 +1293,18 @@ If search string is empty, just beep."
 (defun isearch-mouse-2 (click)
   "Handle mouse-2 in Isearch mode.
 For a click in the echo area, invoke `isearch-yank-x-selection'.
-Otherwise invoke whatever mouse-2 is bound to outside of Isearch."
+Otherwise invoke whatever the calling mouse-2 command sequence
+is bound to outside of Isearch."
   (interactive "e")
   (let* ((w (posn-window (event-start click)))
         (overriding-terminal-local-map nil)
-        (key (vector (event-basic-type click)))
-        ;; FIXME: `key-binding' should accept an event as argument
-        ;; and do all the overlay/text-properties lookup etc...
-        (binding (with-current-buffer
-                     (if (window-live-p w) (window-buffer w) (current-buffer))
-                   (key-binding key))))
+        (binding (key-binding (this-command-keys-vector) t)))
     (if (and (window-minibuffer-p w)
             (not (minibuffer-window-active-p w))) ; in echo area
        (isearch-yank-x-selection)
       (when (functionp binding)
        (call-interactively binding)))))
 
-
 (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
@@ -1368,7 +1352,8 @@ might return the position of the end of the line."
   "Pull rest of line from buffer into search string."
   (interactive)
   (isearch-yank-internal
-   (lambda () (line-end-position (if (eolp) 2 1)))))
+   (lambda () (let ((inhibit-field-text-motion t))
+               (line-end-position (if (eolp) 2 1))))))
 
 (defun isearch-search-and-update ()
   ;; Do the search and update the display.
@@ -1817,8 +1802,6 @@ Isearch mode."
    ((eq   char ?|)       (isearch-fallback t nil t)))
 
   ;; Append the char to the search string, update the message and re-search.
-  (if (char-table-p translation-table-for-input)
-      (setq char (or (aref translation-table-for-input char) char)))
   (isearch-process-search-string
    (char-to-string char)
    (if (>= char ?\200)
@@ -2003,6 +1986,36 @@ Can be changed via `isearch-search-fun-function' for special needs."
      (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.
+  (let ((func (isearch-search-fun))
+       (len (length string))
+       pos1 pos2)
+    (setq pos1 (save-excursion (funcall func string bound noerror)))
+    (if (and (char-table-p translation-table-for-input)
+            (> (string-bytes string) len))
+       (let (translated match-data)
+         (dotimes (i len)
+           (let ((x (aref translation-table-for-input (aref string i))))
+             (when x
+               (or translated (setq translated (copy-sequence string)))
+               (aset translated i x))))
+         (when translated
+           (save-match-data
+             (save-excursion
+               (if (setq pos2 (funcall func translated bound noerror))
+                   (setq match-data (match-data t)))))
+           (when (and pos2
+                      (or (not pos1)
+                          (if isearch-forward (< pos2 pos1) (> pos2 pos1))))
+             (setq pos1 pos2)
+             (set-match-data match-data)))))
+    (if pos1
+       (goto-char pos1))
+    pos1))
+
 (defun isearch-search ()
   ;; Do the search with the current search string.
   (isearch-message nil t)
@@ -2018,9 +2031,7 @@ Can be changed via `isearch-search-fun-function' for special needs."
        (setq isearch-error nil)
        (while retry
          (setq isearch-success
-               (funcall
-                (isearch-search-fun)
-                isearch-string nil t))
+               (isearch-search-string isearch-string nil t))
          ;; Clear RETRY unless we matched some invisible text
          ;; and we aren't supposed to do that.
          (if (or (eq search-invisible t)
@@ -2363,7 +2374,7 @@ Attempt to do the search exactly the way the pending isearch would."
        (isearch-regexp isearch-lazy-highlight-regexp)
        (search-spaces-regexp search-whitespace-regexp))
     (condition-case nil
-       (funcall (isearch-search-fun)
+       (isearch-search-string
                 isearch-lazy-highlight-last-string
                 (if isearch-forward
                     (min (or isearch-lazy-highlight-end-limit (point-max))