Mercurial > emacs
annotate lisp/isearch.el @ 809:8a0066235d56
Initial revision
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 17 Jul 1992 06:48:03 +0000 |
parents | 45d748a65f24 |
children | 20674ae6bf52 |
rev | line source |
---|---|
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
1 ;; isearch-mode.el --- incremental search minor mode. |
725 | 2 |
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
3 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu> |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
4 ;; Version: 1.2 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
5 ;; Last-Modified: 27 May 1992 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
6 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
7 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
725 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
26 ;;; Commentary: |
725 | 27 |
28 ;;;==================================================================== | |
29 ;; Instructions | |
30 | |
31 ;; Searching with isearch-mode.el should work just like isearch.el, | |
32 ;; except it is done in a temporary minor mode that terminates when | |
33 ;; you finish searching. | |
34 | |
35 ;; To use isearch-mode instead of the standard isearch.el, add the | |
36 ;; following to your .emacs file. The standard key bindings to | |
37 ;; isearch-forward, etc, will then use isearch-mode instead of | |
38 ;; isearch. | |
39 | |
40 ;; (fset 'isearch 'isearch-mode) | |
41 ;; (autoload 'isearch-mode "isearch-mode") | |
42 | |
43 ;; The key bindings active within isearch-mode are defined below in | |
44 ;; `isearch-mode-map' and `isearch-mode-meta-map' which are given | |
45 ;; bindings close to the default characters of isearch.el for | |
46 ;; version 19. With `isearch-mode', however, you can bind | |
47 ;; multi-character keys and it should be easier to add new commands. | |
48 | |
49 ;; Note to epoch and emacs version 19 users: isearch-mode should | |
50 ;; work even if you switch windows with the mouse. However, if | |
51 ;; you isearch in a buffer that is also displayed in another window, | |
52 ;; when you switch to that other window you will still be in | |
53 ;; isearch mode but not necessarily in the right state for it to work. | |
54 ;; So ... don't do it unless you are in an experimental mood. | |
55 ;; You can also experiment with the window-local-variable routines | |
56 ;; contained in this package but not yet used. | |
57 ;; Also, I am not sure what happens when you return to an isearching | |
58 ;; buffer; ideally, the echo area should redisplay the searching status. | |
59 ;; A select-window-hook might be useful. | |
60 | |
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
61 ;;; Change Log: |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
62 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
63 ;;;==================================================================== |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
64 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
65 ;;; $Header: /import/kaplan/kaplan/liberte/Isearch/RCS/isearch-mode.el,v 1.2 92/05/27 11:33:57 liberte Exp Locker: liberte $ |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
66 ;;; $Log: isearch-mode.el,v $ |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
67 ;;; Revision 1.2 92/05/27 11:33:57 liberte |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
68 ;;; Several new commands and features have been added. Emacs version |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
69 ;;; 19 has a search ring, which is supported here. Other fixes found |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
70 ;;; in the version 19 isearch are included here. Also see variables |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
71 ;;; search-caps-disable-folding, search-nonincremental-instead, |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
72 ;;; search-whitespace-regexp, and commands isearch-toggle-regexp, |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
73 ;;; isearch-edit-string, |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
74 ;;; |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
75 ;;; Semi-modal searching is supported, using a recursive edit. If |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
76 ;;; isearching is started non-interactively by calling one of the |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
77 ;;; isearch commands (e.g. isearch-forward), it does not return |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
78 ;;; until the search is completed. You should still be able switch |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
79 ;;; buffers, so be careful not to get things confused. |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
80 ;;; |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
81 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
82 ;;; Changes for 1.1 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
83 ;;; 3/18/92 Fixed invalid-regexp. |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
84 ;;; 3/18/92 Fixed yanking in regexps. |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
85 |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
86 ;;; Code: |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
725
diff
changeset
|
87 |
725 | 88 ;;;========================================================================= |
89 ;;; The following, defined in loaddefs.el, are still used with isearch-mode. | |
90 | |
91 ;(defvar search-last-string "" | |
92 ; "Last string search for by a search command. | |
93 ;This does not include direct calls to the primitive search functions, | |
94 ;and does not include searches that are aborted.") | |
95 | |
96 ;(defvar search-last-regexp "" | |
97 ; "Last string searched for by a regexp search command. | |
98 ;This does not include direct calls to the primitive search functions, | |
99 ;and does not include searches that are aborted.") | |
100 | |
101 ;(defconst search-exit-option t | |
102 ; "Non-nil means random control characters terminate incremental search.") | |
103 | |
104 ;(defvar search-slow-window-lines 1 | |
105 ; "*Number of lines in slow search display windows.") | |
106 | |
107 ;(defconst search-slow-speed 1200 | |
108 ; "*Highest terminal speed at which to use \"slow\" style incremental search. | |
109 ;This is the style where a one-line window is created to show the line | |
110 ;that the search has reached.") | |
111 | |
112 ;;;======================================================================== | |
113 ;;; Some additional options and constants. | |
114 | |
115 (defvar search-caps-disable-folding t | |
116 "*If non-nil, upper case chars disable case fold searching. | |
117 This does not yet apply to yanked strings, however.") | |
118 | |
119 (defvar search-nonincremental-instead t | |
120 "*If non-nil, do a nonincremental search instead if exiting immediately. | |
121 The default value of t reflects the default behavior of old | |
122 isearch.") | |
123 | |
124 (defconst search-whitespace-regexp "\\s-+" | |
125 "*If non-nil, regular expression to match a sequence of whitespace chars. | |
126 You might want to use something like \"[ \\t\\r\\n]+\" instead.") | |
127 | |
128 ;;;================================================================== | |
129 ;;; Search ring. | |
130 ;;; "regex" == "regexp". One should become the standard term. | |
131 | |
132 (defvar search-ring nil | |
133 "List of search string sequences.") | |
134 (defvar regex-search-ring nil ;; Is `regex' the new spelling? | |
135 "List of regular expression search string sequences.") | |
136 | |
137 (defconst search-ring-max 16 | |
138 "*Maximum length of search ring before oldest elements are thrown away.") | |
139 (defconst regex-search-ring-max 16 | |
140 "*Maximum length of regex search ring before oldest elements are thrown away.") | |
141 | |
142 (defvar search-ring-yank-pointer nil | |
143 "The tail of the search ring whose car is the last thing searched for.") | |
144 (defvar regex-search-ring-yank-pointer nil | |
145 "The tail of the regular expression search ring whose car is the last | |
146 thing searched for.") | |
147 | |
148 ;;;==================================================== | |
149 ;;; Define isearch-mode keymap. | |
150 | |
151 (defvar isearch-mode-map nil | |
152 "Keymap for isearch-mode.") | |
153 | |
154 (defvar isearch-mode-meta-map nil | |
155 "Keymap for isearch-mode for keys with meta char prefix.") | |
156 | |
157 | |
158 ;; To handle meta char prefix keys, define another full keymap. | |
159 ;; The same must be done for any other prefix keys. | |
160 ;; It would be simpler to disable to global keymap, and/or | |
161 ;; have a default local key binding for any key not otherwise bound. | |
162 (if isearch-mode-meta-map | |
163 nil | |
164 (setq isearch-mode-meta-map | |
165 (list 'keymap (make-vector 128 'isearch-other-meta-char))) | |
166 (define-key isearch-mode-meta-map "n" 'isearch-ring-advance) | |
167 (define-key isearch-mode-meta-map "p" 'isearch-ring-retreat) | |
168 (define-key isearch-mode-meta-map " " 'isearch-whitespace-chars) | |
169 ;for regexps | |
170 | |
171 ;; (define-key isearch-mode-meta-map "?" nil) ; my help key is M-? | |
172 ) | |
173 | |
174 (if isearch-mode-map | |
175 nil | |
176 (let ((i 0) | |
177 | |
178 ;; Printing chars extend the selection by default. | |
179 (array (make-vector 128 'isearch-printing-char))) | |
180 | |
181 ;; Non-printing chars by default suspend isearch mode transparently | |
182 (while (< i ?\ ) | |
183 (aset array i 'isearch-other-control-char) | |
184 (setq i (1+ i))) | |
185 | |
186 (setq i ?A) | |
187 (while (<= i ?Z) | |
188 (aset array i 'isearch-upper-case-char) | |
189 (setq i (1+ i))) | |
190 | |
191 (setq isearch-mode-map (list 'keymap array)) | |
192 | |
193 ;; You can reenable global keys by unbinding them locally. | |
194 | |
195 ;; For the help char this doesnt work quite as expected because | |
196 ;; isearch-mode is not a major mode, and the echo area is not | |
197 ;; restored after the help command. | |
198 ;; Also, we should not assume that the help-command is on C-h. | |
199 ;; If it is not, and the prefix is not the meta-char, we would | |
200 ;; have to create another map for its prefix. | |
201 ; (define-key isearch-mode-map "\C-h" nil) | |
202 | |
203 ;; Several non-printing chars change the searching behavior. | |
204 (define-key isearch-mode-map "\C-s" 'isearch-repeat-forward) | |
205 (define-key isearch-mode-map "\C-r" 'isearch-repeat-backward) | |
206 (define-key isearch-mode-map "\177" 'isearch-delete-char) | |
207 (define-key isearch-mode-map "\C-g" 'isearch-quit) | |
208 | |
209 | |
210 (define-key isearch-mode-map "\C-q" 'isearch-quote-char) | |
211 | |
212 ;; (define-key isearch-mode-map "\r" 'isearch-return-char) | |
213 ;; For version 19, CR (C-m) terminates search and LFD (C-j) matches eol. | |
214 (define-key isearch-mode-map "\r" 'isearch-exit) | |
215 (define-key isearch-mode-map "\C-j" 'isearch-printing-char) | |
216 | |
217 | |
218 (define-key isearch-mode-map "\C-w" 'isearch-yank-word) | |
219 (define-key isearch-mode-map "\C-y" 'isearch-yank-line) | |
220 | |
221 (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp) | |
222 (define-key isearch-mode-map "\C-^" 'isearch-edit-string) | |
223 | |
224 ;; define keys for regexp chars * ? | | |
225 (define-key isearch-mode-map "*" 'isearch-*-char) | |
226 (define-key isearch-mode-map "?" 'isearch-*-char) | |
227 (define-key isearch-mode-map "|" 'isearch-|-char) | |
228 | |
229 ;; Assumes meta-prefix-char is \e. | |
230 ;; isearch-mode-meta-map must be a keymap before this. | |
231 (define-key isearch-mode-map "\e" isearch-mode-meta-map) | |
232 )) | |
233 | |
234 ;;;======================================================== | |
235 ;; Internal variables declared globally for byte-compiler. | |
236 ;; These are all made buffer-local during searching. | |
237 | |
238 (defvar isearch-cmds nil | |
239 "Stack of search status sets.") | |
240 (defvar isearch-string "" | |
241 "The current search string.") | |
242 (defvar isearch-message "" | |
243 "The text-char-description version of isearch-string") | |
244 (defvar isearch-success t) | |
245 (defvar isearch-forward nil) | |
246 (defvar isearch-other-end nil | |
247 "Start of last match if forward, end if backward.") | |
248 (defvar isearch-invalid-regexp nil) | |
249 (defvar isearch-wrapped nil) | |
250 (defvar isearch-barrier 0) | |
251 | |
252 (defvar isearch-regexp nil) | |
253 (defvar isearch-case-fold-search nil | |
254 "Value of case-fold-search while actually searching.") | |
255 | |
256 (defvar isearch-adjusted nil) | |
257 (defvar isearch-slow-terminal-mode nil) | |
258 (defvar isearch-small-window nil | |
259 "If t, using a small window.") | |
260 (defvar isearch-found-point nil | |
261 "to restore point from a small window.") | |
262 | |
263 (defvar isearch-found-start nil | |
264 "This is the window-start value found by the search.") | |
265 (defvar isearch-opoint 0) | |
266 (defvar isearch-window-configuration nil | |
267 "The window configuration active at the beginning of the search.") | |
268 (defvar isearch-old-local-map []) | |
269 | |
270 (defvar isearch-yank-flag nil | |
271 "Flag to indicate a yank occurred, so don't move the cursor.") | |
272 | |
273 (defvar isearch-op-fun nil | |
274 "A function to be called after each input character is processed. | |
275 (It is not called after characters that exit the search.) | |
276 It is only set from an optional argument to `isearch-mode'.") | |
277 | |
278 ;; This is a global variable to avoid byte-compile warnings. | |
279 (defvar isearch-last-command-char -1 | |
280 "Last command char.") | |
281 | |
282 (defvar isearch-mode-hook nil | |
283 "List of functions to call after starting up an incremental search. | |
284 See `isearch-modal' for an example. | |
285 Set with `(setq isearch-mode-hook (cons 'myhook isearch-mode-hook)) | |
286 where myhook can be a function name or lambda expression.") | |
287 | |
288 (defvar isearch-mode-end-hook nil | |
289 "List of functions to call after terminating an incremental search. | |
290 See `isearch-mode-hook' for more details.") | |
291 | |
292 ;;;============================================================== | |
293 ;; Minor-mode-alist changes - kind of redundant with the | |
294 ;; echo area, but if isearching in multiple windows, it can be useful. | |
295 | |
296 (or (assq 'isearch-mode minor-mode-alist) | |
297 (nconc minor-mode-alist | |
298 (list '(isearch-mode isearch-mode)))) | |
299 | |
300 (defvar isearch-mode nil) | |
301 (make-variable-buffer-local 'isearch-mode) | |
302 | |
303 ;;;=============================================================== | |
304 ;;; Entry points to isearch-mode. | |
305 ;;; These four functions should be moved to loaddefs.el | |
306 | |
307 (defun isearch-forward () | |
308 "\ | |
309 Do incremental search forward. | |
310 As you type characters, they add to the search string and are found. | |
311 | |
312 \\<isearch-mode-map> | |
313 Type \\[isearch-delete-char] to cancel characters from end of search | |
314 string. | |
315 Type \\[isearch-exit] to exit, leaving point at location found. | |
316 Type \\[isearch-repeat-forward] to search again forward, | |
317 \\[isearch-repeat-backward] to search again backward. | |
318 Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching. | |
319 Type \\[isearch-yank-word] to yank word from buffer onto end of | |
320 search string and search for it. | |
321 Type \\[isearch-yank-line] to yank rest of line onto end of search string, etc. | |
322 Type \\[isearch-quote-char] to quote control character to search for it. | |
323 Type C-j to match end of line. | |
324 | |
325 Also supported is a search ring of the previous 16 search strings. | |
326 Type \\[isearch-ring-advance] to search for the next item in the search ring. | |
327 Type \\[isearch-ring-retreat] to search for the previous item in the search ring. | |
328 | |
329 Other control and meta characters terminate the search | |
330 and are then executed normally. | |
331 | |
332 \\[isearch-quit] while searching or when search has failed | |
333 cancels input back to what has been found successfully. | |
334 \\[isearch-quit] when search is successful aborts and moves point to starting point. | |
335 | |
336 All of these keys are bound in `isearch-mode-map' and | |
337 `isearch-mode-meta-map'. If `isearch-forward' is called | |
338 non-interactively, it does not return to the calling function until | |
339 the search is done." | |
340 (interactive) | |
341 (if (interactive-p) | |
342 (isearch-mode t) | |
343 (isearch-modal t))) | |
344 | |
345 (defun isearch-forward-regexp () | |
346 "\ | |
347 Do incremental search forward for regular expression. | |
348 Like ordinary incremental search except that your input | |
349 is treated as a regexp. See \\[isearch-forward] for more info." | |
350 (interactive) | |
351 (if (interactive-p) | |
352 (isearch-mode t t) | |
353 (isearch-modal t t))) | |
354 | |
355 (defun isearch-backward () | |
356 "\ | |
357 Do incremental search backward. | |
358 See \\[isearch-forward] for more information." | |
359 (interactive) | |
360 (if (interactive-p) | |
361 (isearch-mode nil) | |
362 (isearch-modal nil))) | |
363 | |
364 (defun isearch-backward-regexp () | |
365 "\ | |
366 Do incremental search backward for regular expression. | |
367 Like ordinary incremental search except that your input | |
368 is treated as a regexp. See \\[isearch-forward] for more info." | |
369 (interactive) | |
370 (if (interactive-p) | |
371 (isearch-mode nil t) | |
372 (isearch-modal nil t))) | |
373 | |
374 | |
375 (defun isearch-modal (forward &optional regexp op-fun) | |
376 ;; As an example of using the hooks, isearch-mode can be made | |
377 ;; modal (in the sense of not returning to the calling function | |
378 ;; until searching is completed) by entering a recursive-edit. | |
379 ;; This is used if the above functions are called non-interactively. | |
380 (let ((isearch-mode-hook | |
381 (cons (function (lambda () (recursive-edit))) | |
382 isearch-mode-hook)) | |
383 (isearch-mode-end-hook | |
384 (cons (function (lambda () (exit-recursive-edit))) | |
385 isearch-mode-end-hook))) | |
386 (isearch-mode forward regexp op-fun))) | |
387 | |
388 | |
389 ;;;================================================================== | |
390 ;; isearch-mode only sets up incremental search for the minor mode. | |
391 ;; All the work is done by the isearch-mode commands. | |
392 | |
393 (defun isearch-mode (forward &optional regexp op-fun) | |
394 "Start isearch minor mode. Called by isearch-forward, etc." | |
395 ;; Make buffer-local variables for isearching. | |
396 ;; We really need window-local variables. | |
397 (mapcar | |
398 'make-local-variable | |
399 '(isearch-forward | |
400 isearch-regexp isearch-string isearch-message | |
401 isearch-case-fold-search | |
402 isearch-cmds isearch-success isearch-wrapped | |
403 isearch-barrier isearch-adjusted isearch-invalid-regexp | |
404 isearch-slow-terminal-mode isearch-other-end isearch-small-window | |
405 isearch-found-point isearch-found-start isearch-opoint | |
406 isearch-window-configuration isearch-old-local-map)) | |
407 | |
408 ;; Initialize global vars. | |
409 (setq isearch-forward forward | |
410 isearch-regexp regexp | |
411 isearch-op-fun op-fun | |
412 isearch-case-fold-search case-fold-search | |
413 isearch-string "" | |
414 isearch-message "" | |
415 isearch-cmds nil | |
416 isearch-success t | |
417 isearch-wrapped nil | |
418 isearch-barrier (point) | |
419 isearch-adjusted nil | |
420 isearch-yank-flag nil | |
421 isearch-invalid-regexp nil | |
422 isearch-slow-terminal-mode (and (<= (baud-rate) search-slow-speed) | |
423 (> (window-height) | |
424 (* 4 search-slow-window-lines))) | |
425 isearch-other-end nil | |
426 isearch-small-window nil | |
427 isearch-found-point nil | |
428 | |
429 isearch-found-start nil | |
430 isearch-opoint (point) | |
431 isearch-window-configuration (current-window-configuration) | |
432 isearch-old-local-map (current-local-map) | |
433 | |
434 ;; inhibit-quit t | |
435 ) | |
436 (setq isearch-mode " Isearch") ;; forward? regexp? | |
437 (set-buffer-modified-p (buffer-modified-p)) ; update modeline | |
438 | |
439 (isearch-push-state) | |
440 | |
441 (use-local-map isearch-mode-map) | |
442 (isearch-update) | |
443 (run-hooks 'isearch-mode-hook) | |
444 ) | |
445 | |
446 | |
447 ;;;==================================================== | |
448 ;; Some high level utilities. Others below. | |
449 | |
450 (defun isearch-update () | |
451 ;; Called after each command to update the display. | |
452 (or unread-command-char | |
453 (progn | |
454 (if (not (input-pending-p)) | |
455 (isearch-message)) | |
456 (if (and isearch-slow-terminal-mode | |
457 (not (or isearch-small-window | |
458 (pos-visible-in-window-p)))) | |
459 (progn | |
460 (setq isearch-small-window t) | |
461 (setq isearch-found-point (point)) | |
462 (move-to-window-line 0) | |
463 (let ((window-min-height 1)) | |
464 (split-window nil (if (< search-slow-window-lines 0) | |
465 (1+ (- search-slow-window-lines)) | |
466 (- (window-height) | |
467 (1+ search-slow-window-lines))))) | |
468 (if (< search-slow-window-lines 0) | |
469 (progn (vertical-motion (- 1 search-slow-window-lines)) | |
470 (set-window-start (next-window) (point)) | |
471 (set-window-hscroll (next-window) | |
472 (window-hscroll)) | |
473 (set-window-hscroll (selected-window) 0)) | |
474 (other-window 1)) | |
475 (goto-char isearch-found-point))))) | |
476 (setq ;; quit-flag nil not for isearch-mode | |
477 isearch-adjusted nil | |
478 isearch-yank-flag nil) | |
479 ) | |
480 | |
481 | |
482 (defun isearch-done () | |
483 ;; Called by all commands that terminate isearch-mode. | |
484 (use-local-map isearch-old-local-map) | |
485 (setq isearch-found-start (window-start (selected-window))) | |
486 (setq isearch-found-point (point)) | |
487 (set-window-configuration isearch-window-configuration) | |
488 | |
489 (if (> (length isearch-string) 0) | |
490 ;; Update the ring data. | |
491 (if isearch-regexp | |
492 (if (not (setq regex-search-ring-yank-pointer | |
493 (memq isearch-string regex-search-ring))) | |
494 (progn | |
495 (setq regex-search-ring (cons isearch-string regex-search-ring) | |
496 regex-search-ring-yank-pointer regex-search-ring) | |
497 (if (> (length regex-search-ring) regex-search-ring-max) | |
498 (setcdr (nthcdr (1- search-ring-max) regex-search-ring) | |
499 nil)))) | |
500 (if (not (setq search-ring-yank-pointer | |
501 (memq isearch-string search-ring))) | |
502 (progn | |
503 (setq search-ring (cons isearch-string search-ring) | |
504 search-ring-yank-pointer search-ring) | |
505 (if (> (length search-ring) search-ring-max) | |
506 (setcdr (nthcdr (1- search-ring-max) search-ring) nil)))))) | |
507 | |
508 ;; If there was movement, mark the starting position. | |
509 ;; Maybe should test difference between and set mark iff > threshold. | |
510 (if (/= (point) isearch-opoint) | |
511 (push-mark isearch-opoint) | |
512 (message "")) | |
513 (if isearch-small-window | |
514 (goto-char isearch-found-point) | |
515 ;; Exiting the save-window-excursion clobbers window-start; restore it. | |
516 (set-window-start (selected-window) isearch-found-start t)) | |
517 | |
518 ;; Kill buffer-local variables for isearching | |
519 (mapcar | |
520 'kill-local-variable | |
521 '(isearch-forward | |
522 isearch-regexp isearch-string isearch-message | |
523 isearch-case-fold-search | |
524 isearch-cmds isearch-success isearch-wrapped | |
525 isearch-barrier isearch-adjusted isearch-invalid-regexp | |
526 isearch-slow-terminal-mode isearch-other-end isearch-small-window | |
527 isearch-found-point isearch-found-start isearch-opoint | |
528 isearch-window-configuration isearch-old-local-map)) | |
529 | |
530 (setq isearch-mode nil) | |
531 (set-buffer-modified-p (buffer-modified-p)) | |
532 (run-hooks 'isearch-mode-end-hook) | |
533 ) | |
534 | |
535 | |
536 ;;;==================================================== | |
537 ;; Commands active while inside of the isearch minor mode. | |
538 | |
539 (defun isearch-exit () | |
540 "Exit search normally. | |
541 However, if this is the first command after starting incremental | |
542 search and `search-nonincremental-instead' is non-nil, do a | |
543 nonincremental search instead." | |
544 | |
545 (interactive) | |
546 (if (and search-nonincremental-instead | |
547 (= 0 (length isearch-string))) | |
548 (nonincremental-search isearch-forward isearch-regexp)) | |
549 (isearch-done)) | |
550 | |
551 | |
552 (defun isearch-edit-string () | |
553 "Edit the search string in the minibuffer and return to incremental search." | |
554 ;; This doesnt back up the search point. | |
555 (interactive) | |
556 (setq isearch-string (read-string (isearch-message-prefix) isearch-string) | |
557 isearch-message (mapconcat 'text-char-description | |
558 isearch-string "")) | |
559 (isearch-push-state) | |
560 (isearch-search) | |
561 (isearch-update)) | |
562 | |
563 | |
564 (defun isearch-quit () | |
565 "Quit incremental search mode if searching is successful. | |
566 Otherwise, revert to previous successful search and continue searching." | |
567 (interactive) | |
568 (ding) | |
569 (discard-input) | |
570 (if isearch-success | |
571 ;; If search is successful, move back to starting point | |
572 ;; and really do quit. | |
573 (progn (goto-char isearch-opoint) | |
574 (isearch-done)) ; exit and quit | |
575 ;; If search is failing, rub out until it is once more | |
576 ;; successful. | |
577 (while (not isearch-success) (isearch-pop-state)) | |
578 (isearch-update))) | |
579 | |
580 | |
581 (defun isearch-repeat (direction) | |
582 ;; Utility for isearch-repeat-forward and -backward. | |
583 (if (eq isearch-forward (eq direction 'forward)) | |
584 ;; C-s in forward or C-r in reverse. | |
585 (if (equal isearch-string "") | |
586 ;; If search string is empty, use last one. | |
587 (setq isearch-string | |
588 ;; (if isearch-regexp | |
589 ;; search-last-regexp search-last-string) | |
590 (or (if isearch-regexp | |
591 (if regex-search-ring-yank-pointer | |
592 (car regex-search-ring-yank-pointer) | |
593 (car regex-search-ring)) | |
594 (if search-ring-yank-pointer | |
595 (car search-ring-yank-pointer) | |
596 (car search-ring))) | |
597 "") | |
598 isearch-message | |
599 (mapconcat 'text-char-description | |
600 isearch-string "")) | |
601 ;; If already have what to search for, repeat it. | |
602 (or isearch-success | |
603 (progn | |
604 | |
605 (goto-char (if isearch-forward (point-min) (point-max))) | |
606 (setq isearch-wrapped t)))) | |
607 ;; C-s in reverse or C-r in forward, change direction. | |
608 (setq isearch-forward (not isearch-forward))) | |
609 | |
610 (setq isearch-barrier (point)) ; For subsequent \| if regexp. | |
611 (setq isearch-success t) | |
612 (or (equal isearch-string "") | |
613 (progn | |
614 ;; If repeating a search that found | |
615 ;; an empty string, ensure we advance. | |
616 (if (equal (match-end 0) (match-beginning 0)) | |
617 (forward-char (if isearch-forward 1 -1))) | |
618 (isearch-search))) | |
619 (isearch-push-state) | |
620 (isearch-update)) | |
621 | |
622 (defun isearch-repeat-forward () | |
623 "Repeat incremental search forwards." | |
624 (interactive) | |
625 (isearch-repeat 'forward)) | |
626 | |
627 (defun isearch-repeat-backward () | |
628 "Repeat incremental search backwards." | |
629 (interactive) | |
630 (isearch-repeat 'backward)) | |
631 | |
632 (defun isearch-toggle-regexp () | |
633 "Toggle regexp searching on or off." | |
634 ;; The status stack is left unchanged. | |
635 (interactive) | |
636 (setq isearch-regexp (not isearch-regexp)) | |
637 (isearch-update)) | |
638 | |
639 (defun isearch-delete-char () | |
640 "Discard last input item and move point back. | |
641 If no previous match was done, just beep." | |
642 (interactive) | |
643 (if (null (cdr isearch-cmds)) | |
644 (ding) | |
645 (isearch-pop-state)) | |
646 (isearch-update)) | |
647 | |
648 | |
649 (defun isearch-yank (chunk) | |
650 ;; Helper for isearch-yank-word and isearch-yank-line | |
651 (let ((word (save-excursion | |
652 (and (not isearch-forward) isearch-other-end | |
653 (goto-char isearch-other-end)) | |
654 (buffer-substring | |
655 (point) | |
656 (save-excursion | |
657 (cond | |
658 ((eq chunk 'word) | |
659 (forward-word 1)) | |
660 ((eq chunk 'line) | |
661 (end-of-line))) | |
662 (point)))))) | |
663 (if isearch-regexp (setq word (regexp-quote word))) | |
664 (setq isearch-string (concat isearch-string word) | |
665 isearch-message | |
666 (concat isearch-message | |
667 (mapconcat 'text-char-description | |
668 word "")) | |
669 ;; Don't move cursor in reverse search. | |
670 isearch-yank-flag t)) | |
671 (isearch-search-and-update)) | |
672 | |
673 | |
674 (defun isearch-yank-word () | |
675 "Pull next word from buffer into search string." | |
676 (interactive) | |
677 (isearch-yank 'word)) | |
678 | |
679 (defun isearch-yank-line () | |
680 "Pull rest of line from buffer into search string." | |
681 (interactive) | |
682 (isearch-yank 'line)) | |
683 | |
684 | |
685 (defun isearch-search-and-update () | |
686 ;; Do the search and update the display. | |
687 (if (and (not isearch-success) | |
688 ;; unsuccessful regexp search may become | |
689 ;; successful by addition of characters which | |
690 ;; make isearch-string valid | |
691 (not isearch-regexp)) | |
692 nil | |
693 ;; In reverse search, adding stuff at | |
694 ;; the end may cause zero or many more chars to be | |
695 ;; matched, in the string following point. | |
696 ;; Allow all those possibilities without moving point as | |
697 ;; long as the match does not extend past search origin. | |
698 (if (and (not isearch-forward) (not isearch-adjusted) | |
699 (condition-case () | |
700 (looking-at (if isearch-regexp isearch-string | |
701 (regexp-quote isearch-string))) | |
702 (error nil)) | |
703 (or isearch-yank-flag | |
704 (<= (match-end 0) | |
705 (min isearch-opoint isearch-barrier)))) | |
706 (setq isearch-success t | |
707 isearch-invalid-regexp nil | |
708 isearch-other-end (match-end 0)) | |
709 ;; Not regexp, not reverse, or no match at point. | |
710 (if (and isearch-other-end (not isearch-adjusted)) | |
711 (goto-char (if isearch-forward isearch-other-end | |
712 (min isearch-opoint | |
713 isearch-barrier | |
714 (1+ isearch-other-end))))) | |
715 (isearch-search) | |
716 )) | |
717 (isearch-push-state) | |
718 (if isearch-op-fun (funcall isearch-op-fun)) | |
719 (isearch-update)) | |
720 | |
721 | |
722 ;; *, ?, and | chars can make a regexp more liberal. | |
723 ;; They can make a regexp match sooner | |
724 ;; or make it succeed instead of failing. | |
725 ;; So go back to place last successful search started | |
726 ;; or to the last ^S/^R (barrier), whichever is nearer. | |
727 | |
728 (defun isearch-*-char () | |
729 "Handle * and ? specially in regexps." | |
730 (interactive) | |
731 (if isearch-regexp | |
732 | |
733 (progn | |
734 (setq isearch-adjusted t) | |
735 (let ((cs (nth (if isearch-forward | |
736 5 ; isearch-other-end | |
737 2) ; saved (point) | |
738 (car (cdr isearch-cmds))))) | |
739 ;; (car isearch-cmds) is after last search; | |
740 ;; (car (cdr isearch-cmds)) is from before it. | |
741 (setq cs (or cs isearch-barrier)) | |
742 (goto-char | |
743 (if isearch-forward | |
744 (max cs isearch-barrier) | |
745 (min cs isearch-barrier)))))) | |
746 (isearch-process-search-char last-command-char)) | |
747 | |
748 | |
749 | |
750 (defun isearch-|-char () | |
751 "If in regexp search, jump to the barrier." | |
752 (interactive) | |
753 (if isearch-regexp | |
754 (progn | |
755 (setq isearch-adjusted t) | |
756 (goto-char isearch-barrier))) | |
757 (isearch-process-search-char last-command-char)) | |
758 | |
759 | |
760 | |
761 (defun isearch-other-control-char () | |
762 "Any other control char => unread it and exit the search normally. | |
763 But only if `search-exit-option' is non-nil." | |
764 (interactive) | |
765 (if search-exit-option | |
766 (progn | |
767 (setq unread-command-char last-command-char) | |
768 (isearch-done)) | |
769 ;; otherwise | |
770 (isearch-search-and-update))) | |
771 | |
772 | |
773 (defun isearch-other-meta-char () | |
774 "Any other meta char => exit the search normally and reexecute the whole key. | |
775 But only if `search-exit-option' is non-nil." | |
776 ;; This will probably work in place of isearch-other-control-char too, | |
777 ;; but here we use unwind-protect and command-execute since it is | |
778 ;; a multi-char key we would want to unread. | |
779 (interactive) | |
780 (if search-exit-option | |
781 (unwind-protect | |
782 (isearch-done) ;; this exits recursive edit | |
783 ;; Reexecute the key. | |
784 (command-execute (this-command-keys))) | |
785 ;; otherwise | |
786 (isearch-search-and-update))) | |
787 | |
788 | |
789 (defun isearch-quote-char () | |
790 "Quote special characters for incremental search." | |
791 (interactive) | |
792 (isearch-process-search-char (read-quoted-char (isearch-message t)))) | |
793 | |
794 | |
795 (defun isearch-return-char () | |
796 "Convert return into newline for incremental search. | |
797 Obsolete." | |
798 (interactive) | |
799 (isearch-process-search-char ?\n)) | |
800 | |
801 | |
802 (defun isearch-printing-char () | |
803 "Any other printing character => add it to the search string and search." | |
804 (interactive) | |
805 (isearch-process-search-char last-command-char)) | |
806 | |
807 | |
808 (defun isearch-upper-case-char () | |
809 "Any upper case char => turn off case fold search for remainder of search." | |
810 ;; This feature only applies to interactively entered chars, | |
811 ;; but not yanked chars, repeat default searches, or search ring searches. | |
812 ;; Support for these should be easy to add. | |
813 (interactive) | |
814 (if search-caps-disable-folding | |
815 (setq isearch-case-fold-search nil)) | |
816 (isearch-printing-char)) | |
817 | |
818 (defun isearch-whitespace-chars () | |
819 "Match all whitespace chars, if in regexp mode." | |
820 (interactive) | |
821 (if (and isearch-regexp search-whitespace-regexp) | |
822 (isearch-process-search-string search-whitespace-regexp " ") | |
823 (isearch-other-meta-char))) | |
824 | |
825 (defun isearch-process-search-char (char) | |
826 ;; Append the char to the search string, update the message and re-search. | |
827 (isearch-process-search-string (char-to-string char) | |
828 | |
829 (text-char-description char))) | |
830 | |
831 (defun isearch-process-search-string (string message) | |
832 (setq isearch-string (concat isearch-string string) | |
833 isearch-message (concat isearch-message message)) | |
834 (isearch-search-and-update)) | |
835 | |
836 | |
837 ;;=========================================================== | |
838 ;; Search Ring | |
839 | |
840 (defun isearch-ring-adjust (advance) | |
841 ;; helper for isearch-ring-advance and isearch-ring-retreat | |
842 (if (cdr isearch-cmds) | |
843 (isearch-pop-state)) | |
844 (let* ((ring (if isearch-regexp regex-search-ring search-ring)) | |
845 (length (length ring)) | |
846 (yank-pointer-name (if isearch-regexp | |
847 'regex-search-ring-yank-pointer | |
848 'search-ring-yank-pointer)) | |
849 (yank-pointer (eval yank-pointer-name))) | |
850 (if (zerop length) | |
851 () | |
852 (set yank-pointer-name | |
853 (setq yank-pointer | |
854 (nthcdr (% (+ (- length (length yank-pointer)) | |
855 (if advance (1- length) 1)) | |
856 length) ring))) | |
857 (setq isearch-string (car yank-pointer) | |
858 isearch-message (mapconcat 'text-char-description | |
859 isearch-string "")))) | |
860 (isearch-push-state) | |
861 (isearch-search) | |
862 (isearch-update)) | |
863 | |
864 (defun isearch-ring-advance () | |
865 "Advance to the next search string in the ring." | |
866 (interactive) | |
867 (isearch-ring-adjust 'advance)) | |
868 | |
869 (defun isearch-ring-retreat () | |
870 "Retreat to the previous search string in the ring." | |
871 (interactive) | |
872 (isearch-ring-adjust nil)) | |
873 | |
874 | |
875 ;;;============================================================= | |
876 ;; Window-local variables | |
877 ;; (not used yet - and maybe never) | |
878 | |
879 (defvar window-local-variable-alist nil | |
880 "An alist of windows associated with window local variables and values. | |
881 The cdr of each item is another alist of variables and values.") | |
882 | |
883 (defvar last-local-window nil) | |
884 (defvar last-window-local-vars nil) | |
885 | |
886 (defun kill-window-local-variables () | |
887 "Remove the old variable list, if any." | |
888 (setq window-local-variable-alist | |
889 (delq window-local-variable-alist | |
890 (assq (selected-window) | |
891 window-local-variable-alist)))) | |
892 | |
893 ;; Assume that window-local variables are not buffer-local | |
894 ;; so we can delay storing until absolutely necessary. | |
895 | |
896 (defun store-window-local-variables (&rest vars-and-vals) | |
897 "Store the window local variables for selected window." | |
898 (setq last-local-window (selected-window)) | |
899 (setq last-window-local-vars vars-and-vals)) | |
900 | |
901 | |
902 (defun fetch-window-local-variables () | |
903 "Fetch the window local variables for selected window. | |
904 Does nothing if the last store was for the same window." | |
905 (if (not (eq (selected-window) last-local-window)) | |
906 (progn | |
907 ;; First store the previous values. | |
908 (setq window-local-variable-alist | |
909 (cons (cons last-local-window | |
910 last-window-local-vars) | |
911 (delq window-local-variable-alist | |
912 (assq last-local-window | |
913 window-local-variable-alist)))) | |
914 ;; Now fetch the values for the selected-window. | |
915 (setq last-local-window (selected-window)) | |
916 (setq last-window-local-vars | |
917 (cdr (assq last-local-window window-local-variable-alist))) | |
918 (let ((vars-and-vals last-window-local-vars)) | |
919 (while vars-and-vals | |
920 (set (car vars-and-vals) (car (cdr vars-and-vals))) | |
921 (setq vars-and-vals (cdr (cdr vars-and-vals)))))))) | |
922 | |
923 | |
924 | |
925 ;;;============================================================== | |
926 ;; The search status stack (and isearch window-local variables, not used). | |
927 | |
928 (defun isearch-top-state () | |
929 ;; (fetch-window-local-variables) | |
930 (let ((cmd (car isearch-cmds))) | |
931 (setq isearch-string (car cmd) | |
932 isearch-message (car (cdr cmd)) | |
933 isearch-success (nth 3 cmd) | |
934 isearch-forward (nth 4 cmd) | |
935 isearch-other-end (nth 5 cmd) | |
936 isearch-invalid-regexp (nth 6 cmd) | |
937 isearch-wrapped (nth 7 cmd) | |
938 isearch-barrier (nth 8 cmd)) | |
939 (goto-char (car (cdr (cdr cmd)))))) | |
940 | |
941 (defun isearch-pop-state () | |
942 ;; (fetch-window-local-variables) | |
943 (setq isearch-cmds (cdr isearch-cmds)) | |
944 (isearch-top-state) | |
945 ) | |
946 | |
947 (defun isearch-push-state () | |
948 (setq isearch-cmds | |
949 (cons (list isearch-string isearch-message (point) | |
950 isearch-success isearch-forward isearch-other-end | |
951 isearch-invalid-regexp isearch-wrapped isearch-barrier) | |
952 isearch-cmds))) | |
953 | |
954 (defun isearch-store-variables () | |
955 (store-window-local-variables | |
956 'isearch-cmds isearch-cmds | |
957 'isearch-regexp isearch-regexp | |
958 'isearch-adjusted isearch-adjusted | |
959 'isearch-slow-terminal-mode isearch-slow-terminal-mode | |
960 'isearch-small-window isearch-small-window | |
961 'isearch-found-point isearch-found-point | |
962 'isearch-found-start isearch-found-start | |
963 'isearch-opoint isearch-opoint | |
964 'isearch-window-configuration isearch-window-configuration | |
965 'isearch-old-local-map isearch-old-local-map | |
966 )) | |
967 | |
968 | |
969 ;;;================================================================== | |
970 ;; Message string | |
971 | |
972 (defun isearch-message (&optional c-q-hack ellipsis) | |
973 ;; Generate and print the message string. | |
974 (let ((cursor-in-echo-area ellipsis) | |
975 (m (concat | |
976 (isearch-message-prefix c-q-hack ellipsis) | |
977 isearch-message | |
978 (isearch-message-suffix c-q-hack ellipsis) | |
979 ))) | |
980 (if c-q-hack m (message "%s" m)))) | |
981 | |
982 (defun isearch-message-prefix (&optional c-q-hack ellipsis) | |
983 ;; If about to search, and previous search regexp was invalid, | |
984 ;; check that it still is. If it is valid now, | |
985 ;; let the message we display while searching say that it is valid. | |
986 (and isearch-invalid-regexp ellipsis | |
987 (condition-case () | |
988 (progn (re-search-forward isearch-string (point) t) | |
989 (setq isearch-invalid-regexp nil)) | |
990 (error nil))) | |
991 ;; If currently failing, display no ellipsis. | |
992 (or isearch-success (setq ellipsis nil)) | |
993 (let ((m (concat (if isearch-success "" "failing ") | |
994 (if isearch-wrapped "wrapped ") | |
995 (if isearch-regexp "regexp " "") | |
996 "I-search" | |
997 (if isearch-forward ": " " backward: ") | |
998 ))) | |
999 (aset m 0 (upcase (aref m 0))) | |
1000 m)) | |
1001 | |
1002 | |
1003 (defun isearch-message-suffix (&optional c-q-hack ellipsis) | |
1004 (concat (if c-q-hack "^Q" "") | |
1005 (if isearch-invalid-regexp | |
1006 (concat " [" isearch-invalid-regexp "]") | |
1007 ""))) | |
1008 | |
1009 | |
1010 ;;;======================================================== | |
1011 ;;; Searching | |
1012 | |
1013 (defun isearch-search () | |
1014 ;; Do the search with the current search string. | |
1015 (isearch-message nil t) | |
1016 (condition-case lossage | |
1017 (let ((inhibit-quit nil) | |
1018 (case-fold-search isearch-case-fold-search)) | |
1019 (if isearch-regexp (setq isearch-invalid-regexp nil)) | |
1020 (setq isearch-success | |
1021 (funcall | |
1022 (if isearch-regexp | |
1023 (if isearch-forward 're-search-forward 're-search-backward) | |
1024 (if isearch-forward 'search-forward 'search-backward)) | |
1025 isearch-string nil t)) | |
1026 (if isearch-success | |
1027 (setq isearch-other-end | |
1028 (if isearch-forward (match-beginning 0) (match-end 0))))) | |
1029 | |
1030 (quit (setq unread-command-char ?\C-g) | |
1031 (setq isearch-success nil)) | |
1032 | |
1033 (invalid-regexp | |
1034 (setq isearch-invalid-regexp (car (cdr lossage))) | |
1035 (if (string-match | |
1036 "\\`Premature \\|\\`Unmatched \\|\\`Invalid " | |
1037 isearch-invalid-regexp) | |
1038 (setq isearch-invalid-regexp "incomplete input")))) | |
1039 | |
1040 (if isearch-success | |
1041 nil | |
1042 ;; Ding if failed this time after succeeding last time. | |
1043 (and (nth 3 (car isearch-cmds)) | |
1044 (ding)) | |
1045 (goto-char (nth 2 (car isearch-cmds))))) | |
1046 | |
1047 ;;;================================================= | |
1048 ;; This is called from incremental-search | |
1049 ;; if the first input character is the exit character. | |
1050 | |
1051 ;; We store the search string in `isearch-string' | |
1052 ;; which has been bound already by `isearch-search' | |
1053 ;; so that, when we exit, it is copied into `search-last-string'. | |
1054 | |
1055 (defun nonincremental-search (forward regexp) | |
1056 ;; This may be broken. Anyway, it could be replaced by the | |
1057 ;; isearch-edit-string command instead. | |
1058 (setq isearch-forward forward | |
1059 isearch-regexp regexp) | |
1060 (let (char function | |
1061 inhibit-quit | |
1062 (cursor-in-echo-area t)) | |
1063 ;; Prompt assuming not word search, | |
1064 (setq isearch-message | |
1065 | |
1066 (if isearch-regexp | |
1067 | |
1068 (if isearch-forward "Regexp search: " | |
1069 "Regexp search backward: ") | |
1070 (if isearch-forward "Search: " "Search backward: "))) | |
1071 (message "%s" isearch-message) | |
1072 ;; Read 1 char and switch to word search if it is ^W. | |
1073 (setq char (read-char)) | |
1074 (if (eq char search-yank-word-char) | |
1075 (setq isearch-message (if isearch-forward "Word search: " | |
1076 | |
1077 "Word search backward: ")) | |
1078 ;; Otherwise let that 1 char be part of the search string. | |
1079 (setq unread-command-char char)) | |
1080 (setq function | |
1081 (if (eq char search-yank-word-char) | |
1082 (if isearch-forward 'word-search-forward 'word-search-backward) | |
1083 (if isearch-regexp | |
1084 (if isearch-forward 're-search-forward 're-search-backward) | |
1085 (if isearch-forward 'search-forward 'search-backward)))) | |
1086 ;; Read the search string with corrected prompt. | |
1087 (setq isearch-string (read-string isearch-message isearch-string)) | |
1088 ;; Empty means use default. | |
1089 (if (= 0 (length isearch-string)) | |
1090 (setq isearch-string search-last-string) | |
1091 ;; Set last search string now so it is set even if we fail. | |
1092 (setq search-last-string isearch-string)) | |
1093 ;; Since we used the minibuffer, we should be available for redo. | |
1094 (setq command-history | |
1095 | |
1096 (cons (list function isearch-string) command-history)) | |
1097 ;; Go ahead and search. | |
1098 (let ((case-fold-search isearch-case-fold-search)) | |
1099 (funcall function isearch-string)))) |