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