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