changeset 56868:bec9907cc422

* isearch.el (isearch-wrap-function) (isearch-push-state-function): New defvars. (isearch-pop-fun-state): New defsubst. (isearch-top-state): Call function saved in `isearch-pop-fun-state'. (isearch-push-state): Set the result of calling `isearch-push-state-function' to the `isearch-pop-fun-state' field. (isearch-cancel): Call function saved in `isearch-pop-fun-state' to restore the mode-specific starting point of terminated search. (isearch-abort): Call `isearch-cancel' instead of its duplicated code. (isearch-repeat): Call `isearch-wrap-function' if defined. (isearch-message-prefix): Don't add prefix "over" to the message for wrapped search if `isearch-wrap-function' is defined. (isearch-search): Call function saved in `isearch-pop-fun-state' to restore the mode-specific starting point of failed search.
author Juri Linkov <juri@jurta.org>
date Wed, 01 Sep 2004 20:32:13 +0000
parents 16f3ec82330a
children e0e96606bedd
files lisp/isearch.el
diffstat 1 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/isearch.el	Wed Sep 01 19:42:58 2004 +0000
+++ b/lisp/isearch.el	Wed Sep 01 20:32:13 2004 +0000
@@ -57,10 +57,6 @@
 ;; keep the behavior.  No point in forcing nonincremental search until
 ;; the last possible moment.
 
-;; TODO
-;; - Integrate the emacs 19 generalized command history.
-;; - Hooks and options for failed search.
-
 ;;; Code:
 
 
@@ -161,6 +157,15 @@
 (defvar isearch-mode-end-hook nil
   "Function(s) to call after terminating an incremental search.")
 
+(defvar isearch-wrap-function nil
+  "Function to call to wrap the search when search is failed.
+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
+to the search status stack.")
+
 ;; Search ring.
 
 (defvar search-ring nil
@@ -775,6 +780,9 @@
 (defsubst isearch-case-fold-search-state (frame)
   "Return the case-folding flag in FRAME."
   (aref frame 11))
+(defsubst isearch-pop-fun-state (frame)
+  "Return the function restoring the mode-specific isearch state in FRAME."
+  (aref frame 12))
 
 (defun isearch-top-state ()
   (let ((cmd (car isearch-cmds)))
@@ -789,6 +797,8 @@
 	  isearch-barrier (isearch-barrier-state cmd)
 	  isearch-within-brackets (isearch-within-brackets-state cmd)
 	  isearch-case-fold-search (isearch-case-fold-search-state cmd))
+    (if (functionp (isearch-pop-fun-state cmd))
+	(funcall (isearch-pop-fun-state cmd) cmd))
     (goto-char (isearch-point-state cmd))))
 
 (defun isearch-pop-state ()
@@ -801,7 +811,9 @@
 		      isearch-success isearch-forward isearch-other-end
 		      isearch-word
 		      isearch-invalid-regexp isearch-wrapped isearch-barrier
-		      isearch-within-brackets isearch-case-fold-search)
+		      isearch-within-brackets isearch-case-fold-search
+		      (if isearch-push-state-function
+			  (funcall isearch-push-state-function)))
 	      isearch-cmds)))
 
 
@@ -987,10 +999,13 @@
 (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)
-  (isearch-done t)
+  (isearch-done t)                      ; exit isearch
   (isearch-clean-overlays)
-  (signal 'quit nil))  ; and pass on quit signal
+  (signal 'quit nil))                   ; and pass on quit signal
 
 (defun isearch-abort ()
   "Abort incremental search mode if searching is successful, signaling quit.
@@ -1002,11 +1017,9 @@
   (if isearch-success
       ;; If search is successful, move back to starting point
       ;; and really do quit.
-      (progn (goto-char isearch-opoint)
-	     (setq isearch-success nil)
-	     (isearch-done t)   ; exit isearch
-	     (isearch-clean-overlays)
-	     (signal 'quit nil))  ; and pass on quit signal
+      (progn
+        (setq isearch-success nil)
+        (isearch-cancel))
     ;; If search is failing, or has an incomplete regexp,
     ;; rub out until it is once more successful.
     (while (or (not isearch-success) isearch-invalid-regexp)
@@ -1031,7 +1044,9 @@
 	;; If already have what to search for, repeat it.
 	(or isearch-success
 	    (progn
-	      (goto-char (if isearch-forward (point-min) (point-max)))
+	      (if isearch-wrap-function
+		  (funcall isearch-wrap-function)
+	        (goto-char (if isearch-forward (point-min) (point-max))))
 	      (setq isearch-wrapped t))))
     ;; C-s in reverse or C-r in forward, change direction.
     (setq isearch-forward (not isearch-forward)))
@@ -1881,6 +1896,7 @@
   (or isearch-success (setq ellipsis nil))
   (let ((m (concat (if isearch-success "" "failing ")
 		   (if (and isearch-wrapped
+			    (not isearch-wrap-function)
 			    (if isearch-forward
 				(> (point) isearch-opoint)
 			      (< (point) isearch-opoint)))
@@ -1977,6 +1993,8 @@
     ;; Ding if failed this time after succeeding last time.
     (and (isearch-success-state (car isearch-cmds))
 	 (ding))
+    (if (functionp (isearch-pop-fun-state (car isearch-cmds)))
+        (funcall (isearch-pop-fun-state (car isearch-cmds)) (car isearch-cmds)))
     (goto-char (isearch-point-state (car isearch-cmds)))))