0
|
1 ;; Incremental search minor mode.
|
|
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; LCD Archive Entry:
|
|
5 ;; isearch-mode|Daniel LaLiberte|liberte@cs.uiuc.edu
|
|
6 ;; |A minor mode replacement for isearch.el.
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
16
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
0
|
24
|
|
25 ;;; Synched up with: Not synched with FSF.
|
|
26
|
|
27 ;;;====================================================================
|
|
28 ;; Instructions
|
|
29
|
|
30 ;; Searching with isearch-mode.el should work just like isearch.el,
|
|
31 ;; except it is done in a temporary minor mode that terminates when
|
|
32 ;; you finish searching.
|
|
33
|
|
34 ;; Semi-modal searching is supported, using a recursive edit. If
|
|
35 ;; isearching is started non-interactively by calling one of the
|
|
36 ;; isearch commands (e.g. (isearch-forward), but not like gnus does
|
|
37 ;; it: (call-interactively 'isearch-forward)), isearch-mode does not
|
|
38 ;; return until the search is completed. You should still be able
|
|
39 ;; switch buffers, so be careful not to get things confused.
|
|
40
|
|
41 ;; The key bindings active within isearch-mode are defined below in
|
|
42 ;; `isearch-mode-map' which is given bindings close to the default
|
|
43 ;; characters of isearch.el for version 19. With `isearch-mode',
|
|
44 ;; however, you can bind multi-character keys and it should be easier
|
|
45 ;; to add new commands. One bug though: keys with meta-prefix cannot
|
|
46 ;; be longer than two chars. Also see minibuffer-local-isearch-map
|
|
47 ;; for bindings active during `isearch-edit-string'.
|
|
48
|
|
49 ;; The search ring and completion commands automatically put you in
|
|
50 ;; the minibuffer to edit the string. This gives you a chance to
|
|
51 ;; modify the search string before executing the search. There are
|
|
52 ;; three commands to terminate the editing: C-s and C-r exit the
|
|
53 ;; minibuffer and search forward and reverse respectively, while C-m
|
|
54 ;; exits and does a nonincremental search.
|
|
55
|
|
56 ;; Exiting immediately from isearch uses isearch-edit-string instead
|
|
57 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
|
|
58 ;; The name of this option should probably be changed if we decide to
|
|
59 ;; keep the behavior. One difference is that isearch-edit-string does
|
|
60 ;; not support word search yet; perhaps isearch-mode should support it
|
|
61 ;; even for incremental searches, but how?
|
|
62
|
|
63 ;;;====================================================================
|
|
64 ;;; Change History
|
|
65
|
|
66 ;;; Header: /import/kaplan/kaplan/liberte/Isearch/RCS/isearch-mode.el,v 1.3 92/06/29 13:10:08 liberte Exp Locker: liberte
|
|
67 ;;; Log: isearch-mode.el,v
|
|
68 ;;;
|
|
69 ;;; 20-aug-92 Hacked by jwz for Lucid Emacs 19.3.
|
|
70 ;;;
|
|
71 ;;; Revision 1.3 92/06/29 13:10:08 liberte
|
|
72 ;;; Moved modal isearch-mode handling into isearch-mode.
|
|
73 ;;; Got rid of buffer-local isearch variables.
|
|
74 ;;; isearch-edit-string used by ring adjustments, completion, and
|
|
75 ;;; nonincremental searching. C-s and C-r are additional exit commands.
|
|
76 ;;; Renamed all regex to regexp.
|
|
77 ;;; Got rid of found-start and found-point globals.
|
|
78 ;;; Generalized handling of upper-case chars.
|
|
79
|
|
80 ;;; Revision 1.2 92/05/27 11:33:57 liberte
|
|
81 ;;; Emacs version 19 has a search ring, which is supported here.
|
|
82 ;;; Other fixes found in the version 19 isearch are included here.
|
|
83 ;;;
|
|
84 ;;; Also see variables search-caps-disable-folding,
|
|
85 ;;; search-nonincremental-instead, search-whitespace-regexp, and
|
|
86 ;;; commands isearch-toggle-regexp, isearch-edit-string.
|
|
87 ;;;
|
|
88 ;;; semi-modal isearching is supported.
|
|
89
|
|
90 ;;; Changes for 1.1
|
|
91 ;;; 3/18/92 Fixed invalid-regexp.
|
|
92 ;;; 3/18/92 Fixed yanking in regexps.
|
|
93
|
|
94
|
|
95 (defun isearch-char-to-string (c)
|
|
96 (if (integerp c)
|
|
97 (make-string 1 c)
|
|
98 (make-string 1 (event-to-character c nil nil t))))
|
|
99
|
|
100 ;(defun isearch-text-char-description (c)
|
|
101 ; (isearch-char-to-string c))
|
|
102
|
|
103 (define-function 'isearch-text-char-description 'text-char-description)
|
|
104
|
|
105
|
|
106 ;;;=========================================================================
|
|
107 ;;; User-accessible variables
|
|
108
|
|
109 (defvar search-last-string ""
|
|
110 "Last string search for by a search command.
|
|
111 This does not include direct calls to the primitive search functions,
|
|
112 and does not include searches that are aborted.")
|
|
113
|
|
114 (defvar search-last-regexp ""
|
|
115 "Last string searched for by a regexp search command.
|
|
116 This does not include direct calls to the primitive search functions,
|
|
117 and does not include searches that are aborted.")
|
|
118
|
|
119 (defconst search-exit-option t
|
|
120 "Non-nil means random control characters terminate incremental search.")
|
|
121
|
|
122 (defvar search-slow-window-lines 1
|
|
123 "*Number of lines in slow search display windows.
|
|
124 These are the short windows used during incremental search on slow terminals.
|
|
125 Negative means put the slow search window at the top (normally it's at bottom)
|
|
126 and the value is minus the number of lines.")
|
|
127
|
|
128 (defconst search-slow-speed 1200
|
|
129 "*Highest terminal speed at which to use \"slow\" style incremental search.
|
|
130 This is the style where a one-line window is created to show the line
|
|
131 that the search has reached.")
|
|
132
|
|
133 (defvar search-caps-disable-folding t
|
|
134 "*If non-nil, upper case chars disable case fold searching.
|
|
135 This does not apply to \"yanked\" strings.")
|
|
136
|
|
137 (defvar search-nonincremental-instead t
|
|
138 "*If non-nil, do a nonincremental search instead if exiting immediately.")
|
|
139
|
|
140 (defconst search-whitespace-regexp "\\(\\s \\|[\n\r]\\)+"
|
|
141 "*If non-nil, regular expression to match a sequence of whitespace chars.")
|
|
142
|
|
143 ;;;==================================================================
|
|
144 ;;; Search ring.
|
|
145
|
|
146 (defvar search-ring nil
|
|
147 "List of search string sequences.")
|
|
148 (defvar regexp-search-ring nil
|
|
149 "List of regular expression search string sequences.")
|
|
150
|
|
151 (defconst search-ring-max 16
|
|
152 "*Maximum length of search ring before oldest elements are thrown away.")
|
|
153 (defconst regexp-search-ring-max 16
|
|
154 "*Maximum length of regexp search ring before oldest elements are thrown away.")
|
|
155
|
|
156 (defvar search-ring-yank-pointer nil
|
|
157 "The tail of the search ring whose car is the last thing searched for.")
|
|
158 (defvar regexp-search-ring-yank-pointer nil
|
|
159 "The tail of the regular expression search ring whose car is the last
|
|
160 thing searched for.")
|
|
161
|
|
162 ;;;====================================================
|
|
163 ;;; Define isearch-mode keymap.
|
|
164
|
|
165 (defvar isearch-mode-map
|
|
166 (let ((map (make-keymap)))
|
|
167 (set-keymap-name map 'isearch-mode-map)
|
|
168
|
|
169 ;; Bind all printing characters to `isearch-printing-char'.
|
|
170 ;; This isn't normally necessary, but if a printing character were
|
|
171 ;; bound to something other than self-insert-command in global-map,
|
|
172 ;; then it would terminate the search and be executed without this.
|
|
173 (let ((i 32)
|
|
174 (str (make-string 1 0)))
|
|
175 (while (< i 127)
|
|
176 (aset str 0 i)
|
|
177 (define-key map str 'isearch-printing-char)
|
|
178 (setq i (1+ i))))
|
|
179 (define-key map "\t" 'isearch-printing-char)
|
|
180
|
|
181 ;; Several non-printing chars change the searching behavior.
|
|
182 ;;
|
|
183 (define-key map "\C-s" 'isearch-repeat-forward)
|
|
184 (define-key map "\M-\C-s" 'isearch-repeat-forward)
|
|
185 (define-key map "\C-r" 'isearch-repeat-backward)
|
|
186 (define-key map "\177" 'isearch-delete-char)
|
|
187 (define-key map "\C-g" 'isearch-abort)
|
|
188
|
|
189 (define-key map "\C-q" 'isearch-quote-char)
|
|
190
|
|
191 (define-key map "\C-m" 'isearch-exit)
|
|
192 (define-key map "\C-j" 'isearch-printing-char)
|
|
193 (define-key map "\t" 'isearch-printing-char)
|
|
194
|
|
195 (define-key map "\C-w" 'isearch-yank-word)
|
|
196 (define-key map "\C-y" 'isearch-yank-line)
|
26
|
197 (define-key map "\M-y" 'isearch-yank-kill)
|
0
|
198
|
|
199 ;; Define keys for regexp chars * ? |
|
|
200 (define-key map "*" 'isearch-*-char)
|
|
201 (define-key map "?" 'isearch-*-char)
|
|
202 (define-key map "|" 'isearch-|-char)
|
|
203
|
|
204 ;; Some bindings you may want to put in your isearch-mode-hook.
|
|
205 ;; Suggest some alternates...
|
|
206 ;; (define-key map "\C-t" 'isearch-toggle-regexp)
|
|
207 ;; (define-key map "\C-^" 'isearch-edit-string)
|
|
208
|
|
209 ;; backspace deletes, but C-h is help.
|
|
210 (define-key map 'backspace 'isearch-delete-char)
|
|
211 (define-key map '(control h) 'isearch-mode-help)
|
|
212
|
|
213 (define-key map "\M-n" 'isearch-ring-advance)
|
|
214 (define-key map "\M-p" 'isearch-ring-retreat)
|
|
215 (define-key map "\M- " 'isearch-whitespace-chars)
|
|
216 (define-key map "\M-\t" 'isearch-complete)
|
|
217
|
|
218 (define-key map 'button2 'isearch-yank-x-selection)
|
|
219
|
|
220 map)
|
|
221 "Keymap for isearch-mode.")
|
|
222
|
|
223 (defvar minibuffer-local-isearch-map
|
|
224 (let ((map (make-sparse-keymap)))
|
|
225 ;; #### - this should also be minor-mode-ified
|
|
226 (set-keymap-parents map (list minibuffer-local-map))
|
|
227 (set-keymap-name map 'minibuffer-local-isearch-map)
|
|
228
|
|
229 ;;#### This should just arrange to use the usual Emacs minibuffer histories
|
|
230 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
|
|
231 (define-key map "\M-n" 'isearch-ring-advance-edit)
|
|
232 (define-key map "\M-p" 'isearch-ring-retreat-edit)
|
|
233 (define-key map "\M-\t" 'isearch-complete-edit)
|
|
234 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
|
|
235 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
|
|
236 map)
|
|
237 "Keymap for editing isearch strings in the minibuffer.")
|
|
238
|
|
239 ;;;========================================================
|
|
240 ;; Internal variables declared globally for byte-compiler.
|
|
241 ;; These are all bound locally while editing the search string.
|
|
242
|
|
243 (defvar isearch-forward nil) ; Searching in the forward direction.
|
|
244 (defvar isearch-regexp nil) ; Searching for a regexp.
|
|
245 (defvar isearch-word nil) ; Searching for words.
|
|
246
|
|
247 (defvar isearch-cmds nil) ; Stack of search status sets.
|
|
248 (defvar isearch-string "") ; The current search string.
|
|
249 (defvar isearch-message "") ; text-char-description version of isearch-string
|
|
250
|
|
251 (defvar isearch-success t) ; Searching is currently successful.
|
|
252 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
|
|
253 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
|
|
254 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
|
|
255 (defvar isearch-barrier 0)
|
|
256 (defvar isearch-buffer nil) ; the buffer we've frobbed the keymap of
|
|
257
|
|
258 (defvar isearch-case-fold-search nil)
|
|
259
|
|
260 (defvar isearch-adjusted nil)
|
|
261 (defvar isearch-slow-terminal-mode nil)
|
|
262 ;;; If t, using a small window.
|
|
263 (defvar isearch-small-window nil)
|
|
264 (defvar isearch-opoint 0)
|
|
265 ;;; The window configuration active at the beginning of the search.
|
|
266 (defvar isearch-window-configuration nil)
|
|
267 (defvar isearch-selected-frame nil)
|
|
268
|
|
269 ;; Flag to indicate a yank occurred, so don't move the cursor.
|
|
270 (defvar isearch-yank-flag nil)
|
|
271
|
|
272 ;;; A function to be called after each input character is processed.
|
|
273 ;;; (It is not called after characters that exit the search.)
|
|
274 ;;; It is only set from an optional argument to `isearch-mode'.
|
|
275 (defvar isearch-op-fun nil)
|
|
276
|
|
277 ;;; Is isearch-mode in a recursive edit for modal searching.
|
|
278 (defvar isearch-recursive-edit nil)
|
|
279
|
|
280 ;;; Should isearch be terminated after doing one search?
|
|
281 (defvar isearch-nonincremental nil)
|
|
282
|
|
283 ;; New value of isearch-forward after isearch-edit-string.
|
|
284 (defvar isearch-new-forward nil)
|
|
285
|
|
286
|
|
287 (defvar isearch-mode-hook nil
|
|
288 "Function(s) to call after starting up an incremental search.")
|
|
289
|
|
290 (defvar isearch-mode-end-hook nil
|
|
291 "Function(s) to call after terminating an incremental search.")
|
|
292
|
|
293 ;;;==============================================================
|
|
294 ;; Minor-mode-alist changes - kind of redundant with the
|
|
295 ;; echo area, but if isearching in multiple windows, it can be useful.
|
|
296
|
|
297 (add-minor-mode 'isearch-mode 'isearch-mode)
|
|
298
|
|
299 (defvar isearch-mode nil)
|
|
300 (make-variable-buffer-local 'isearch-mode)
|
|
301
|
|
302 ;;;===============================================================
|
|
303 ;;; Entry points to isearch-mode.
|
|
304 ;;; These four functions should replace those in loaddefs.el
|
|
305 ;;; An alternative is to fset isearch-forward etc to isearch-mode,
|
|
306 ;;; and look at the last command to set the options accordingly.
|
|
307
|
|
308 (defun isearch-forward (&optional regexp-p)
|
|
309 "Do incremental search forward.
|
|
310 With a prefix argument, do an incremental regular expression search instead.
|
|
311 \\<isearch-mode-map>
|
|
312 As you type characters, they add to the search string and are found.
|
|
313 The following non-printing keys are bound in `isearch-mode-map'.
|
|
314
|
|
315 Type \\[isearch-delete-char] to cancel characters from end of search string.
|
|
316 Type \\[isearch-exit] to exit, leaving point at location found.
|
|
317 Type LFD (C-j) to match end of line.
|
|
318 Type \\[isearch-repeat-forward] to search again forward,\
|
|
319 \\[isearch-repeat-backward] to search again backward.
|
|
320 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
|
|
321 string and search for it.
|
|
322 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
|
|
323 and search for it.
|
|
324 Type \\[isearch-quote-char] to quote control character to search for it.
|
|
325 Type \\[isearch-whitespace-chars] to match all whitespace chars in regexp.
|
|
326 \\[isearch-abort] while searching or when search has failed cancels input\
|
|
327 back to what has
|
|
328 been found successfully.
|
|
329 \\[isearch-abort] when search is successful aborts and moves point to\
|
|
330 starting point.
|
|
331
|
|
332 Also supported is a search ring of the previous 16 search strings.
|
|
333 Type \\[isearch-ring-advance] to search for the next item in the search ring.
|
|
334 Type \\[isearch-ring-retreat] to search for the previous item in the search\
|
|
335 ring.
|
|
336 Type \\[isearch-complete] to complete the search string using the search ring.
|
|
337
|
|
338 The above keys are bound in the isearch-mode-map. To change the keys which
|
|
339 are special to isearch-mode, simply change the bindings in that map.
|
|
340
|
|
341 Other control and meta characters terminate the search
|
|
342 and are then executed normally (depending on `search-exit-option').
|
|
343
|
|
344 If this function is called non-interactively, it does not return to
|
|
345 the calling function until the search is done.
|
|
346
|
|
347 The bindings, more precisely:
|
|
348 \\{isearch-mode-map}"
|
|
349
|
|
350 ;; Non-standard bindings
|
|
351 ;; Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
|
|
352 ;; Type \\[isearch-edit-string] to edit the search string in the minibuffer.
|
|
353 ;; Terminate editing and return to incremental searching with CR.
|
|
354
|
26
|
355 (interactive "_P")
|
0
|
356 (isearch-mode t (not (null regexp-p)) nil (not (interactive-p))))
|
|
357
|
|
358 (defun isearch-forward-regexp ()
|
|
359 "\
|
|
360 Do incremental search forward for regular expression.
|
|
361 Like ordinary incremental search except that your input
|
|
362 is treated as a regexp. See \\[isearch-forward] for more info."
|
26
|
363 (interactive "_")
|
0
|
364 (isearch-mode t t nil (not (interactive-p))))
|
|
365
|
|
366 (defun isearch-backward (&optional regexp-p)
|
|
367 "\
|
|
368 Do incremental search backward.
|
|
369 With a prefix argument, do an incremental regular expression search instead.
|
|
370 See \\[isearch-forward] for more information."
|
26
|
371 (interactive "_P")
|
0
|
372 (isearch-mode nil (not (null regexp-p)) nil (not (interactive-p))))
|
|
373
|
|
374 (defun isearch-backward-regexp ()
|
|
375 "\
|
|
376 Do incremental search backward for regular expression.
|
|
377 Like ordinary incremental search except that your input
|
|
378 is treated as a regexp. See \\[isearch-forward] for more info."
|
26
|
379 (interactive "_")
|
0
|
380 (isearch-mode nil t nil (not (interactive-p))))
|
|
381
|
26
|
382 ;; This function is way wrong, because you can't scroll the help
|
|
383 ;; screen; as soon as you press a key, it's gone. I don't know of a
|
|
384 ;; good way to fix it, though. -hniksic
|
0
|
385 (defun isearch-mode-help ()
|
26
|
386 (interactive "_")
|
44
|
387 (let ((w (selected-window)))
|
|
388 (describe-function 'isearch-forward)
|
|
389 (select-window w))
|
0
|
390 (isearch-update))
|
|
391
|
|
392
|
|
393 ;;;==================================================================
|
|
394 ;; isearch-mode only sets up incremental search for the minor mode.
|
|
395 ;; All the work is done by the isearch-mode commands.
|
|
396
|
|
397 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
|
|
398 "Start isearch minor mode. Called by isearch-forward, etc."
|
|
399
|
|
400 (if executing-kbd-macro (setq recursive-edit nil))
|
|
401
|
|
402 (let ((inhibit-quit t)) ; don't leave things in an inconsistent state...
|
|
403
|
|
404 ;; Initialize global vars.
|
|
405 (setq isearch-buffer (current-buffer)
|
|
406 isearch-forward forward
|
|
407 isearch-regexp regexp
|
|
408 isearch-word word-p
|
|
409 isearch-op-fun op-fun
|
|
410 isearch-case-fold-search case-fold-search
|
|
411 isearch-string ""
|
|
412 isearch-message ""
|
|
413 isearch-cmds nil
|
|
414 isearch-success t
|
|
415 isearch-wrapped nil
|
|
416 isearch-barrier (point)
|
|
417 isearch-adjusted nil
|
|
418 isearch-yank-flag nil
|
|
419 isearch-invalid-regexp nil
|
|
420 isearch-slow-terminal-mode (and (<= (device-baud-rate)
|
|
421 search-slow-speed)
|
|
422 (> (window-height)
|
|
423 (* 4 search-slow-window-lines)))
|
|
424 isearch-other-end nil
|
|
425 isearch-small-window nil
|
|
426
|
|
427 isearch-opoint (point)
|
|
428 isearch-window-configuration (current-window-configuration)
|
|
429
|
|
430 ;; #### - don't do this statically: isearch-mode must be FIRST in
|
|
431 ;; the minor-mode-map-alist -- Stig
|
|
432 minor-mode-map-alist (cons (cons 'isearch-mode isearch-mode-map)
|
|
433 minor-mode-map-alist)
|
|
434 isearch-selected-frame (selected-frame)
|
|
435
|
|
436 isearch-mode (gettext " Isearch")
|
|
437 )
|
|
438
|
|
439 ;; XEmacs change: without clearing the match data, sometimes old values
|
|
440 ;; of isearch-other-end get used. Don't ask me why...
|
|
441 (store-match-data nil)
|
|
442
|
|
443 (add-hook 'pre-command-hook 'isearch-pre-command-hook)
|
|
444 (set-buffer-modified-p (buffer-modified-p)) ; update modeline
|
|
445 (isearch-push-state)
|
|
446
|
|
447 ) ; inhibit-quit is t before here
|
|
448
|
|
449 (isearch-update)
|
|
450 (run-hooks 'isearch-mode-hook)
|
|
451
|
|
452 ;; isearch-mode can be made modal (in the sense of not returning to
|
|
453 ;; the calling function until searching is completed) by entering
|
|
454 ;; a recursive-edit and exiting it when done isearching.
|
|
455 (if recursive-edit
|
|
456 (let ((isearch-recursive-edit t))
|
|
457 (recursive-edit)))
|
|
458 )
|
|
459
|
|
460
|
|
461 ;;;====================================================
|
|
462 ;; Some high level utilities. Others below.
|
|
463
|
|
464 (defun isearch-update ()
|
|
465 ;; Called after each command to update the display.
|
|
466 (if (null unread-command-event)
|
|
467 (progn
|
|
468 (if (not (input-pending-p))
|
|
469 (isearch-message))
|
|
470 (if (and isearch-slow-terminal-mode
|
|
471 (not (or isearch-small-window
|
|
472 (pos-visible-in-window-p))))
|
|
473 (let ((found-point (point)))
|
|
474 (setq isearch-small-window t)
|
|
475 (move-to-window-line 0)
|
|
476 (let ((window-min-height 1))
|
|
477 (split-window nil (if (< search-slow-window-lines 0)
|
|
478 (1+ (- search-slow-window-lines))
|
|
479 (- (window-height)
|
|
480 (1+ search-slow-window-lines)))))
|
|
481 (if (< search-slow-window-lines 0)
|
|
482 (progn (vertical-motion (- 1 search-slow-window-lines))
|
|
483 (set-window-start (next-window) (point))
|
|
484 (set-window-hscroll (next-window)
|
|
485 (window-hscroll))
|
|
486 (set-window-hscroll (selected-window) 0))
|
|
487 (other-window 1))
|
|
488 (goto-char found-point)))
|
|
489 (if isearch-other-end
|
|
490 (if (< isearch-other-end (point))
|
|
491 (isearch-highlight isearch-other-end (point))
|
|
492 (isearch-highlight (point) isearch-other-end))
|
|
493 (if (extentp isearch-extent)
|
|
494 (isearch-dehighlight nil)))
|
|
495 ))
|
|
496 (setq ;; quit-flag nil not for isearch-mode
|
|
497 isearch-adjusted nil
|
|
498 isearch-yank-flag nil)
|
|
499 )
|
|
500
|
|
501
|
|
502 (defun isearch-done ()
|
|
503 ;; Called by all commands that terminate isearch-mode.
|
|
504 (let ((inhibit-quit t)) ; danger danger!
|
|
505 (if (and isearch-buffer (buffer-live-p isearch-buffer))
|
|
506 (save-excursion
|
|
507 ;; Some loser process filter might have switched the
|
|
508 ;; window's buffer, so be sure to set these variables back
|
|
509 ;; in the buffer we frobbed them in. But only if the buffer
|
|
510 ;; is still alive.
|
|
511 (set-buffer isearch-buffer)
|
|
512 (setq minor-mode-map-alist (delq (assoc 'isearch-mode minor-mode-map-alist)
|
|
513 minor-mode-map-alist))
|
|
514 ;; Use remove-hook instead of just setting it to our saved value
|
|
515 ;; in case some process filter has created a buffer and modified
|
|
516 ;; the pre-command-hook in that buffer... yeah, this is obscure,
|
|
517 ;; and yeah, I was getting screwed by it. -jwz
|
|
518 (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
|
|
519 (set-keymap-parents isearch-mode-map nil)
|
|
520 (setq isearch-mode nil)
|
|
521 (set-buffer-modified-p (buffer-modified-p));; update modeline
|
|
522 (isearch-dehighlight t)))
|
|
523
|
|
524 ;; it's not critical that this be inside inhibit-quit, but leaving
|
|
525 ;; things in small-window-mode would be bad.
|
|
526 (let ((found-start (window-start (selected-window)))
|
|
527 (found-point (point)))
|
|
528 (cond ((eq (selected-frame) isearch-selected-frame)
|
|
529 (set-window-configuration isearch-window-configuration)
|
|
530
|
|
531 (if isearch-small-window
|
|
532 (goto-char found-point)
|
|
533 ;; Exiting the save-window-excursion clobbers
|
|
534 ;; window-start; restore it.
|
|
535 (set-window-start (selected-window) found-start t))))
|
|
536 ;; If there was movement, mark the starting position.
|
|
537 ;; Maybe should test difference between and set mark iff > threshold.
|
|
538 (if (and (buffer-live-p isearch-buffer)
|
|
539 (/= (point isearch-buffer) isearch-opoint))
|
|
540 (progn
|
|
541 (push-mark isearch-opoint t nil isearch-buffer)
|
|
542 (or executing-kbd-macro (> (minibuffer-depth) 0)
|
|
543 (message "Mark saved where search started"))))
|
|
544 )
|
|
545 (setq isearch-buffer nil)
|
|
546 ) ; inhibit-quit is t before here
|
|
547
|
|
548 (if (> (length isearch-string) 0)
|
|
549 ;; Update the ring data.
|
|
550 (if isearch-regexp
|
|
551 (if (not (setq regexp-search-ring-yank-pointer
|
|
552 (member isearch-string regexp-search-ring)))
|
|
553 (progn
|
|
554 (setq regexp-search-ring
|
|
555 (cons isearch-string regexp-search-ring)
|
|
556 regexp-search-ring-yank-pointer regexp-search-ring)
|
|
557 (if (> (length regexp-search-ring) regexp-search-ring-max)
|
|
558 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
|
|
559 nil))))
|
|
560 (if (not (setq search-ring-yank-pointer
|
|
561 ;; really need equal test instead of eq.
|
|
562 (member isearch-string search-ring)))
|
|
563 (progn
|
|
564 (setq search-ring (cons isearch-string search-ring)
|
|
565 search-ring-yank-pointer search-ring)
|
|
566 (if (> (length search-ring) search-ring-max)
|
|
567 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
|
|
568
|
|
569 (run-hooks 'isearch-mode-end-hook)
|
|
570 (if isearch-recursive-edit (exit-recursive-edit)))
|
|
571
|
|
572
|
|
573 ;;;====================================================
|
|
574 ;; Commands active while inside of the isearch minor mode.
|
|
575
|
|
576 (defun isearch-exit ()
|
|
577 "Exit search normally.
|
|
578 However, if this is the first command after starting incremental
|
|
579 search and `search-nonincremental-instead' is non-nil, do an
|
|
580 incremental search via `isearch-edit-string'."
|
|
581 (interactive)
|
|
582 (if (and search-nonincremental-instead
|
|
583 (= 0 (length isearch-string)))
|
|
584 (let ((isearch-nonincremental t))
|
|
585 (isearch-edit-string))
|
|
586 (isearch-done)))
|
|
587
|
|
588
|
|
589 (defun isearch-edit-string ()
|
|
590 "Edit the search string in the minibuffer.
|
|
591 The following additional command keys are active while editing.
|
|
592 \\<minibuffer-local-isearch-map>
|
|
593 \\[exit-minibuffer] to exit editing and resume incremental searching.
|
|
594 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
|
|
595 \\[isearch-backward-exit-minibuffer] to resume isearching backward.
|
|
596 \\[isearch-ring-advance-edit] to replace the search string with the next\
|
|
597 item in the search ring.
|
|
598 \\[isearch-ring-retreat-edit] to replace the search string with the next\
|
|
599 item in the search ring.
|
|
600 \\[isearch-complete-edit] to complete the search string from the search ring."
|
|
601
|
|
602 ;; Editing doesnt back up the search point. Should it?
|
|
603 (interactive)
|
|
604
|
|
605 (condition-case nil
|
|
606 (let ((minibuffer-local-map minibuffer-local-isearch-map)
|
|
607 isearch-nonincremental ; should search nonincrementally?
|
|
608 isearch-new-string
|
|
609 isearch-new-message
|
|
610 (isearch-new-forward isearch-forward)
|
|
611
|
|
612 ;; Locally bind all isearch global variables to protect them
|
|
613 ;; from recursive isearching.
|
|
614 (isearch-string isearch-string)
|
|
615 (isearch-message isearch-message)
|
|
616 (isearch-forward isearch-forward) ; set by commands below.
|
|
617
|
|
618 (isearch-forward isearch-forward)
|
|
619 (isearch-regexp isearch-regexp)
|
|
620 (isearch-word isearch-word)
|
|
621 (isearch-op-fun isearch-op-fun)
|
|
622 (isearch-cmds isearch-cmds)
|
|
623 (isearch-success isearch-success)
|
|
624 (isearch-wrapped isearch-wrapped)
|
|
625 (isearch-barrier isearch-barrier)
|
|
626 (isearch-adjusted isearch-adjusted)
|
|
627 (isearch-yank-flag isearch-yank-flag)
|
|
628 (isearch-invalid-regexp isearch-invalid-regexp)
|
|
629 (isearch-other-end isearch-other-end)
|
|
630 (isearch-opoint isearch-opoint)
|
|
631 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
|
|
632 (isearch-small-window isearch-small-window)
|
|
633 (isearch-recursive-edit isearch-recursive-edit)
|
|
634 (isearch-window-configuration (current-window-configuration))
|
|
635 (isearch-selected-frame (selected-frame))
|
|
636 )
|
|
637 ;; Actually terminate isearching until editing is done.
|
|
638 ;; This is so that the user can do anything without failure,
|
|
639 ;; like switch buffers and start another isearch, and return.
|
|
640 ;; (condition-case nil
|
|
641 (isearch-done)
|
|
642 ;;#### What does this mean? There is no such condition!
|
|
643 ;; (exit nil)) ; was recursive editing
|
|
644
|
|
645 (unwind-protect
|
|
646 (let ((prompt (isearch-message-prefix nil t))
|
|
647 event)
|
|
648 ;; If the first character the user types when we prompt them
|
|
649 ;; for a string is the yank-word character, then go into
|
|
650 ;; word-search mode. Otherwise unread that character and
|
|
651 ;; read a string the normal way.
|
|
652 (let ((cursor-in-echo-area t))
|
|
653 (message "%s" prompt)
|
|
654 (setq event (next-command-event))
|
|
655 (if (eq 'isearch-yank-word
|
|
656 (lookup-key isearch-mode-map (vector event)))
|
|
657 (setq isearch-word t)
|
|
658 (setq unread-command-event event)))
|
|
659 (setq isearch-new-string
|
|
660 ;; (if (fboundp 'gmhist-old-read-from-minibuffer)
|
|
661 ;; ;; Eschew gmhist crockery
|
|
662 ;; (gmhist-old-read-from-minibuffer prompt isearch-string)
|
|
663 (read-string
|
|
664 prompt isearch-string
|
|
665 't ;does its own history (but shouldn't)
|
|
666 ;; (if isearch-regexp
|
|
667 ;; ;; The search-rings aren't exactly minibuffer
|
|
668 ;; ;; histories, but they are close enough
|
|
669 ;; (cons 'regexp-search-ring
|
|
670 ;; (- (length regexp-search-ring-yank-pointer)
|
|
671 ;; (length regexp-search-ring)))
|
|
672 ;; (cons 'search-ring
|
|
673 ;; (- (length search-ring-yank-pointer)
|
|
674 ;; (length search-ring))))
|
|
675 )
|
|
676 ;; )
|
|
677 isearch-new-message (mapconcat
|
|
678 'isearch-text-char-description
|
|
679 isearch-new-string ""))
|
|
680 )
|
|
681 ;; Always resume isearching by restarting it.
|
|
682 (isearch-mode isearch-forward
|
|
683 isearch-regexp
|
|
684 isearch-op-fun
|
|
685 isearch-recursive-edit
|
|
686 isearch-word)
|
|
687 )
|
|
688
|
|
689 ;; Copy new values in outer locals to isearch globals
|
|
690 (setq isearch-string isearch-new-string
|
|
691 isearch-message isearch-new-message
|
|
692 isearch-forward isearch-new-forward)
|
|
693
|
|
694 ;; Empty isearch-string means use default.
|
|
695 (if (= 0 (length isearch-string))
|
|
696 (setq isearch-string (if isearch-regexp search-last-regexp
|
|
697 search-last-string))
|
|
698 ;; Set last search string now so it is set even if we fail.
|
|
699 (if search-last-regexp
|
|
700 (setq search-last-regexp isearch-string)
|
|
701 (setq search-last-string isearch-string)))
|
|
702
|
|
703 ;; Reinvoke the pending search.
|
|
704 (isearch-push-state)
|
|
705 (isearch-search)
|
|
706 (isearch-update)
|
|
707 (if isearch-nonincremental (isearch-done)))
|
|
708
|
|
709 (quit ; handle abort-recursive-edit
|
|
710 (isearch-abort) ;; outside of let to restore outside global values
|
|
711 )))
|
|
712
|
|
713 (defun isearch-nonincremental-exit-minibuffer ()
|
|
714 (interactive)
|
|
715 (setq isearch-nonincremental t)
|
|
716 (exit-minibuffer))
|
|
717
|
|
718 (defun isearch-forward-exit-minibuffer ()
|
|
719 (interactive)
|
|
720 (setq isearch-new-forward t)
|
|
721 (exit-minibuffer))
|
|
722
|
|
723 (defun isearch-reverse-exit-minibuffer ()
|
|
724 (interactive)
|
|
725 (setq isearch-new-forward nil)
|
|
726 (exit-minibuffer))
|
|
727
|
|
728
|
|
729 (defun isearch-abort ()
|
|
730 "Quit incremental search mode if searching is successful, signalling quit.
|
|
731 Otherwise, revert to previous successful search and continue searching.
|
|
732 Use `isearch-exit' to quit without signalling."
|
|
733 (interactive)
|
|
734 ;; (ding) signal instead below, if quiting
|
|
735 (discard-input)
|
|
736 (if isearch-success
|
|
737 ;; If search is successful, move back to starting point
|
|
738 ;; and really do quit.
|
|
739 (progn (goto-char isearch-opoint)
|
|
740 (isearch-done) ; exit isearch
|
|
741 (signal 'quit '(isearch))) ; and pass on quit signal
|
|
742 ;; If search is failing, rub out until it is once more successful.
|
|
743 (while (not isearch-success) (isearch-pop-state))
|
|
744 (isearch-update)))
|
|
745
|
|
746
|
|
747 (defun isearch-repeat (direction)
|
|
748 ;; Utility for isearch-repeat-forward and -backward.
|
|
749 (if (eq isearch-forward (eq direction 'forward))
|
|
750 ;; C-s in forward or C-r in reverse.
|
|
751 (if (equal isearch-string "")
|
|
752 ;; If search string is empty, use last one.
|
|
753 (setq isearch-string
|
|
754 (or (if isearch-regexp
|
|
755 (if regexp-search-ring-yank-pointer
|
|
756 (car regexp-search-ring-yank-pointer)
|
|
757 (car regexp-search-ring))
|
|
758 (if search-ring-yank-pointer
|
|
759 (car search-ring-yank-pointer)
|
|
760 (car search-ring)))
|
|
761 "")
|
|
762 isearch-message
|
|
763 (mapconcat 'isearch-text-char-description
|
|
764 isearch-string ""))
|
|
765 ;; If already have what to search for, repeat it.
|
|
766 (or isearch-success
|
|
767 (progn
|
|
768
|
|
769 (goto-char (if isearch-forward (point-min) (point-max)))
|
|
770 (setq isearch-wrapped t))))
|
|
771 ;; C-s in reverse or C-r in forward, change direction.
|
|
772 (setq isearch-forward (not isearch-forward)))
|
|
773
|
|
774 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
|
|
775 (setq isearch-success t)
|
|
776 (or (equal isearch-string "")
|
|
777 ;; If repeating a search that found
|
|
778 ;; an empty string, ensure we advance.
|
|
779 (if (equal (match-end 0) (match-beginning 0))
|
|
780 (if (if isearch-forward (eobp) (bobp))
|
|
781 ;; nowhere to advance to, so fail (and wrap next time)
|
|
782 (progn
|
|
783 (setq isearch-success nil)
|
|
784 (and executing-kbd-macro
|
|
785 (not defining-kbd-macro)
|
|
786 (isearch-done))
|
|
787 (ding nil 'isearch-failed))
|
|
788 (forward-char (if isearch-forward 1 -1))
|
|
789 (isearch-search))
|
|
790 (isearch-search)))
|
|
791 (isearch-push-state)
|
|
792 (isearch-update))
|
|
793
|
|
794 (defun isearch-repeat-forward ()
|
|
795 "Repeat incremental search forwards."
|
|
796 (interactive)
|
|
797 (isearch-repeat 'forward))
|
|
798
|
|
799 (defun isearch-repeat-backward ()
|
|
800 "Repeat incremental search backwards."
|
|
801 (interactive)
|
|
802 (isearch-repeat 'backward))
|
|
803
|
|
804 (defun isearch-toggle-regexp ()
|
|
805 "Toggle regexp searching on or off."
|
|
806 ;; The status stack is left unchanged.
|
|
807 (interactive)
|
|
808 (setq isearch-regexp (not isearch-regexp))
|
|
809 (if isearch-regexp (setq isearch-word nil))
|
|
810 (isearch-update))
|
|
811
|
|
812 (defun isearch-toggle-case-fold ()
|
|
813 "Toggle case folding in searching on or off."
|
|
814 (interactive)
|
|
815 (setq isearch-case-fold-search
|
|
816 (if isearch-case-fold-search nil 'yes))
|
|
817 (message "%s%s [case %ssensitive]"
|
|
818 (isearch-message-prefix)
|
|
819 isearch-message
|
|
820 (if isearch-case-fold-search "in" ""))
|
|
821 (setq isearch-adjusted t)
|
|
822 (sit-for 1)
|
|
823 (isearch-update))
|
|
824
|
|
825 (defun isearch-delete-char ()
|
|
826 "Discard last input item and move point back.
|
|
827 If no previous match was done, just beep."
|
|
828 (interactive)
|
|
829 (if (null (cdr isearch-cmds))
|
|
830 (ding nil 'isearch-quit)
|
|
831 (isearch-pop-state))
|
|
832 (isearch-update))
|
|
833
|
|
834
|
|
835 (defun isearch-yank (chunk)
|
26
|
836 ;; Helper for isearch-yank-* functions. CHUNK can be a string or a
|
|
837 ;; function.
|
0
|
838 (let ((word (if (stringp chunk)
|
|
839 chunk
|
|
840 (save-excursion
|
|
841 (and (not isearch-forward) isearch-other-end
|
|
842 (goto-char isearch-other-end))
|
|
843 (buffer-substring
|
|
844 (point)
|
|
845 (save-excursion
|
|
846 (funcall chunk)
|
|
847 (point)))))))
|
|
848 ;; if configured so that typing upper-case characters turns off case
|
|
849 ;; folding, then downcase the string so that yanking an upper-case
|
|
850 ;; word doesn't mess with case-foldedness.
|
|
851 (if (and search-caps-disable-folding isearch-case-fold-search)
|
|
852 (setq word (downcase word)))
|
|
853 (if isearch-regexp (setq word (regexp-quote word)))
|
|
854 (setq isearch-string (concat isearch-string word)
|
|
855 isearch-message
|
|
856 (concat isearch-message
|
|
857 (mapconcat 'isearch-text-char-description
|
|
858 word ""))
|
|
859 ;; Don't move cursor in reverse search.
|
|
860 isearch-yank-flag t))
|
|
861 (isearch-search-and-update))
|
|
862
|
|
863
|
|
864 (defun isearch-yank-word ()
|
|
865 "Pull next word from buffer into search string."
|
|
866 (interactive)
|
|
867 (isearch-yank (function (lambda () (forward-word 1)))))
|
|
868
|
|
869 (defun isearch-yank-line ()
|
|
870 "Pull rest of line from buffer into search string."
|
|
871 (interactive)
|
|
872 (isearch-yank 'end-of-line))
|
|
873
|
26
|
874 (defun isearch-yank-kill ()
|
|
875 "Pull rest of line from kill ring into search string."
|
|
876 (interactive)
|
|
877 (isearch-yank (current-kill 0)))
|
|
878
|
0
|
879 (defun isearch-yank-sexp ()
|
|
880 "Pull next expression from buffer into search string."
|
|
881 (interactive)
|
|
882 (isearch-yank 'forward-sexp))
|
|
883
|
|
884 (defun isearch-yank-x-selection ()
|
|
885 "Pull the current X selection into the search string."
|
|
886 (interactive)
|
|
887 (isearch-yank (x-get-selection)))
|
|
888
|
|
889 (defun isearch-yank-x-clipboard ()
|
|
890 "Pull the current X clipboard selection into the search string."
|
|
891 (interactive)
|
|
892 (isearch-yank (x-get-clipboard)))
|
|
893
|
|
894 (defun isearch-search-and-update ()
|
|
895 ;; Do the search and update the display.
|
|
896 (if (and (not isearch-success)
|
|
897 ;; unsuccessful regexp search may become
|
|
898 ;; successful by addition of characters which
|
|
899 ;; make isearch-string valid
|
|
900 (not isearch-regexp))
|
|
901 nil
|
|
902 ;; In reverse search, adding stuff at
|
|
903 ;; the end may cause zero or many more chars to be
|
|
904 ;; matched, in the string following point.
|
|
905 ;; Allow all those possibilities without moving point as
|
|
906 ;; long as the match does not extend past search origin.
|
|
907 (if (and (not isearch-forward) (not isearch-adjusted)
|
|
908 (condition-case ()
|
|
909 (looking-at (if isearch-regexp isearch-string
|
|
910 (regexp-quote isearch-string)))
|
|
911 (error nil))
|
|
912 (or isearch-yank-flag
|
|
913 (<= (match-end 0)
|
|
914 (min isearch-opoint isearch-barrier))))
|
|
915 (setq isearch-success t
|
|
916 isearch-invalid-regexp nil
|
|
917 isearch-other-end (match-end 0))
|
|
918 ;; Not regexp, not reverse, or no match at point.
|
|
919 (if (and isearch-other-end (not isearch-adjusted))
|
|
920 (goto-char (if isearch-forward isearch-other-end
|
|
921 (min isearch-opoint
|
|
922 isearch-barrier
|
|
923 (1+ isearch-other-end)))))
|
|
924 (isearch-search)
|
|
925 ))
|
|
926 (isearch-push-state)
|
|
927 (if isearch-op-fun (funcall isearch-op-fun))
|
|
928 (isearch-update))
|
|
929
|
|
930
|
|
931 ;; *, ?, and | chars can make a regexp more liberal.
|
|
932 ;; They can make a regexp match sooner
|
|
933 ;; or make it succeed instead of failing.
|
|
934 ;; So go back to place last successful search started
|
|
935 ;; or to the last ^S/^R (barrier), whichever is nearer.
|
|
936
|
|
937 (defun isearch-*-char ()
|
|
938 "Handle * and ? specially in regexps."
|
|
939 (interactive)
|
|
940 (if isearch-regexp
|
|
941
|
|
942 (progn
|
|
943 (setq isearch-adjusted t)
|
|
944 (let ((cs (nth (if isearch-forward
|
|
945 5 ; isearch-other-end
|
|
946 2) ; saved (point)
|
|
947 (car (cdr isearch-cmds)))))
|
|
948 ;; (car isearch-cmds) is after last search;
|
|
949 ;; (car (cdr isearch-cmds)) is from before it.
|
|
950 (setq cs (or cs isearch-barrier))
|
|
951 (goto-char
|
|
952 (if isearch-forward
|
|
953 (max cs isearch-barrier)
|
|
954 (min cs isearch-barrier))))))
|
|
955 (isearch-process-search-char last-command-event))
|
|
956
|
|
957
|
|
958
|
|
959 (defun isearch-|-char ()
|
|
960 "If in regexp search, jump to the barrier."
|
|
961 (interactive)
|
|
962 (if isearch-regexp
|
|
963 (progn
|
|
964 (setq isearch-adjusted t)
|
|
965 (goto-char isearch-barrier)))
|
|
966 (isearch-process-search-char last-command-event))
|
|
967
|
|
968 (defun isearch-quote-char ()
|
|
969 "Quote special characters for incremental search."
|
|
970 (interactive)
|
|
971 (isearch-process-search-char (read-quoted-char (isearch-message t))))
|
|
972
|
|
973
|
|
974 (defun isearch-return-char ()
|
|
975 "Convert return into newline for incremental search.
|
|
976 Obsolete."
|
|
977 (interactive)
|
|
978 (isearch-process-search-char ?\n))
|
|
979
|
|
980
|
|
981 (defun isearch-printing-char ()
|
|
982 "Any other printing character => add it to the search string and search."
|
|
983 (interactive)
|
|
984 (isearch-process-search-char last-command-event))
|
|
985
|
|
986
|
|
987 (defun isearch-whitespace-chars ()
|
|
988 "Match all whitespace chars, if in regexp mode."
|
|
989 (interactive)
|
|
990 (if (and isearch-regexp search-whitespace-regexp)
|
|
991 (isearch-process-search-string search-whitespace-regexp " ")
|
|
992 (beep)
|
|
993 (isearch-process-search-char ?\ )
|
|
994 ; (if isearch-word
|
|
995 ; nil
|
|
996 ; (setq isearch-word t)
|
|
997 ; (goto-char isearch-other-end)
|
|
998 ; (isearch-process-search-char ?\ ))
|
|
999 ))
|
|
1000
|
|
1001 (defun isearch-process-search-char (char)
|
|
1002 ;; Append the char to the search string, update the message and re-search.
|
|
1003 (isearch-process-search-string (isearch-char-to-string char)
|
|
1004 (isearch-text-char-description char)))
|
|
1005
|
|
1006 (defun isearch-process-search-string (string message)
|
|
1007 (setq isearch-string (concat isearch-string string)
|
|
1008 isearch-message (concat isearch-message message))
|
|
1009 (isearch-search-and-update))
|
|
1010
|
|
1011
|
|
1012 ;;===========================================================
|
|
1013 ;; Search Ring
|
|
1014
|
|
1015 (defvar search-ring-update nil
|
|
1016 "*Non-nil if advancing or retreating in the search ring should cause search.
|
|
1017 Default nil means edit the string from the search ring first.")
|
|
1018
|
|
1019 (defun isearch-ring-adjust1 (advance)
|
|
1020 ;; Helper for isearch-ring-adjust
|
|
1021 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
|
|
1022 (length (length ring))
|
|
1023 (yank-pointer-name (if isearch-regexp
|
|
1024 'regexp-search-ring-yank-pointer
|
|
1025 'search-ring-yank-pointer))
|
|
1026 (yank-pointer (eval yank-pointer-name)))
|
|
1027 (if (zerop length)
|
|
1028 ()
|
|
1029 (set yank-pointer-name
|
|
1030 (setq yank-pointer
|
|
1031 (nthcdr (% (+ (- length (length yank-pointer))
|
|
1032 (if advance (1- length) 1))
|
|
1033 length) ring)))
|
|
1034 (setq isearch-string (car yank-pointer)
|
|
1035 isearch-message (mapconcat 'isearch-text-char-description
|
|
1036 isearch-string "")))))
|
|
1037
|
|
1038 (defun isearch-ring-adjust (advance)
|
|
1039 ;; Helper for isearch-ring-advance and isearch-ring-retreat
|
|
1040 (if (cdr isearch-cmds) ;; is there more than one thing on stack?
|
|
1041 (isearch-pop-state))
|
|
1042 (isearch-ring-adjust1 advance)
|
|
1043 (isearch-push-state)
|
|
1044 (if search-ring-update
|
|
1045 (progn
|
|
1046 (isearch-search)
|
|
1047 (isearch-update))
|
|
1048 (isearch-edit-string)
|
|
1049 ))
|
|
1050
|
|
1051 (defun isearch-ring-advance ()
|
|
1052 "Advance to the next search string in the ring."
|
|
1053 ;; This could be more general to handle a prefix arg, but who would use it.
|
|
1054 (interactive)
|
|
1055 (isearch-ring-adjust 'advance))
|
|
1056
|
|
1057 (defun isearch-ring-retreat ()
|
|
1058 "Retreat to the previous search string in the ring."
|
|
1059 (interactive)
|
|
1060 (isearch-ring-adjust nil))
|
|
1061
|
|
1062 (defun isearch-ring-adjust-edit (advance)
|
|
1063 "Use the next or previous search string in the ring while in minibuffer."
|
|
1064 (isearch-ring-adjust1 advance)
|
|
1065 (erase-buffer)
|
|
1066 (insert isearch-string))
|
|
1067
|
|
1068 (defun isearch-ring-advance-edit ()
|
|
1069 (interactive)
|
|
1070 (isearch-ring-adjust-edit 'advance))
|
|
1071
|
|
1072 (defun isearch-ring-retreat-edit ()
|
|
1073 "Retreat to the previous search string in the ring while in the minibuffer."
|
|
1074 (interactive)
|
|
1075 (isearch-ring-adjust-edit nil))
|
|
1076
|
|
1077
|
|
1078 (defun isearch-complete1 ()
|
|
1079 ;; Helper for isearch-complete and isearch-complete-edit
|
|
1080 ;; Return t if completion OK,
|
|
1081 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
|
|
1082 (alist (mapcar (function (lambda (string) (list string))) ring))
|
|
1083 (completion-ignore-case case-fold-search)
|
|
1084 (completion (try-completion isearch-string alist))
|
|
1085 )
|
|
1086 (cond
|
|
1087 ((eq completion t)
|
|
1088 ;; isearch-string stays the same
|
|
1089 t)
|
|
1090 ((or completion ; not nil, must be a string
|
|
1091 (= 0 (length isearch-string))) ; shouldnt have to say this
|
|
1092 (if (equal completion isearch-string) ;; no extension?
|
|
1093 (if completion-auto-help
|
|
1094 (with-output-to-temp-buffer "*Isearch completions*"
|
|
1095 (display-completion-list
|
|
1096 (all-completions isearch-string alist))))
|
|
1097 (setq isearch-string completion))
|
|
1098 t)
|
|
1099 (t
|
|
1100 (temp-minibuffer-message "No completion")
|
|
1101 nil))))
|
|
1102
|
|
1103 (defun isearch-complete ()
|
|
1104 "Complete the search string from the strings on the search ring.
|
|
1105 The completed string is then editable in the minibuffer.
|
|
1106 If there is no completion possible, say so and continue searching."
|
|
1107 (interactive)
|
|
1108 (if (isearch-complete1)
|
|
1109 (isearch-edit-string)
|
|
1110 ;; else
|
|
1111 (sit-for 1)
|
|
1112 (isearch-update)))
|
|
1113
|
|
1114 (defun isearch-complete-edit ()
|
|
1115 "Same as `isearch-complete' except in the minibuffer."
|
|
1116 (interactive)
|
|
1117 (setq isearch-string (buffer-string))
|
|
1118 (if (isearch-complete1)
|
|
1119 (progn
|
|
1120 (erase-buffer)
|
|
1121 (insert isearch-string))))
|
|
1122
|
|
1123
|
|
1124 ;;;==============================================================
|
|
1125 ;; The search status stack (and isearch window-local variables, not used).
|
|
1126
|
|
1127 (defun isearch-top-state ()
|
|
1128 ;; (fetch-window-local-variables)
|
|
1129 (let ((cmd (car isearch-cmds)))
|
|
1130 (setq isearch-string (car cmd)
|
|
1131 isearch-message (car (cdr cmd))
|
|
1132 isearch-success (nth 3 cmd)
|
|
1133 isearch-forward (nth 4 cmd)
|
|
1134 isearch-other-end (nth 5 cmd)
|
|
1135 isearch-invalid-regexp (nth 6 cmd)
|
|
1136 isearch-wrapped (nth 7 cmd)
|
|
1137 isearch-barrier (nth 8 cmd))
|
|
1138 (goto-char (car (cdr (cdr cmd))))))
|
|
1139
|
|
1140 (defun isearch-pop-state ()
|
|
1141 ;; (fetch-window-local-variables)
|
|
1142 (setq isearch-cmds (cdr isearch-cmds))
|
|
1143 (isearch-top-state)
|
|
1144 )
|
|
1145
|
|
1146 (defun isearch-push-state ()
|
|
1147 (setq isearch-cmds
|
|
1148 (cons (list isearch-string isearch-message (point)
|
|
1149 isearch-success isearch-forward isearch-other-end
|
|
1150 isearch-invalid-regexp isearch-wrapped isearch-barrier)
|
|
1151 isearch-cmds)))
|
|
1152
|
|
1153
|
|
1154 ;;;==================================================================
|
|
1155 ;; Message string
|
|
1156
|
|
1157 (defun isearch-message (&optional c-q-hack ellipsis)
|
|
1158 ;; Generate and print the message string.
|
|
1159 (let ((cursor-in-echo-area ellipsis)
|
|
1160 (m (concat
|
|
1161 (isearch-message-prefix c-q-hack)
|
|
1162 isearch-message
|
|
1163 (isearch-message-suffix c-q-hack)
|
|
1164 )))
|
|
1165 (if c-q-hack m (message "%s" m))))
|
|
1166
|
|
1167 (defun isearch-message-prefix (&optional c-q-hack nonincremental)
|
|
1168 ;; If about to search, and previous search regexp was invalid,
|
|
1169 ;; check that it still is. If it is valid now,
|
|
1170 ;; let the message we display while searching say that it is valid.
|
|
1171 (and isearch-invalid-regexp
|
|
1172 (condition-case ()
|
|
1173 (progn (re-search-forward isearch-string (point) t)
|
|
1174 (setq isearch-invalid-regexp nil))
|
|
1175 (error nil)))
|
|
1176 ;; #### - Yo! Emacs assembles strings all over the place, they can't all
|
|
1177 ;; be internationalized in the manner proposed below... Add an explicit
|
|
1178 ;; call to `gettext' and have the string snarfer pluck the english
|
|
1179 ;; strings out of the comment below. XEmacs is on a purespace diet! -Stig
|
|
1180 (let ((m (concat (if isearch-success nil "failing ")
|
|
1181 (if isearch-wrapped "wrapped ")
|
|
1182 (if isearch-word "word ")
|
|
1183 (if isearch-regexp "regexp ")
|
|
1184 (if nonincremental "search" "I-search")
|
|
1185 (if isearch-forward nil " backward")
|
|
1186 ": "
|
|
1187 )))
|
|
1188 (aset m 0 (upcase (aref m 0)))
|
|
1189 (gettext m)))
|
|
1190
|
|
1191 (defun isearch-message-suffix (&optional c-q-hack)
|
|
1192 (concat (if c-q-hack "^Q" "")
|
|
1193 (if isearch-invalid-regexp
|
|
1194 (concat " [" isearch-invalid-regexp "]")
|
|
1195 "")))
|
|
1196
|
|
1197 ;;;;; #### - yuck...this is soooo lame. Is this really worth 4k of purespace???
|
|
1198 ;;;
|
|
1199 ;;;(let ((i (logior (if isearch-success 32 0)
|
|
1200 ;;; (if isearch-wrapped 16 0)
|
|
1201 ;;; (if isearch-word 8 0)
|
|
1202 ;;; (if isearch-regexp 4 0)
|
|
1203 ;;; (if nonincremental 2 0)
|
|
1204 ;;; (if isearch-forward 1 0))))
|
|
1205 ;;; (cond
|
|
1206 ;;; ((= i 63) (gettext "Wrapped word regexp search: ")) ; 111111
|
|
1207 ;;; ((= i 62) (gettext "Wrapped word regexp search backward: ")) ; 111110
|
|
1208 ;;; ((= i 61) (gettext "Wrapped word regexp I-search: ")) ; 111101
|
|
1209 ;;; ((= i 60) (gettext "Wrapped word regexp I-search backward: ")) ; 111100
|
|
1210 ;;; ((= i 59) (gettext "Wrapped word search: ")) ; 111011
|
|
1211 ;;; ((= i 58) (gettext "Wrapped word search backward: ")) ; 111010
|
|
1212 ;;; ((= i 57) (gettext "Wrapped word I-search: ")) ; 111001
|
|
1213 ;;; ((= i 56) (gettext "Wrapped word I-search backward: ")) ; 111000
|
|
1214 ;;; ((= i 55) (gettext "Wrapped regexp search: ")) ; 110111
|
|
1215 ;;; ((= i 54) (gettext "Wrapped regexp search backward: ")) ; 110110
|
|
1216 ;;; ((= i 53) (gettext "Wrapped regexp I-search: ")) ; 110101
|
|
1217 ;;; ((= i 52) (gettext "Wrapped regexp I-search backward: ")) ; 110100
|
|
1218 ;;; ((= i 51) (gettext "Wrapped search: ")) ; 110011
|
|
1219 ;;; ((= i 50) (gettext "Wrapped search backward: ")) ; 110010
|
|
1220 ;;; ((= i 49) (gettext "Wrapped I-search: ")) ; 110001
|
|
1221 ;;; ((= i 48) (gettext "Wrapped I-search backward: ")) ; 110000
|
|
1222 ;;; ((= i 47) (gettext "Word regexp search: ")) ; 101111
|
|
1223 ;;; ((= i 46) (gettext "Word regexp search backward: ")) ; 101110
|
|
1224 ;;; ((= i 45) (gettext "Word regexp I-search: ")) ; 101101
|
|
1225 ;;; ((= i 44) (gettext "Word regexp I-search backward: ")) ; 101100
|
|
1226 ;;; ((= i 43) (gettext "Word search: ")) ; 101011
|
|
1227 ;;; ((= i 42) (gettext "Word search backward: ")) ; 101010
|
|
1228 ;;; ((= i 41) (gettext "Word I-search: ")) ; 101001
|
|
1229 ;;; ((= i 40) (gettext "Word I-search backward: ")) ; 101000
|
|
1230 ;;; ((= i 39) (gettext "Regexp search: ")) ; 100111
|
|
1231 ;;; ((= i 38) (gettext "Regexp search backward: ")) ; 100110
|
|
1232 ;;; ((= i 37) (gettext "Regexp I-search: ")) ; 100101
|
|
1233 ;;; ((= i 36) (gettext "Regexp I-search backward: ")) ; 100100
|
|
1234 ;;; ((= i 35) (gettext "Search: ")) ; 100011
|
|
1235 ;;; ((= i 34) (gettext "Search backward: ")) ; 100010
|
|
1236 ;;; ((= i 33) (gettext "I-search: ")) ; 100001
|
|
1237 ;;; ((= i 32) (gettext "I-search backward: ")) ; 100000
|
|
1238 ;;; ((= i 31) (gettext "Failing wrapped word regexp search: ")) ; 011111
|
|
1239 ;;; ((= i 30) (gettext "Failing wrapped word regexp search backward: ")) ; 011110
|
|
1240 ;;; ((= i 29) (gettext "Failing wrapped word regexp I-search: ")) ; 011101
|
|
1241 ;;; ((= i 28) (gettext "Failing wrapped word regexp I-search backward: ")) ; 011100
|
|
1242 ;;; ((= i 27) (gettext "Failing wrapped word search: ")) ; 011011
|
|
1243 ;;; ((= i 26) (gettext "Failing wrapped word search backward: ")) ; 011010
|
|
1244 ;;; ((= i 25) (gettext "Failing wrapped word I-search: ")) ; 011001
|
|
1245 ;;; ((= i 24) (gettext "Failing wrapped word I-search backward: ")) ; 011000
|
|
1246 ;;; ((= i 23) (gettext "Failing wrapped regexp search: ")) ; 010111
|
|
1247 ;;; ((= i 22) (gettext "Failing wrapped regexp search backward: ")) ; 010110
|
|
1248 ;;; ((= i 21) (gettext "Failing wrapped regexp I-search: ")) ; 010101
|
|
1249 ;;; ((= i 20) (gettext "Failing wrapped regexp I-search backward: ")) ; 010100
|
|
1250 ;;; ((= i 19) (gettext "Failing wrapped search: ")) ; 010011
|
|
1251 ;;; ((= i 18) (gettext "Failing wrapped search backward: ")) ; 010010
|
|
1252 ;;; ((= i 17) (gettext "Failing wrapped I-search: ")) ; 010001
|
|
1253 ;;; ((= i 16) (gettext "Failing wrapped I-search backward: ")) ; 010000
|
|
1254 ;;; ((= i 15) (gettext "Failing word regexp search: ")) ; 001111
|
|
1255 ;;; ((= i 14) (gettext "Failing word regexp search backward: ")) ; 001110
|
|
1256 ;;; ((= i 13) (gettext "Failing word regexp I-search: ")) ; 001101
|
|
1257 ;;; ((= i 12) (gettext "Failing word regexp I-search backward: ")) ; 001100
|
|
1258 ;;; ((= i 11) (gettext "Failing word search: ")) ; 001011
|
|
1259 ;;; ((= i 10) (gettext "Failing word search backward: ")) ; 001010
|
|
1260 ;;; ((= i 9) (gettext "Failing word I-search: ")) ; 001001
|
|
1261 ;;; ((= i 8) (gettext "Failing word I-search backward: ")) ; 001000
|
|
1262 ;;; ((= i 7) (gettext "Failing regexp search: ")) ; 000111
|
|
1263 ;;; ((= i 6) (gettext "Failing regexp search backward: ")) ; 000110
|
|
1264 ;;; ((= i 5) (gettext "Failing regexp I-search: ")) ; 000101
|
|
1265 ;;; ((= i 4) (gettext "Failing regexp I-search backward: ")) ; 000100
|
|
1266 ;;; ((= i 3) (gettext "Failing search: ")) ; 000011
|
|
1267 ;;; ((= i 2) (gettext "Failing search backward: ")) ; 000010
|
|
1268 ;;; ((= i 1) (gettext "Failing I-search: ")) ; 000001
|
|
1269 ;;; ((= i 0) (gettext "Failing I-search backward: ")) ; 000000
|
|
1270 ;;; (t (error "Something's rotten")))))
|
|
1271
|
|
1272
|
|
1273 ;;;========================================================
|
|
1274 ;;; Exiting
|
|
1275
|
|
1276 (put 'isearch-printing-char 'isearch-command t)
|
|
1277 (put 'isearch-return-char 'isearch-command t)
|
|
1278 (put 'isearch-repeat-forward 'isearch-command t)
|
|
1279 (put 'isearch-repeat-backward 'isearch-command t)
|
|
1280 (put 'isearch-delete-char 'isearch-command t)
|
|
1281 (put 'isearch-abort 'isearch-command t)
|
|
1282 (put 'isearch-quote-char 'isearch-command t)
|
|
1283 (put 'isearch-exit 'isearch-command t)
|
|
1284 (put 'isearch-printing-char 'isearch-command t)
|
|
1285 (put 'isearch-printing-char 'isearch-command t)
|
|
1286 (put 'isearch-yank-word 'isearch-command t)
|
|
1287 (put 'isearch-yank-line 'isearch-command t)
|
26
|
1288 (put 'isearch-yank-kill 'isearch-command t)
|
0
|
1289 (put 'isearch-yank-sexp 'isearch-command t)
|
|
1290 (put 'isearch-*-char 'isearch-command t)
|
|
1291 (put 'isearch-*-char 'isearch-command t)
|
|
1292 (put 'isearch-|-char 'isearch-command t)
|
|
1293 (put 'isearch-toggle-regexp 'isearch-command t)
|
|
1294 (put 'isearch-toggle-case-fold 'isearch-command t)
|
|
1295 (put 'isearch-edit-string 'isearch-command t)
|
|
1296 (put 'isearch-mode-help 'isearch-command t)
|
|
1297 (put 'isearch-ring-advance 'isearch-command t)
|
|
1298 (put 'isearch-ring-retreat 'isearch-command t)
|
|
1299 (put 'isearch-ring-advance-edit 'isearch-command t)
|
|
1300 (put 'isearch-ring-retreat-edit 'isearch-command t)
|
|
1301 (put 'isearch-whitespace-chars 'isearch-command t)
|
|
1302 (put 'isearch-complete 'isearch-command t)
|
|
1303 (put 'isearch-complete-edit 'isearch-command t)
|
|
1304 (put 'isearch-edit-string 'isearch-command t)
|
|
1305 (put 'isearch-toggle-regexp 'isearch-command t)
|
|
1306 (put 'isearch-forward-exit-minibuffer 'isearch-command t)
|
|
1307 (put 'isearch-reverse-exit-minibuffer 'isearch-command t)
|
|
1308 (put 'isearch-nonincremental-exit-minibuffer 'isearch-command t)
|
|
1309 (put 'isearch-yank-x-selection 'isearch-command t)
|
|
1310 (put 'isearch-yank-x-clipboard 'isearch-command t)
|
|
1311
|
|
1312 ;; scrolling the scrollbar should not terminate isearch.
|
|
1313
|
|
1314 ;; vertical scrollbar:
|
|
1315 (put 'scrollbar-line-up 'isearch-command t)
|
|
1316 (put 'scrollbar-line-down 'isearch-command t)
|
|
1317 (put 'scrollbar-page-up 'isearch-command t)
|
|
1318 (put 'scrollbar-page-down 'isearch-command t)
|
|
1319 (put 'scrollbar-to-top 'isearch-command t)
|
|
1320 (put 'scrollbar-to-bottom 'isearch-command t)
|
|
1321 (put 'scrollbar-vertical-drag 'isearch-command t)
|
|
1322
|
|
1323 ;; horizontal scrollbar:
|
|
1324 (put 'scrollbar-char-left 'isearch-command t)
|
|
1325 (put 'scrollbar-char-right 'isearch-command t)
|
|
1326 (put 'scrollbar-page-left 'isearch-command t)
|
|
1327 (put 'scrollbar-page-right 'isearch-command t)
|
|
1328 (put 'scrollbar-to-left 'isearch-command t)
|
|
1329 (put 'scrollbar-to-right 'isearch-command t)
|
|
1330 (put 'scrollbar-horizontal-drag 'isearch-command t)
|
|
1331
|
|
1332 (defun isearch-pre-command-hook ()
|
|
1333 ;;
|
|
1334 ;; For use as the value of `pre-command-hook' when isearch-mode is active.
|
|
1335 ;; If the command about to be executed is not one of the isearch commands,
|
|
1336 ;; then isearch-mode is turned off before that command is executed.
|
|
1337 ;;
|
|
1338 ;; If the command about to be executed is self-insert-command, or is a
|
|
1339 ;; keyboard macro of a single key sequence which is bound to self-insert-
|
|
1340 ;; command, then we add those chars to the search ring instead of inserting
|
|
1341 ;; them in the buffer. In this way, the set of self-searching characters
|
|
1342 ;; need not be exhaustively enumerated, but is derived from other maps.
|
|
1343 ;;
|
|
1344 (cond ((not (eq (current-buffer) isearch-buffer))
|
|
1345 ;; If the buffer (likely meaning "frame") has changed, bail.
|
|
1346 ;; This can also happen if a proc filter has popped up another
|
|
1347 ;; buffer, which is arguably a bad thing for it to have done,
|
|
1348 ;; but the way in which isearch would have hosed you in that
|
|
1349 ;; case is unarguably even worse. -jwz
|
|
1350 (isearch-done))
|
|
1351 (t
|
|
1352 (isearch-maybe-frob-keyboard-macros)
|
|
1353 (if (and this-command
|
|
1354 (symbolp this-command)
|
|
1355 (get this-command 'isearch-command))
|
|
1356 nil ; then continue.
|
|
1357 (isearch-done)))))
|
|
1358
|
|
1359 (defun isearch-maybe-frob-keyboard-macros ()
|
|
1360 ;;
|
|
1361 ;; If the command about to be executed is `self-insert-command' then change
|
|
1362 ;; the command to `isearch-printing-char' instead, meaning add the last-
|
|
1363 ;; typed character to the search string.
|
|
1364 ;;
|
|
1365 ;; If `this-command' is a string or a vector (that is, a keyboard macro)
|
|
1366 ;; and it contains only one command, which is bound to self-insert-command,
|
|
1367 ;; then do the same thing as for self-inserting commands: arrange for that
|
|
1368 ;; character to be added to the search string. If we didn't do this, then
|
|
1369 ;; typing a compose sequence (a la x-compose.el) would terminate the search
|
|
1370 ;; and insert the character, instead of searching for that character.
|
|
1371 ;;
|
|
1372 ;; We should continue doing this, since it's pretty much the behavior one
|
|
1373 ;; would expect, but it will stop being so necessary once key-translation-
|
|
1374 ;; map exists and is used by x-compose.el and things like it, since the
|
|
1375 ;; translation will have been done before we see the keys.
|
|
1376 ;;
|
|
1377 (cond ((eq this-command 'self-insert-command)
|
|
1378 (setq this-command 'isearch-printing-char))
|
|
1379 ((and (or (stringp this-command) (vectorp this-command))
|
|
1380 (eq (key-binding this-command) 'self-insert-command))
|
|
1381 (setq last-command-event (character-to-event (aref this-command 0))
|
|
1382 last-command-char (and (stringp this-command)
|
|
1383 (aref this-command 0))
|
|
1384 this-command 'isearch-printing-char))
|
|
1385 ))
|
|
1386
|
|
1387
|
|
1388 ;;;========================================================
|
|
1389 ;;; Highlighting
|
|
1390
|
|
1391 (defvar isearch-highlight t
|
|
1392 "*Whether isearch and query-replace should highlight the text which
|
|
1393 currently matches the search-string.")
|
|
1394
|
|
1395 (defvar isearch-extent nil)
|
|
1396
|
|
1397 ;; this face is initialized by x-faces.el since isearch is preloaded.
|
|
1398 ;; this face is now created in initialize-faces
|
|
1399 ;;(make-face 'isearch)
|
|
1400
|
|
1401 (defun isearch-make-extent (begin end)
|
|
1402 (let ((x (make-extent begin end (current-buffer))))
|
|
1403 ;; make the isearch extent always take prescedence over any mouse-
|
|
1404 ;; highlighted extents we may be passing through, since isearch, being
|
|
1405 ;; modal, is more interesting (there's nothing they could do with a
|
|
1406 ;; mouse-highlighted extent while in the midst of a search anyway).
|
|
1407 (set-extent-priority x (1+ mouse-highlight-priority))
|
|
1408 (set-extent-face x 'isearch)
|
|
1409 (setq isearch-extent x)))
|
|
1410
|
|
1411 (defun isearch-highlight (begin end)
|
|
1412 (if (null isearch-highlight)
|
|
1413 nil
|
|
1414 ;; make sure isearch-extent is in the current buffer
|
|
1415 (cond ((not (extentp isearch-extent))
|
|
1416 (isearch-make-extent begin end))
|
|
1417 ((not (eq (extent-object isearch-extent) (current-buffer)))
|
|
1418 (delete-extent isearch-extent)
|
|
1419 (isearch-make-extent begin end)))
|
|
1420 (set-extent-endpoints isearch-extent begin end)))
|
|
1421
|
|
1422 (defun isearch-dehighlight (totally)
|
|
1423 (if (and isearch-highlight isearch-extent)
|
|
1424 (if totally
|
|
1425 (let ((inhibit-quit t))
|
|
1426 (if (extentp isearch-extent)
|
|
1427 (delete-extent isearch-extent))
|
|
1428 (setq isearch-extent nil))
|
|
1429 (if (extentp isearch-extent)
|
|
1430 (detach-extent isearch-extent)
|
|
1431 (setq isearch-extent nil)))))
|
|
1432
|
|
1433
|
|
1434 ;;;========================================================
|
|
1435 ;;; Searching
|
|
1436
|
|
1437 (defun isearch-search ()
|
|
1438 ;; Do the search with the current search string.
|
|
1439 (isearch-message nil t)
|
|
1440 (if (and isearch-case-fold-search search-caps-disable-folding)
|
|
1441 (setq isearch-case-fold-search (isearch-no-upper-case-p isearch-string)))
|
|
1442
|
|
1443 (setq isearch-mode (if case-fold-search
|
|
1444 (if isearch-case-fold-search
|
|
1445 " Isearch" ;As God Intended Mode
|
|
1446 " ISeARch") ;Warn about evil case via StuDLYcAps.
|
|
1447 "Isearch"
|
|
1448 ; (if isearch-case-fold-search
|
|
1449 ; " isearch" ;Presumably case-sensitive losers
|
|
1450 ; ;will notice this 1-char difference.
|
|
1451 ; " Isearch") ;Weenie mode.
|
|
1452 ))
|
|
1453 (condition-case lossage
|
|
1454 (let ((inhibit-quit nil)
|
|
1455 (case-fold-search isearch-case-fold-search))
|
|
1456 (if isearch-regexp (setq isearch-invalid-regexp nil))
|
|
1457 (setq isearch-success
|
|
1458 (funcall
|
|
1459 (cond (isearch-word
|
|
1460 (if isearch-forward
|
|
1461 'word-search-forward 'word-search-backward))
|
|
1462 (isearch-regexp
|
|
1463 (if isearch-forward
|
|
1464 're-search-forward 're-search-backward))
|
|
1465 (t
|
|
1466 (if isearch-forward 'search-forward 'search-backward)))
|
|
1467 isearch-string nil t))
|
|
1468 (if isearch-success
|
|
1469 (setq isearch-other-end
|
|
1470 (if isearch-forward (match-beginning 0) (match-end 0)))))
|
|
1471
|
|
1472 (quit (setq unread-command-event (character-to-event (quit-char)))
|
|
1473 (setq isearch-success nil))
|
|
1474
|
|
1475 (invalid-regexp
|
|
1476 (setq isearch-invalid-regexp (car (cdr lossage)))
|
|
1477 (if (string-match
|
|
1478 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
|
|
1479 isearch-invalid-regexp)
|
|
1480 (setq isearch-invalid-regexp (gettext "incomplete input")))))
|
|
1481
|
|
1482 (if isearch-success
|
|
1483 nil
|
|
1484
|
|
1485 ;; If we're being run inside a keyboard macro, then the call to
|
|
1486 ;; ding will signal an error (to terminate the macro). We must
|
|
1487 ;; turn off isearch-mode first, so that we aren't still in isearch
|
|
1488 ;; mode after the macro exits. Note that isearch-recursive-edit
|
|
1489 ;; must not be true if a keyboard macro is executing.
|
|
1490 (if (and executing-kbd-macro (not defining-kbd-macro))
|
|
1491 (progn
|
|
1492 (isearch-done)
|
|
1493 (ding nil 'isearch-failed)))
|
|
1494
|
|
1495 ;; Ding if failed this time after succeeding last time.
|
|
1496 (and (nth 3 (car isearch-cmds))
|
|
1497 (ding nil 'isearch-failed))
|
|
1498 (goto-char (nth 2 (car isearch-cmds)))))
|
|
1499
|
|
1500 ;;;=================================================
|
|
1501 ;; This is called from incremental-search
|
|
1502 ;; if the first input character is the exit character.
|
|
1503
|
|
1504 ;; We store the search string in `isearch-string'
|
|
1505 ;; which has been bound already by `isearch-search'
|
|
1506 ;; so that, when we exit, it is copied into `search-last-string'.
|
|
1507
|
|
1508 ;(defun nonincremental-search (forward regexp)
|
|
1509 ; ;; This may be broken. Anyway, it is replaced by the isearch-edit-string.
|
|
1510 ; ;; Missing features: word search option, command history.
|
|
1511 ; (setq isearch-forward forward
|
|
1512 ; isearch-regexp regexp)
|
|
1513 ; (let (char function
|
|
1514 ; inhibit-quit
|
|
1515 ; (cursor-in-echo-area t))
|
|
1516 ; ;; Prompt assuming not word search,
|
|
1517 ; (setq isearch-message
|
|
1518 ; (if isearch-regexp
|
|
1519 ; (if isearch-forward "Regexp search: "
|
|
1520 ; "Regexp search backward: ")
|
|
1521 ; (if isearch-forward "Search: " "Search backward: ")))
|
|
1522 ; (message "%s" isearch-message)
|
|
1523 ; ;; Read 1 char and switch to word search if it is ^W.
|
|
1524 ; (setq char (read-char))
|
|
1525 ; (if (eq char search-yank-word-char)
|
|
1526 ; (setq isearch-message (if isearch-forward "Word search: "
|
|
1527 ; "Word search backward: "))
|
|
1528 ; ;; Otherwise let that 1 char be part of the search string.
|
|
1529 ; (setq unread-command-event (character-to-event char))
|
|
1530 ; )
|
|
1531 ; (setq function
|
|
1532 ; (if (eq char search-yank-word-char)
|
|
1533 ; (if isearch-forward 'word-search-forward 'word-search-backward)
|
|
1534 ; (if isearch-regexp
|
|
1535 ; (if isearch-forward 're-search-forward 're-search-backward)
|
|
1536 ; (if isearch-forward 'search-forward 'search-backward))))
|
|
1537 ; ;; Read the search string with corrected prompt.
|
|
1538 ; (setq isearch-string (read-string isearch-message isearch-string))
|
|
1539 ; ;; Empty means use default.
|
|
1540 ; (if (= 0 (length isearch-string))
|
|
1541 ; (setq isearch-string search-last-string)
|
|
1542 ; ;; Set last search string now so it is set even if we fail.
|
|
1543 ; (setq search-last-string isearch-string))
|
|
1544 ; ;; Since we used the minibuffer, we should be available for redo.
|
|
1545 ; (setq command-history
|
|
1546 ; (cons (list function isearch-string) command-history))
|
|
1547 ; ;; Go ahead and search.
|
|
1548 ; (if search-caps-disable-folding
|
|
1549 ; (setq isearch-case-fold-search
|
|
1550 ; (isearch-no-upper-case-p isearch-string)))
|
|
1551 ; (let ((case-fold-search isearch-case-fold-search))
|
|
1552 ; (funcall function isearch-string))))
|
|
1553
|
|
1554
|
|
1555 (defun isearch-no-upper-case-p (string)
|
|
1556 "Return t if there are no upper case chars in string.
|
30
|
1557 But upper case chars preceded by \\ do not count since they
|
0
|
1558 have special meaning in a regexp."
|
|
1559 ;; this incorrectly returns t for "\\\\A"
|
|
1560 (let ((case-fold-search nil))
|
|
1561 (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string))))
|