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