annotate lisp/=isearch-old.el @ 828:4b56424868f6

*** empty log message ***
author Eric S. Raymond <esr@snark.thyrsus.com>
date Tue, 21 Jul 1992 07:57:59 +0000
parents 4f28bd14272c
children 20674ae6bf52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 347
diff changeset
1 ;;; isearch.el --- incremental search commands
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 347
diff changeset
2
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
3 ;; Maintainer: FSF
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
4 ;; Last-Modified: 30 Jun 1992
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
5
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; any later version.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
24 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
25
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 (defvar search-last-string "" "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 Last string search for by a non-regexp search command.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 This does not include direct calls to the primitive search functions,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 and does not include searches that are aborted.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (defvar search-last-regexp "" "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 Last string searched for by a regexp search command.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 This does not include direct calls to the primitive search functions,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 and does not include searches that are aborted.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (defconst search-repeat-char ?\C-s "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 *Character to repeat incremental search forwards.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (defconst search-reverse-char ?\C-r "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 *Character to repeat incremental search backwards.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (defconst search-exit-char ?\C-m "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 *Character to exit incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (defconst search-delete-char ?\177 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 *Character to delete from incremental search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (defconst search-quote-char ?\C-q "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 *Character to quote special characters for incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (defconst search-yank-word-char ?\C-w "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 *Character to pull next word from buffer into search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 (defconst search-yank-line-char ?\C-y "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 *Character to pull rest of line from buffer into search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 (defconst search-ring-advance-char ?\M-n "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 *Character to pull next (more recent) search string from the ring of same.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (defconst search-ring-retreat-char ?\M-p "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 *Character to pull previous (older) search string from the ring of same.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (defconst search-exit-option t "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 *Non-nil means random control characters terminate incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (defvar search-slow-window-lines 1 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 *Number of lines in slow search display windows.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 These are the short windows used during incremental search on slow terminals.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 Negative means put the slow search window at the top (normally it's at bottom)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 and the value is minus the number of lines.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 (defvar search-slow-speed 1200 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 *Highest terminal speed at which to use \"slow\" style incremental search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 This is the style where a one-line window is created to show the line
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 that the search has reached.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 (defconst search-upper-case t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 "*Non-nil means an upper-case letter as search input means case-sensitive.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 Any upper-case letter given explicitly as input to the incremental search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 has the effect of turning off `case-fold-search' for the rest of this search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 Deleting the letter from the search string cancels the effect.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (fset 'search-forward-regexp 're-search-forward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (fset 'search-backward-regexp 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (defvar search-ring nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 "List of recent non-regexp incremental searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 Each element is a cons cell of the form (STRING . UPPERCASE-FLAG).")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (defvar regexp-search-ring nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 "List of recent regexp incremental searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 Each element is a cons cell of the form (STRING . UPPERCASE-FLAG).")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (defconst search-ring-max 16
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 "*Maximum length of search ring before oldest elements are thrown away.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (defvar search-ring-yank-pointer nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 "The tail of the search ring whose car is the last thing searched for.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (defvar regexp-search-ring-yank-pointer nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 "The tail of the regular expression search ring whose car is the last
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 thing searched for.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (defun isearch-forward ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 "Do incremental search forward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 As you type characters, they add to the search string and are found.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 Type Delete to cancel characters from end of search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 Type RET to exit, leaving point at location found.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 Type C-s to search again forward, C-r to search again backward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 Type C-w to yank word from buffer onto end of search string and search for it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 Type C-y to yank rest of line onto end of search string, etc.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 Type C-q to quote control character to search for it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 Other control and meta characters terminate the search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 and are then executed normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 The above special characters are mostly controlled by parameters;
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 do M-x apropos on search-.*-char to find them.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 C-g while searching or when search has failed
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 cancels input back to what has been found successfully.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 C-g when search is successful aborts and moves point to starting point."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (isearch t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (define-key global-map "\C-s" 'isearch-forward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (defun isearch-forward-regexp ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 "Do incremental search forward for regular expression.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 Like ordinary incremental search except that your input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 is treated as a regexp. See \\[isearch-forward] for more info."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (isearch t t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (define-key esc-map "\C-s" 'isearch-forward-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (defun isearch-backward ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 "Do incremental search backward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 See \\[isearch-forward] for more information."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (isearch nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (define-key global-map "\C-r" 'isearch-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (defun isearch-backward-regexp ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 "Do incremental search backward for regular expression.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 Like ordinary incremental search except that your input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 is treated as a regexp. See \\[isearch-forward] for more info."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (isearch nil t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (define-key esc-map "\C-r" 'isearch-backward-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 ;; This function does all the work of incremental search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 ;; The functions attached to ^R and ^S are trivial,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 ;; merely calling this one, but they are always loaded by default
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 ;; whereas this file can optionally be autoloadable.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 ;; This is the only entry point in this file.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 ;; OP-FUN is a function to be called after each input character is processed.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 ;; (It is not called after characters that exit the search.)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 (defun isearch (forward &optional regexp op-fun)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (let ((search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (search-message "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 ;; List of previous states during this search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (history nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 ;; t means search is currently successful.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (success t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 ;; Set once the search has wrapped around the end of the buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (wrapped nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 ;; Nominal starting point for searching
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 ;; Usually this is the same as the opoint,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 ;; but it is changed by wrapping
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 ;; and also by repeating the search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (barrier (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 ;; Set temporarily when adding a character to a regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 ;; enables it to match more rather than fewer places in the buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 liberalized
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 ;; Set temporarily by yanking text into the search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 yank-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (invalid-regexp nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 ;; non-nil means an explicit uppercase letter seen in the input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (uppercase-flag nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 ;; Non-nil means start using a small window
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
174 ;; if the search moves outside what is currently on the frame.
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (slow-terminal-mode (and (<= baud-rate search-slow-speed)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (> (window-height)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (* 4 search-slow-window-lines))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 ;; t means a small window is currently in use.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (small-window nil) ;if t, using a small window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 ;; These variables preserve information from the small window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 ;; through exit from the save-window-excursion.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (found-point nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (found-start nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 ;; Point is at one end of the last match.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 ;; This variable records the other end of that match.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (other-end nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 ;; Value of point at start of search,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 ;; for moving the cursor back on quitting.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (opoint (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (inhibit-quit t) ;Prevent ^G from quitting, so we can read it.
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
191 ;; The frame we're working on; if this changes, we exit isearch.
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
192 (frame (if (fboundp 'selected-frame) (selected-frame))))
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (save-window-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (catch 'search-done
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (while t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (or (and (numberp unread-command-char) (>= unread-command-char 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (or (input-pending-p)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 (isearch-message))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (if (and slow-terminal-mode
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (not (or small-window (pos-visible-in-window-p))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (setq small-window t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (setq found-point (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (move-to-window-line 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (let ((window-min-height 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (split-window nil (if (< search-slow-window-lines 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (1+ (- search-slow-window-lines))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (- (window-height)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (1+ search-slow-window-lines)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (if (< search-slow-window-lines 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (progn (vertical-motion (- 1 search-slow-window-lines))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (set-window-start (next-window) (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (set-window-hscroll (next-window)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (window-hscroll))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (set-window-hscroll (selected-window) 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (other-window 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (goto-char found-point)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (let ((char (if quit-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 ?\C-g
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (read-event))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (setq quit-flag nil liberalized nil yank-flag nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (cond ((and (or (not (integerp char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (and (>= char 128)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (not (= char search-ring-advance-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (not (= char search-ring-retreat-char))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 search-exit-option)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
233 ;; If the user switches to a different frame, exit.
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
234 ((not (eq frame last-event-frame))
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 ((eq char search-exit-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 ;; RET means exit search normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 ;; Except, if first thing typed, it means do nonincremental
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (if (= 0 (length search-string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (nonincremental-search forward regexp))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 ((= char ?\C-g)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 ;; ^G means the user tried to quit.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (ding)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (discard-input)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 ;; If search is successful, move back to starting point
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 ;; and really do quit.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (progn (goto-char opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (signal 'quit nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 ;; If search is failing, rub out until it is once more
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 ;; successful.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (while (not success) (isearch-pop))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 ((or (eq char search-repeat-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (eq char search-reverse-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (if (eq forward (eq char search-repeat-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 ;; C-s in forward or C-r in reverse.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (if (equal search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 ;; If search string is empty, use last one.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (isearch-get-string-from-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 ;; If already have what to search for, repeat it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (or success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (progn (goto-char (if forward (point-min) (point-max)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (setq wrapped t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 ;; C-s in reverse or C-r in forward, change direction.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (setq forward (not forward)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (setq barrier (point)) ; For subsequent \| if regexp.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (setq success t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (or (equal search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 ;; If repeating a search that found an empty string,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 ;; ensure we advance. Test history to make sure we
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 ;; actually have done a search already; otherwise,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 ;; the match data will be random.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (if (and (cdr history)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (= (match-end 0) (match-beginning 0)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (forward-char (if forward 1 -1)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (isearch-search)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (isearch-push-state))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 ((= char search-delete-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 ;; Rubout means discard last input item and move point
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 ;; back. If buffer is empty, just beep.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (if (null (cdr history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (ding)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (isearch-pop)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 ((= char search-ring-advance-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (isearch-pop)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 (let ((length (length regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (setq regexp-search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (nthcdr (% (+ 1 (- length (length regexp-search-ring-yank-pointer)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 regexp-search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (isearch-get-string-from-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (let ((length (length search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (setq search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (nthcdr (% (+ 1 (- length (length search-ring-yank-pointer)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (isearch-get-string-from-ring))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (isearch-search))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 ((= char search-ring-retreat-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (isearch-pop)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (let ((length (length regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 (setq regexp-search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (nthcdr (% (+ (- length (length regexp-search-ring-yank-pointer))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (1- length))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 regexp-search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 (isearch-get-string-from-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (let ((length (length search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (setq search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (nthcdr (% (+ (- length (length search-ring-yank-pointer))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (1- length))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (isearch-get-string-from-ring))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 (isearch-search))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 (cond ((or (eq char search-yank-word-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (eq char search-yank-line-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 ;; ^W means gobble next word from buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 ;; ^Y means gobble rest of line from buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (let ((word (save-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (and (not forward) other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (goto-char other-end))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (buffer-substring
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (point)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 (save-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (if (eq char search-yank-line-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 (end-of-line)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (forward-word 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (point))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (setq word (regexp-quote word)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (setq search-string (concat search-string word)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (concat search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (mapconcat 'text-char-description
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 word ""))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 ;; Don't move cursor in reverse search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 yank-flag t)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 ;; Any other control char =>
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 ;; unread it and exit the search normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 ((and search-exit-option
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (/= char search-quote-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (or (>= char ?\177)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (and (< char ? )
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (/= char ?\t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (/= char ?\n))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 ;; Any other character => add it to the
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 ;; search string and search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (cond ((= char search-quote-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (setq char (read-quoted-char
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (isearch-message t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 ((= char ?\r)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 ;; RET translates to newline.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (setq char ?\n)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (setq search-string (concat search-string
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (char-to-string char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 search-message (concat search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (text-char-description char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 uppercase-flag (or uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (not (= char (downcase char)))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (if (and (not success)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 ;; unsuccessful regexp search may become
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 ;; successful by addition of characters which
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 ;; make search-string valid
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (not regexp))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 ;; Check for chars that can make a regexp more liberal.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 ;; They can make a regexp match sooner
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 ;; or make it succeed instead of failing.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 ;; So go back to place last successful search started
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 ;; or to the last ^S/^R (barrier), whichever is nearer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (and regexp history
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 (cond ((and (memq char '(?* ??))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 ;; Don't treat *, ? as special
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 ;; within [] or after \.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 (not (nth 6 (car history))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 (setq liberalized t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 ;; This used to use element 2
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 ;; in a reverse search, but it seems that 5
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 ;; (which is the end of the old match)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 ;; is better in that case too.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 (let ((cs (nth 5 ; old other-end.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (car (cdr history)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 ;; (car history) is after last search;
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 ;; (car (cdr history)) is from before it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 (setq cs (or cs barrier))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (goto-char
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (if forward
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (max cs barrier)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 (min cs barrier)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 ((eq char ?\|)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 (setq liberalized t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (goto-char barrier))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 ;; Turn off case-sensitivity if string requests it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (let ((case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 (and case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (not (and uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 search-upper-case)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 ;; In reverse search, adding stuff at
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 ;; the end may cause zero or many more chars to be
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 ;; matched, in the string following point.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 ;; Allow all those possibilities without moving point as
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 ;; long as the match does not extend past search origin.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 (if (and (not forward) (not liberalized)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (condition-case ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (looking-at (if regexp search-string
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (regexp-quote search-string)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 (error nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (or yank-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 ;; Used to have (min opoint barrier)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 ;; instead of barrier.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 ;; This lost when wrapping.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (<= (match-end 0) barrier)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 (setq success t invalid-regexp nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 other-end (match-end 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 ;; Not regexp, not reverse, or no match at point.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 (if (and other-end (not liberalized))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 (goto-char (if forward other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 ;; Used to have opoint inside the min.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 ;; This lost when wrapping.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 (min barrier (1+ other-end)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (isearch-search))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (isearch-push-state))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (if op-fun (funcall op-fun))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 (setq found-start (window-start (selected-window)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (setq found-point (point)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (if (> (length search-string) 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 (if (and regexp (not (member search-string regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (setq regexp-search-ring (cons (cons search-string uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 regexp-search-ring-yank-pointer regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 (if (> (length regexp-search-ring) regexp-search-ring-max)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring) nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 (if (not (member search-string search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (setq search-ring (cons (cons search-string uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 search-ring-yank-pointer search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (if (> (length search-ring) search-ring-max)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 ;; If we displayed a single-line window, set point in this window.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 (if small-window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 (goto-char found-point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 ;; If there was movement, mark the starting position.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 ;; Maybe should test difference between and set mark iff > threshold.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (if (/= (point) opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 (push-mark opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (message ""))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (or small-window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 ;; Exiting the save-window-excursion clobbers this; restore it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 (set-window-start (selected-window) found-start t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 (defun isearch-message (&optional c-q-hack ellipsis)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 ;; If about to search, and previous search regexp was invalid,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 ;; check that it still is. If it is valid now,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 ;; let the message we display while searching say that it is valid.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (and invalid-regexp ellipsis
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 (condition-case ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 (progn (re-search-forward search-string (point) t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 (setq invalid-regexp nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 (error nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 ;; If currently failing, display no ellipsis.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 (or success (setq ellipsis nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 (let ((m (concat (if success "" "failing ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 (if wrapped "wrapped ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 (if (or (not case-fold-search)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (and uppercase-flag search-upper-case))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 "case-sensitive ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (if regexp "regexp " "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 "I-search"
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (if forward ": " " backward: ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (if c-q-hack "^Q" "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 (if invalid-regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (concat " [" invalid-regexp "]")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 ""))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 (aset m 0 (upcase (aref m 0)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 (let ((cursor-in-echo-area ellipsis))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 (if c-q-hack m (message "%s" m)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 ;; Get the search string from the "front" of the ring of previous searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (defun isearch-get-string-from-ring ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (let ((elt (car (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 (or regexp-search-ring-yank-pointer regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (or search-ring-yank-pointer search-ring)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 ;; ELT describes the most recent search or where we have rotated the ring.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (if elt
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (setq search-string (car elt)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 uppercase-flag (cdr elt))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 (setq search-string "" uppercase-flag nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 ;; Let's give this one the benefit of the doubt.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (setq invalid-regexp nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (setq search-message (mapconcat 'text-char-description search-string "")))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (defun isearch-pop ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 (setq history (cdr history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 (let ((cmd (car history)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 (setq search-string (car cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 search-message (car (cdr cmd))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 success (nth 3 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 forward (nth 4 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 other-end (nth 5 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 invalid-regexp (nth 6 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 wrapped (nth 7 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 barrier (nth 8 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 uppercase-flag (nth 9 cmd))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 (goto-char (car (cdr (cdr cmd))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 (defun isearch-push-state ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 (setq history (cons (list search-string search-message (point)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 success forward other-end invalid-regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 wrapped barrier uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 history)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 (defun isearch-search ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 (let ((case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 (and case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 (not (and uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 search-upper-case)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 (isearch-message nil t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 (condition-case lossage
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 (let ((inhibit-quit nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (if regexp (setq invalid-regexp nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (setq success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (funcall
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 (if forward 're-search-forward 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (if forward 'search-forward 'search-backward))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 search-string nil t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (setq other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 (if forward (match-beginning 0) (match-end 0)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (quit (setq unread-command-char ?\C-g)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 (setq success nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 (invalid-regexp (setq invalid-regexp (car (cdr lossage)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 (if (string-match "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 invalid-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 (setq invalid-regexp "incomplete input"))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 ;; Ding if failed this time after succeeding last time.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 (and (nth 3 (car history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (ding))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (goto-char (nth 2 (car history))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 ;; This is called from incremental-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 ;; if the first input character is the exit character.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 ;; The interactive-arg-reader uses free variables `forward' and `regexp'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 ;; which are bound by `incremental-search'.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 ;; We store the search string in `search-string'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 ;; which has been bound already by `incremental-search'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 ;; so that, when we exit, it is copied into `search-last-string'.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 (defun nonincremental-search (forward regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (let (message char function string inhibit-quit)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 (let ((cursor-in-echo-area t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 ;; Prompt assuming not word search,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 (setq message (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 (if forward "Regexp search: "
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 "Regexp search backward: ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 (if forward "Search: " "Search backward: ")))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (message "%s" message)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 ;; Read 1 char and switch to word search if it is ^W.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 (setq char (read-event)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 (if (and (numberp char) (eq char search-yank-word-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 (setq message (if forward "Word search: " "Word search backward: "))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 ;; Otherwise let that 1 char be part of the search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (setq unread-command-char char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (setq function
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 (if (eq char search-yank-word-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (if forward 'word-search-forward 'word-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 (if forward 're-search-forward 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 (if forward 'search-forward 'search-backward))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 ;; Read the search string with corrected prompt.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 (setq string (read-string message))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 ;; Empty means use default.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (if (= 0 (length string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 (setq string search-last-string)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 ;; Set last search string now so it is set even if we fail.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (setq search-last-string string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 ;; Since we used the minibuffer, we should be available for redo.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 (setq command-history (cons (list function string) command-history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 ;; Go ahead and search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (funcall function string)))
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 347
diff changeset
608
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 347
diff changeset
609 ;;; isearch.el ends here