57 |
;; keep the behavior. No point in forcing nonincremental search until |
;; keep the behavior. No point in forcing nonincremental search until |
58 |
;; the last possible moment. |
;; the last possible moment. |
59 |
|
|
|
;; TODO |
|
|
;; - Integrate the emacs 19 generalized command history. |
|
|
;; - Hooks and options for failed search. |
|
|
|
|
60 |
;;; Code: |
;;; Code: |
61 |
|
|
62 |
|
|
157 |
(defvar isearch-mode-end-hook nil |
(defvar isearch-mode-end-hook nil |
158 |
"Function(s) to call after terminating an incremental search.") |
"Function(s) to call after terminating an incremental search.") |
159 |
|
|
160 |
|
(defvar isearch-wrap-function nil |
161 |
|
"Function to call to wrap the search when search is failed. |
162 |
|
If nil, move point to the beginning of the buffer for a forward search, |
163 |
|
or to the end of the buffer for a backward search.") |
164 |
|
|
165 |
|
(defvar isearch-push-state-function nil |
166 |
|
"Function to save a function restoring the mode-specific isearch state |
167 |
|
to the search status stack.") |
168 |
|
|
169 |
;; Search ring. |
;; Search ring. |
170 |
|
|
171 |
(defvar search-ring nil |
(defvar search-ring nil |
780 |
(defsubst isearch-case-fold-search-state (frame) |
(defsubst isearch-case-fold-search-state (frame) |
781 |
"Return the case-folding flag in FRAME." |
"Return the case-folding flag in FRAME." |
782 |
(aref frame 11)) |
(aref frame 11)) |
783 |
|
(defsubst isearch-pop-fun-state (frame) |
784 |
|
"Return the function restoring the mode-specific isearch state in FRAME." |
785 |
|
(aref frame 12)) |
786 |
|
|
787 |
(defun isearch-top-state () |
(defun isearch-top-state () |
788 |
(let ((cmd (car isearch-cmds))) |
(let ((cmd (car isearch-cmds))) |
797 |
isearch-barrier (isearch-barrier-state cmd) |
isearch-barrier (isearch-barrier-state cmd) |
798 |
isearch-within-brackets (isearch-within-brackets-state cmd) |
isearch-within-brackets (isearch-within-brackets-state cmd) |
799 |
isearch-case-fold-search (isearch-case-fold-search-state cmd)) |
isearch-case-fold-search (isearch-case-fold-search-state cmd)) |
800 |
|
(if (functionp (isearch-pop-fun-state cmd)) |
801 |
|
(funcall (isearch-pop-fun-state cmd) cmd)) |
802 |
(goto-char (isearch-point-state cmd)))) |
(goto-char (isearch-point-state cmd)))) |
803 |
|
|
804 |
(defun isearch-pop-state () |
(defun isearch-pop-state () |
811 |
isearch-success isearch-forward isearch-other-end |
isearch-success isearch-forward isearch-other-end |
812 |
isearch-word |
isearch-word |
813 |
isearch-invalid-regexp isearch-wrapped isearch-barrier |
isearch-invalid-regexp isearch-wrapped isearch-barrier |
814 |
isearch-within-brackets isearch-case-fold-search) |
isearch-within-brackets isearch-case-fold-search |
815 |
|
(if isearch-push-state-function |
816 |
|
(funcall isearch-push-state-function))) |
817 |
isearch-cmds))) |
isearch-cmds))) |
818 |
|
|
819 |
|
|
999 |
(defun isearch-cancel () |
(defun isearch-cancel () |
1000 |
"Terminate the search and go back to the starting point." |
"Terminate the search and go back to the starting point." |
1001 |
(interactive) |
(interactive) |
1002 |
|
(if (functionp (isearch-pop-fun-state (car (last isearch-cmds)))) |
1003 |
|
(funcall (isearch-pop-fun-state (car (last isearch-cmds))) |
1004 |
|
(car (last isearch-cmds)))) |
1005 |
(goto-char isearch-opoint) |
(goto-char isearch-opoint) |
1006 |
(isearch-done t) |
(isearch-done t) ; exit isearch |
1007 |
(isearch-clean-overlays) |
(isearch-clean-overlays) |
1008 |
(signal 'quit nil)) ; and pass on quit signal |
(signal 'quit nil)) ; and pass on quit signal |
1009 |
|
|
1010 |
(defun isearch-abort () |
(defun isearch-abort () |
1011 |
"Abort incremental search mode if searching is successful, signaling quit. |
"Abort incremental search mode if searching is successful, signaling quit. |
1017 |
(if isearch-success |
(if isearch-success |
1018 |
;; If search is successful, move back to starting point |
;; If search is successful, move back to starting point |
1019 |
;; and really do quit. |
;; and really do quit. |
1020 |
(progn (goto-char isearch-opoint) |
(progn |
1021 |
(setq isearch-success nil) |
(setq isearch-success nil) |
1022 |
(isearch-done t) ; exit isearch |
(isearch-cancel)) |
|
(isearch-clean-overlays) |
|
|
(signal 'quit nil)) ; and pass on quit signal |
|
1023 |
;; If search is failing, or has an incomplete regexp, |
;; If search is failing, or has an incomplete regexp, |
1024 |
;; rub out until it is once more successful. |
;; rub out until it is once more successful. |
1025 |
(while (or (not isearch-success) isearch-invalid-regexp) |
(while (or (not isearch-success) isearch-invalid-regexp) |
1044 |
;; If already have what to search for, repeat it. |
;; If already have what to search for, repeat it. |
1045 |
(or isearch-success |
(or isearch-success |
1046 |
(progn |
(progn |
1047 |
(goto-char (if isearch-forward (point-min) (point-max))) |
(if isearch-wrap-function |
1048 |
|
(funcall isearch-wrap-function) |
1049 |
|
(goto-char (if isearch-forward (point-min) (point-max)))) |
1050 |
(setq isearch-wrapped t)))) |
(setq isearch-wrapped t)))) |
1051 |
;; C-s in reverse or C-r in forward, change direction. |
;; C-s in reverse or C-r in forward, change direction. |
1052 |
(setq isearch-forward (not isearch-forward))) |
(setq isearch-forward (not isearch-forward))) |
1896 |
(or isearch-success (setq ellipsis nil)) |
(or isearch-success (setq ellipsis nil)) |
1897 |
(let ((m (concat (if isearch-success "" "failing ") |
(let ((m (concat (if isearch-success "" "failing ") |
1898 |
(if (and isearch-wrapped |
(if (and isearch-wrapped |
1899 |
|
(not isearch-wrap-function) |
1900 |
(if isearch-forward |
(if isearch-forward |
1901 |
(> (point) isearch-opoint) |
(> (point) isearch-opoint) |
1902 |
(< (point) isearch-opoint))) |
(< (point) isearch-opoint))) |
1993 |
;; Ding if failed this time after succeeding last time. |
;; Ding if failed this time after succeeding last time. |
1994 |
(and (isearch-success-state (car isearch-cmds)) |
(and (isearch-success-state (car isearch-cmds)) |
1995 |
(ding)) |
(ding)) |
1996 |
|
(if (functionp (isearch-pop-fun-state (car isearch-cmds))) |
1997 |
|
(funcall (isearch-pop-fun-state (car isearch-cmds)) (car isearch-cmds))) |
1998 |
(goto-char (isearch-point-state (car isearch-cmds))))) |
(goto-char (isearch-point-state (car isearch-cmds))))) |
1999 |
|
|
2000 |
|
|