1 ;;; isearch.el --- incremental search minor mode.
3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
30 ;; isearch-mode behaves modally and does not return until the search
31 ;; is completed. It uses a recursive-edit to behave this way. Note:
32 ;; gnus does it wrong: (call-interactively 'isearch-forward).
34 ;; The key bindings active within isearch-mode are defined below in
35 ;; `isearch-mode-map' which is given bindings close to the default
36 ;; characters of the original isearch.el. With `isearch-mode',
37 ;; however, you can bind multi-character keys and it should be easier
38 ;; to add new commands. One bug though: keys with meta-prefix cannot
39 ;; be longer than two chars. Also see minibuffer-local-isearch-map
40 ;; for bindings active during `isearch-edit-string'.
42 ;; Note to emacs version 19 users: isearch-mode should work even if
43 ;; you switch windows with the mouse, in which case isearch-mode is
44 ;; terminated automatically before the switch. This is true of lemacs
45 ;; too, with a few more cleanups I've neglected in this release.
46 ;; No one has supplied patches for epoch yet.
48 ;; The search ring and completion commands automatically put you in
49 ;; the minibuffer to edit the string. This gives you a chance to
50 ;; modify the search string before executing the search. There are
51 ;; three commands to terminate the editing: C-s and C-r exit the
52 ;; minibuffer and search forward and reverse respectively, while C-m
53 ;; exits and does a nonincremental search.
55 ;; Exiting immediately from isearch uses isearch-edit-string instead
56 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
57 ;; The name of this option should probably be changed if we decide to
58 ;; keep the behavior. No point in forcing nonincremental search until
59 ;; the last possible moment.
62 ;; - Integrate the emacs 19 generalized command history.
63 ;; - Think about incorporating query-replace.
64 ;; - Hooks and options for failed search.
68 ;; Changes before those recorded in ChangeLog:
70 ;; Revision 1.4 92/09/14 16:26:02 liberte
71 ;; Added prefix args to isearch-forward, etc. to switch between
72 ;; string and regular expression searching.
73 ;; Added some support for lemacs.
74 ;; Added general isearch-highlight option - but only for lemacs so far.
75 ;; Added support for frame switching in emacs 19.
76 ;; Added word search option to isearch-edit-string.
77 ;; Renamed isearch-quit to isearch-abort.
78 ;; Numerous changes to comments and doc strings.
80 ;; Revision 1.3 92/06/29 13:10:08 liberte
81 ;; Moved modal isearch-mode handling into isearch-mode.
82 ;; Got rid of buffer-local isearch variables.
83 ;; isearch-edit-string used by ring adjustments, completion, and
84 ;; nonincremental searching. C-s and C-r are additional exit commands.
85 ;; Renamed all regex to regexp.
86 ;; Got rid of found-start and found-point globals.
87 ;; Generalized handling of upper-case chars.
89 ;; Revision 1.2 92/05/27 11:33:57 liberte
90 ;; Emacs version 19 has a search ring, which is supported here.
91 ;; Other fixes found in the version 19 isearch are included here.
93 ;; Also see variables search-caps-disable-folding,
94 ;; search-nonincremental-instead, search-whitespace-regexp, and
95 ;; commands isearch-toggle-regexp, isearch-edit-string.
97 ;; semi-modal isearching is supported.
100 ;; 3/18/92 Fixed invalid-regexp.
101 ;; 3/18/92 Fixed yanking in regexps.
106 ;;; Some additional options and constants.
108 (defvar search-exit-option t
109 "*Non-nil means random control characters terminate incremental search.")
111 (defvar search-slow-window-lines
1
112 "*Number of lines in slow search display windows.
113 These are the short windows used during incremental search on slow terminals.
114 Negative means put the slow search window at the top (normally it's at bottom)
115 and the value is minus the number of lines.")
117 (defvar search-slow-speed
1200
118 "*Highest terminal speed at which to use \"slow\" style incremental search.
119 This is the style where a one-line window is created to show the line
120 that the search has reached.")
122 (defvar search-upper-case
'not-yanks
123 "*If non-nil, upper case chars disable case fold searching.
124 That is, upper and lower case chars must match exactly.
125 This applies no matter where the chars come from, but does not
126 apply to chars in regexps that are prefixed with `\\'.
127 If this value is `not-yanks', yanked text is always downcased.")
129 (defvar search-nonincremental-instead t
130 "*If non-nil, do a nonincremental search instead if exiting immediately.
131 Actually, `isearch-edit-string' is called to let you enter the search
132 string, and RET terminates editing and does a nonincremental search.")
134 (defvar search-whitespace-regexp
"\\s-+"
135 "*If non-nil, regular expression to match a sequence of whitespace chars.
136 You might want to use something like \"[ \\t\\r\\n]+\" instead.")
138 (defvar search-highlight nil
139 "*Non-nil means incremental search highlights the current match.")
141 (defvar search-invisible nil
142 "*Non-nil means incremental search can match text hidden by an overlay.
143 \(This applies when using `noutline.el'.)")
145 (defvar isearch-mode-hook nil
146 "Function(s) to call after starting up an incremental search.")
148 (defvar isearch-mode-end-hook nil
149 "Function(s) to call after terminating an incremental search.")
153 (defvar search-ring nil
154 "List of search string sequences.")
155 (defvar regexp-search-ring nil
156 "List of regular expression search string sequences.")
158 (defvar search-ring-max
16
159 "*Maximum length of search ring before oldest elements are thrown away.")
160 (defvar regexp-search-ring-max
16
161 "*Maximum length of regexp search ring before oldest elements are thrown away.")
163 (defvar search-ring-yank-pointer nil
164 "Index in `search-ring' of last string reused.
166 (defvar regexp-search-ring-yank-pointer nil
167 "Index in `regexp-search-ring' of last string reused.
170 (defvar search-ring-update nil
171 "*Non-nil if advancing or retreating in the search ring should cause search.
172 Default value, nil, means edit the string instead.")
174 ;;; Define isearch-mode keymap.
176 (defvar isearch-mode-map nil
177 "Keymap for isearch-mode.")
182 (or (vectorp (nth 1 map
))
183 (error "The initialization of isearch-mode-map must be updated"))
184 ;; Give this map a vector 256 long, for dense binding
185 ;; of a larger range of ordinary characters.
186 (setcar (cdr map
) (make-vector 256 nil
))
188 ;; Make function keys, etc, exit the search.
189 (define-key map
[t] 'isearch-other-control-char)
190 ;; Control chars, by default, end isearch mode transparently.
191 ;; We need these explicit definitions because, in a dense keymap,
192 ;; the binding for t does not affect characters.
193 ;; We use a dense keymap to save space.
195 (define-key map (make-string 1 i) 'isearch-other-control-char)
198 ;; Printing chars extend the search string by default.
200 (while (< i (length (nth 1 map)))
201 (define-key map (vector i) 'isearch-printing-char)
204 ;; To handle local bindings with meta char prefix keys, define
205 ;; another full keymap. This must be done for any other prefix
206 ;; keys as well, one full keymap per char of the prefix key. It
207 ;; would be simpler to disable the global keymap, and/or have a
208 ;; default local key binding for any key not otherwise bound.
209 (let ((meta-map (make-sparse-keymap)))
210 (define-key map (char-to-string meta-prefix-char) meta-map)
211 (define-key map [escape] meta-map))
212 (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
214 ;; Several non-printing chars change the searching behavior.
215 (define-key map "\C-s" 'isearch-repeat-forward)
216 (define-key map "\C-r" 'isearch-repeat-backward)
217 (define-key map "\177" 'isearch-delete-char)
218 (define-key map "\C-g" 'isearch-abort)
219 ;; This assumes \e is the meta-prefix-char.
220 (or (= ?\e meta-prefix-char)
221 (error "Inconsistency in isearch.el"))
222 (define-key map "\e\e\e" 'isearch-cancel)
223 (define-key map [escape escape escape] 'isearch-cancel)
225 (define-key map "\C-q" 'isearch-quote-char)
227 (define-key map "\r" 'isearch-exit)
228 (define-key map "\C-j" 'isearch-printing-char)
229 (define-key map "\t" 'isearch-printing-char)
230 (define-key map " " 'isearch-whitespace-chars)
232 (define-key map "\C-w" 'isearch-yank-word)
233 (define-key map "\C-y" 'isearch-yank-line)
235 ;; Define keys for regexp chars * ? |.
236 ;; Nothing special for + because it matches at least once.
237 (define-key map "*" 'isearch-*-char)
238 (define-key map "?" 'isearch-*-char)
239 (define-key map "|" 'isearch-|-char)
241 ;;; Turned off because I find I expect to get the global definition--rms.
242 ;;; ;; Instead bind C-h to special help command for isearch-mode.
243 ;;; (define-key map "\C-h" 'isearch-mode-help)
245 (define-key map "\M-n" 'isearch-ring-advance)
246 (define-key map "\M-p" 'isearch-ring-retreat)
247 (define-key map "\M-y" 'isearch-yank-kill)
249 (define-key map "\M-\t" 'isearch-complete)
251 ;; Pass frame events transparently so they won't exit the search.
252 ;; In particular, if we have more than one display open, then a
253 ;; switch-frame might be generated by someone typing at another keyboard.
254 (define-key map [switch-frame] nil)
255 (define-key map [delete-frame] nil)
256 (define-key map [iconify-frame] nil)
257 (define-key map [make-frame-visible] nil)
258 ;; For searching multilingual text.
259 (define-key map "\C-\\" 'isearch-toggle-input-method)
260 (define-key map "\C-^" 'isearch-toggle-specified-input-method)
262 (setq isearch-mode-map map)
265 ;; Some bindings you may want to put in your isearch-mode-hook.
266 ;; Suggest some alternates...
267 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-case-fold)
268 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
269 ;; (define-key isearch-mode-map "\C-^" 'isearch-edit-string)
272 (defvar minibuffer-local-isearch-map nil
273 "Keymap for editing isearch strings in the minibuffer.")
275 (or minibuffer-local-isearch-map
276 (let ((map (copy-keymap minibuffer-local-map)))
277 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
278 (define-key map "\M-n" 'isearch-ring-advance-edit)
279 (define-key map "\M-p" 'isearch-ring-retreat-edit)
280 (define-key map "\M-\t" 'isearch-complete-edit)
281 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
282 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
283 (setq minibuffer-local-isearch-map map)
286 ;; Internal variables declared globally for byte-compiler.
287 ;; These are all set with setq while isearching
288 ;; and bound locally while editing the search string.
290 (defvar isearch-forward nil) ; Searching in the forward direction.
291 (defvar isearch-regexp nil) ; Searching for a regexp.
292 (defvar isearch-word nil) ; Searching for words.
294 (defvar isearch-cmds nil) ; Stack of search status sets.
295 (defvar isearch-string "") ; The current search string.
296 (defvar isearch-message "") ; text-char-description version of isearch-string
298 (defvar isearch-success t) ; Searching is currently successful.
299 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
300 (defvar isearch-within-brackets nil) ; Regexp has unclosed [.
301 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
302 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
303 (defvar isearch-barrier 0)
304 (defvar isearch-just-started nil)
306 ; case-fold-search while searching.
307 ; either nil, t, or 'yes. 'yes means the same as t except that mixed
308 ; case in the search string is ignored.
309 (defvar isearch-case-fold-search nil)
311 (defvar isearch-adjusted nil)
312 (defvar isearch-slow-terminal-mode nil)
313 ;;; If t, using a small window.
314 (defvar isearch-small-window nil)
315 (defvar isearch-opoint 0)
316 ;;; The window configuration active at the beginning of the search.
317 (defvar isearch-window-configuration nil)
319 ;; Flag to indicate a yank occurred, so don't move the cursor.
320 (defvar isearch-yank-flag nil)
322 ;; Flag to indicate that we are searching multibyte characaters.
323 (defvar isearch-multibyte-characters-flag nil)
325 ;;; A function to be called after each input character is processed.
326 ;;; (It is not called after characters that exit the search.)
327 ;;; It is only set from an optional argument to `isearch-mode'.
328 (defvar isearch-op-fun nil)
330 ;;; Is isearch-mode in a recursive edit for modal searching.
331 (defvar isearch-recursive-edit nil)
333 ;;; Should isearch be terminated after doing one search?
334 (defvar isearch-nonincremental nil)
336 ;; New value of isearch-forward after isearch-edit-string.
337 (defvar isearch-new-forward nil)
340 ;; Minor-mode-alist changes - kind of redundant with the
341 ;; echo area, but if isearching in multiple windows, it can be useful.
343 (or (assq 'isearch-mode minor-mode-alist)
344 (nconc minor-mode-alist
345 (list '(isearch-mode isearch-mode))))
347 (defvar isearch-mode nil) ;; Name of the minor mode, if non-nil.
348 (make-variable-buffer-local 'isearch-mode)
350 (define-key global-map "\C-s" 'isearch-forward)
351 (define-key esc-map "\C-s" 'isearch-forward-regexp)
352 (define-key global-map "\C-r" 'isearch-backward)
353 (define-key esc-map "\C-r" 'isearch-backward-regexp)
355 ;;; Entry points to isearch-mode.
356 ;;; These four functions should replace those in loaddefs.el
357 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
358 ;;; and look at this-command to set the options accordingly.
360 (defun isearch-forward (&optional regexp-p no-recursive-edit)
362 Do incremental search forward.
363 With a prefix argument, do an incremental regular expression search instead.
365 As you type characters, they add to the search string and are found.
366 The following non-printing keys are bound in `isearch-mode-map'.
368 Type \\[isearch-delete-char] to cancel characters from end of search string.
369 Type \\[isearch-exit] to exit, leaving point at location found.
370 Type LFD (C-j) to match end of line.
371 Type \\[isearch-repeat-forward] to search again forward,\
372 \\[isearch-repeat-backward] to search again backward.
373 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
374 string and search for it.
375 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
377 Type \\[isearch-yank-kill] to yank the last string of killed text.
378 Type \\[isearch-quote-char] to quote control character to search for it.
379 \\[isearch-abort] while searching or when search has failed cancels input\
381 been found successfully.
382 \\[isearch-abort] when search is successful aborts and moves point to\
385 Also supported is a search ring of the previous 16 search strings.
386 Type \\[isearch-ring-advance] to search for the next item in the search ring.
387 Type \\[isearch-ring-retreat] to search for the previous item in the search\
389 Type \\[isearch-complete] to complete the search string using the search ring.
391 The above keys, bound in `isearch-mode-map', are often controlled by
392 options; do M-x apropos on search-.* to find them.
393 Other control and meta characters terminate the search
394 and are then executed normally (depending on `search-exit-option').
395 Likewise for function keys and mouse button events.
397 If this function is called non-interactively, it does not return to
398 the calling function until the search is done."
401 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
403 (defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
405 Do incremental search forward for regular expression.
406 With a prefix argument, do a regular string search instead.
407 Like ordinary incremental search except that your input
408 is treated as a regexp. See \\[isearch-forward] for more info."
410 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
412 (defun isearch-backward (&optional regexp-p no-recursive-edit)
414 Do incremental search backward.
415 With a prefix argument, do a regular expression search instead.
416 See \\[isearch-forward] for more information."
418 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
420 (defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
422 Do incremental search backward for regular expression.
423 With a prefix argument, do a regular string search instead.
424 Like ordinary incremental search except that your input
425 is treated as a regexp. See \\[isearch-forward] for more info."
427 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
430 (defun isearch-mode-help ()
432 (describe-function 'isearch-forward)
436 ;; isearch-mode only sets up incremental search for the minor mode.
437 ;; All the work is done by the isearch-mode commands.
440 ;;(defvar isearch-commands '(isearch-forward isearch-backward
441 ;; isearch-forward-regexp isearch-backward-regexp)
442 ;; "List of commands for which isearch-mode does not recursive-edit.")
445 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
446 "Start isearch minor mode. Called by `isearch-forward', etc.
448 \\{isearch-mode-map}"
450 ;; Initialize global vars.
451 (setq isearch-forward forward
452 isearch-regexp regexp
454 isearch-op-fun op-fun
455 isearch-case-fold-search case-fold-search
461 isearch-barrier (point)
463 isearch-yank-flag nil
464 isearch-invalid-regexp nil
465 isearch-within-brackets nil
466 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
468 (* 4 search-slow-window-lines)))
469 isearch-other-end nil
470 isearch-small-window nil
471 isearch-just-started t
472 isearch-multibyte-characters-flag nil
474 isearch-opoint (point)
475 search-ring-yank-pointer nil
476 regexp-search-ring-yank-pointer nil)
478 (setq isearch-window-configuration
479 (if isearch-slow-terminal-mode (current-window-configuration) nil))
481 ;; Maybe make minibuffer frame visible and/or raise it.
482 (let ((frame (window-frame (minibuffer-window))))
483 (if (not (memq (frame-live-p frame) '(nil t)))
485 (make-frame-visible frame)
486 (if minibuffer-auto-raise
487 (raise-frame frame)))))
489 (setq isearch-mode " Isearch") ;; forward? regexp?
490 (force-mode-line-update)
494 (setq overriding-terminal-local-map isearch-mode-map)
496 (run-hooks 'isearch-mode-hook)
498 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
500 ;; isearch-mode can be made modal (in the sense of not returning to
501 ;; the calling function until searching is completed) by entering
502 ;; a recursive-edit and exiting it when done isearching.
504 (let ((isearch-recursive-edit t))
509 ;; Some high level utilities. Others below.
511 (defun isearch-update ()
512 ;; Called after each command to update the display.
513 (if (null unread-command-events)
515 (if (not (input-pending-p))
517 (if (and isearch-slow-terminal-mode
518 (not (or isearch-small-window
519 (pos-visible-in-window-p))))
520 (let ((found-point (point)))
521 (setq isearch-small-window t)
522 (move-to-window-line 0)
523 (let ((window-min-height 1))
524 (split-window nil (if (< search-slow-window-lines 0)
525 (1+ (- search-slow-window-lines))
527 (1+ search-slow-window-lines)))))
528 (if (< search-slow-window-lines 0)
529 (progn (vertical-motion (- 1 search-slow-window-lines))
530 (set-window-start (next-window) (point))
531 (set-window-hscroll (next-window)
533 (set-window-hscroll (selected-window) 0))
535 (goto-char found-point)))
536 (if isearch-other-end
537 (if (< isearch-other-end (point)) ; isearch-forward?
538 (isearch-highlight isearch-other-end (point))
539 (isearch-highlight (point) isearch-other-end))
540 (isearch-dehighlight nil))
542 (setq ;; quit-flag nil not for isearch-mode
544 isearch-yank-flag nil)
547 (defun isearch-done (&optional nopush edit)
548 (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
549 ;; Called by all commands that terminate isearch-mode.
550 ;; If NOPUSH is non-nil, we don't push the string on the search ring.
551 (setq overriding-terminal-local-map nil)
552 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
553 (isearch-dehighlight t)
554 (let ((found-start (window-start (selected-window)))
555 (found-point (point)))
556 (if isearch-window-configuration
557 (set-window-configuration isearch-window-configuration))
559 (if isearch-small-window
560 (goto-char found-point)
561 ;; Exiting the save-window-excursion clobbers window-start; restore it.
562 (set-window-start (selected-window) found-start t))
564 ;; If there was movement, mark the starting position.
565 ;; Maybe should test difference between and set mark iff > threshold.
566 (if (/= (point) isearch-opoint)
567 (or (and transient-mark-mode mark-active)
569 (push-mark isearch-opoint t)
570 (or executing-kbd-macro (> (minibuffer-depth) 0)
571 (message "Mark saved where search started"))))))
573 (setq isearch-mode nil)
574 (force-mode-line-update)
576 (if (and (> (length isearch-string) 0) (not nopush))
577 ;; Update the ring data.
578 (isearch-update-ring isearch-string isearch-regexp))
580 (run-hooks 'isearch-mode-end-hook)
581 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
583 (defun isearch-update-ring (string &optional regexp)
584 "Add STRING to the beginning of the search ring.
585 REGEXP says which ring to use."
587 (if (or (null regexp-search-ring)
588 (not (string= string (car regexp-search-ring))))
590 (setq regexp-search-ring
591 (cons string regexp-search-ring))
592 (if (> (length regexp-search-ring) regexp-search-ring-max)
593 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
595 (if (or (null search-ring)
596 (not (string= string (car search-ring))))
598 (setq search-ring (cons string search-ring))
599 (if (> (length search-ring) search-ring-max)
600 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
602 ;;; Switching buffers should first terminate isearch-mode.
603 ;;; This is done quite differently for each variant of emacs.
604 ;;; For lemacs, see Exiting in lemacs below
606 ;; For Emacs 19, the frame switch event is handled.
607 (defun isearch-switch-frame-handler ()
608 (interactive) ;; Is this necessary?
609 ;; First terminate isearch-mode.
611 (handle-switch-frame (car (cdr (isearch-last-command-char)))))
614 ;; Commands active while inside of the isearch minor mode.
616 (defun isearch-exit ()
617 "Exit search normally.
618 However, if this is the first command after starting incremental
619 search and `search-nonincremental-instead' is non-nil, do a
620 nonincremental search instead via `isearch-edit-string'."
622 (if (and search-nonincremental-instead
623 (= 0 (length isearch-string)))
624 (let ((isearch-nonincremental t))
625 (isearch-edit-string)))
629 (defun isearch-edit-string ()
630 "Edit the search string in the minibuffer.
631 The following additional command keys are active while editing.
632 \\<minibuffer-local-isearch-map>
633 \\[exit-minibuffer] to resume incremental searching with the edited string.
634 \\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
635 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
636 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
637 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
638 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
639 \\[isearch-complete-edit] to complete the search string using the search ring.
641 If first char entered is \\[isearch-yank-word], then do word search instead."
643 ;; This code is very hairy for several reasons, explained in the code.
644 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
645 ;; If there were a way to catch any change of buffer from the minibuffer,
646 ;; this could be simplified greatly.
647 ;; Editing doesn't back up the search point. Should it?
651 (let ((isearch-nonincremental isearch-nonincremental)
653 ;; Locally bind all isearch global variables to protect them
654 ;; from recursive isearching.
655 ;; isearch-string -message and -forward are not bound
656 ;; so they may be changed. Instead, save the values.
657 (isearch-new-string isearch-string)
658 (isearch-new-message isearch-message)
659 (isearch-new-forward isearch-forward)
660 (isearch-new-word isearch-word)
662 (isearch-regexp isearch-regexp)
663 (isearch-op-fun isearch-op-fun)
664 (isearch-cmds isearch-cmds)
665 (isearch-success isearch-success)
666 (isearch-wrapped isearch-wrapped)
667 (isearch-barrier isearch-barrier)
668 (isearch-adjusted isearch-adjusted)
669 (isearch-yank-flag isearch-yank-flag)
670 (isearch-invalid-regexp isearch-invalid-regexp)
671 (isearch-within-brackets isearch-within-brackets)
672 ;;; Don't bind this. We want isearch-search, below, to set it.
673 ;;; And the old value won't matter after that.
674 ;;; (isearch-other-end isearch-other-end)
675 ;;; Perhaps some of these other variables should be bound for a
676 ;;; shorter period, ending before the next isearch-search.
677 ;;; But there doesn't seem to be a real bug, so let's not risk it now.
678 (isearch-opoint isearch-opoint)
679 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
680 (isearch-small-window isearch-small-window)
681 (isearch-recursive-edit isearch-recursive-edit)
682 ;; Save current configuration so we can restore it here.
683 (isearch-window-configuration (current-window-configuration))
686 ;; Actually terminate isearching until editing is done.
687 ;; This is so that the user can do anything without failure,
688 ;; like switch buffers and start another isearch, and return.
691 (exit nil)) ; was recursive editing
693 (isearch-message) ;; for read-char
695 (let* (;; Why does following read-char echo?
696 ;;(echo-keystrokes 0) ;; not needed with above message
697 (e (let ((cursor-in-echo-area t))
699 ;; Binding minibuffer-history-symbol to nil is a work-around
700 ;; for some incompatibility with gmhist.
701 (minibuffer-history-symbol)
702 (message-log-max nil))
703 ;; If the first character the user types when we prompt them
704 ;; for a string is the yank-word character, then go into
705 ;; word-search mode. Otherwise unread that character and
706 ;; read a key the normal way.
707 ;; Word search does not apply (yet) to regexp searches,
708 ;; no check is made here.
709 (message (isearch-message-prefix nil nil t))
710 (if (eq 'isearch-yank-word
711 (lookup-key isearch-mode-map (vector e)))
712 (setq isearch-word t;; so message-prefix is right
714 (cancel-kbd-macro-events)
716 (setq cursor-in-echo-area nil)
717 (setq isearch-new-string
719 (read-from-minibuffer
720 (isearch-message-prefix nil nil isearch-nonincremental)
722 minibuffer-local-isearch-map nil
725 (mapconcat 'isearch-text-char-description
726 isearch-new-string "")))
727 ;; Always resume isearching by restarting it.
728 (isearch-mode isearch-forward
734 ;; Copy new local values to isearch globals
735 (setq isearch-string isearch-new-string
736 isearch-message isearch-new-message
737 isearch-forward isearch-new-forward
738 isearch-word isearch-new-word))
740 ;; Empty isearch-string means use default.
741 (if (= 0 (length isearch-string))
742 (setq isearch-string (or (car (if isearch-regexp
746 ;; This used to set the last search string,
747 ;; but I think it is not right to do that here.
748 ;; Only the string actually used should be saved.
751 ;; Push the state as of before this C-s.
754 ;; Reinvoke the pending search.
757 (if isearch-nonincremental
759 ;; (sit-for 1) ;; needed if isearch-done does: (message "")
762 (quit ; handle abort-recursive-edit
763 (isearch-abort) ;; outside of let to restore outside global values
766 (defun isearch-nonincremental-exit-minibuffer ()
768 (setq isearch-nonincremental t)
771 (defun isearch-forward-exit-minibuffer ()
773 (setq isearch-new-forward t)
776 (defun isearch-reverse-exit-minibuffer ()
778 (setq isearch-new-forward nil)
781 (defun isearch-cancel ()
782 "Terminate the search and go back to the starting point."
784 (goto-char isearch-opoint)
786 (signal 'quit nil)) ; and pass on quit signal
788 (defun isearch-abort ()
789 "Abort incremental search mode if searching is successful, signaling quit.
790 Otherwise, revert to previous successful search and continue searching.
791 Use `isearch-exit' to quit without signaling."
793 ;; (ding) signal instead below, if quitting
796 ;; If search is successful, move back to starting point
797 ;; and really do quit.
798 (progn (goto-char isearch-opoint)
799 (setq isearch-success nil)
800 (isearch-done t) ; exit isearch
801 (signal 'quit nil)) ; and pass on quit signal
802 ;; If search is failing, or has an incomplete regexp,
803 ;; rub out until it is once more successful.
804 (while (or (not isearch-success) isearch-invalid-regexp)
808 (defun isearch-repeat (direction)
809 ;; Utility for isearch-repeat-forward and -backward.
810 (if (eq isearch-forward (eq direction 'forward))
811 ;; C-s in forward or C-r in reverse.
812 (if (equal isearch-string "")
813 ;; If search string is empty, use last one.
815 (or (if isearch-regexp
816 (car regexp-search-ring)
820 (mapconcat 'isearch-text-char-description
822 ;; If already have what to search for, repeat it.
825 (goto-char (if isearch-forward (point-min) (point-max)))
826 (setq isearch-wrapped t))))
827 ;; C-s in reverse or C-r in forward, change direction.
828 (setq isearch-forward (not isearch-forward)))
830 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
832 (if (equal isearch-string "")
833 (setq isearch-success t)
834 (if (and isearch-success (equal (match-end 0) (match-beginning 0))
835 (not isearch-just-started))
836 ;; If repeating a search that found
837 ;; an empty string, ensure we advance.
838 (if (if isearch-forward (eobp) (bobp))
839 ;; If there's nowhere to advance to, fail (and wrap next time).
841 (setq isearch-success nil)
843 (forward-char (if isearch-forward 1 -1))
850 (defun isearch-repeat-forward ()
851 "Repeat incremental search forwards."
853 (isearch-repeat 'forward))
855 (defun isearch-repeat-backward ()
856 "Repeat incremental search backwards."
858 (isearch-repeat 'backward))
860 (defun isearch-toggle-regexp ()
861 "Toggle regexp searching on or off."
862 ;; The status stack is left unchanged.
864 (setq isearch-regexp (not isearch-regexp))
865 (if isearch-regexp (setq isearch-word nil))
868 (defun isearch-toggle-case-fold ()
869 "Toggle case folding in searching on or off."
871 (setq isearch-case-fold-search
872 (if isearch-case-fold-search nil 'yes))
873 (let ((message-log-max nil))
874 (message "%s%s [case %ssensitive]"
875 (isearch-message-prefix nil nil isearch-nonincremental)
877 (if isearch-case-fold-search "in" "")))
878 (setq isearch-adjusted t)
882 (defun isearch-delete-char ()
883 "Discard last input item and move point back.
884 If no previous match was done, just beep."
886 (if (null (cdr isearch-cmds))
892 (defun isearch-yank (chunk)
893 ;; Helper for isearch-yank-word and isearch-yank-line
894 ;; CHUNK should be word, line, kill, or x-sel.
902 (and (not isearch-forward) isearch-other-end
903 (goto-char isearch-other-end))
913 ;; Downcase the string if not supposed to case-fold yanked strings.
914 (if (and isearch-case-fold-search
915 (eq 'not-yanks search-upper-case))
916 (setq string (downcase string)))
917 (if isearch-regexp (setq string (regexp-quote string)))
918 (setq isearch-string (concat isearch-string string)
920 (concat isearch-message
921 (mapconcat 'isearch-text-char-description
923 ;; Don't move cursor in reverse search.
924 isearch-yank-flag t))
925 (isearch-search-and-update))
927 (defun isearch-yank-kill ()
928 "Pull string from kill ring into search string."
930 (isearch-yank 'kill))
932 (defun isearch-yank-word ()
933 "Pull next word from buffer into search string."
935 (isearch-yank 'word))
937 (defun isearch-yank-line ()
938 "Pull rest of line from buffer into search string."
940 (isearch-yank 'line))
943 (defun isearch-search-and-update ()
944 ;; Do the search and update the display.
945 (if (and (not isearch-success)
946 ;; unsuccessful regexp search may become
947 ;; successful by addition of characters which
948 ;; make isearch-string valid
949 (not isearch-regexp))
951 ;; In reverse search, adding stuff at
952 ;; the end may cause zero or many more chars to be
953 ;; matched, in the string following point.
954 ;; Allow all those possibilities without moving point as
955 ;; long as the match does not extend past search origin.
956 (if (and (not isearch-forward) (not isearch-adjusted)
958 (let ((case-fold-search isearch-case-fold-search))
959 (looking-at (if isearch-regexp isearch-string
960 (regexp-quote isearch-string))))
962 (or isearch-yank-flag
964 (min isearch-opoint isearch-barrier))))
965 (setq isearch-success t
966 isearch-invalid-regexp nil
967 isearch-within-brackets nil
968 isearch-other-end (match-end 0))
969 ;; Not regexp, not reverse, or no match at point.
970 (if (and isearch-other-end (not isearch-adjusted))
971 (goto-char (if isearch-forward isearch-other-end
974 (1+ isearch-other-end)))))
978 (if isearch-op-fun (funcall isearch-op-fun))
982 ;; *, ?, and | chars can make a regexp more liberal.
983 ;; They can make a regexp match sooner or make it succeed instead of failing.
984 ;; So go back to place last successful search started
985 ;; or to the last ^S/^R (barrier), whichever is nearer.
986 ;; + needs no special handling because the string must match at least once.
988 (defun isearch-*-char ()
989 "Handle * and ? specially in regexps."
994 (setq isearch-adjusted t)
995 ;; Get the isearch-other-end from before the last search.
996 ;; We want to start from there,
997 ;; so that we don't retreat farther than that.
998 ;; (car isearch-cmds) is after last search;
999 ;; (car (cdr isearch-cmds)) is from before it.
1000 (let ((cs (nth 5 (car (cdr isearch-cmds)))))
1001 (setq cs (or cs isearch-barrier))
1004 (max cs isearch-barrier)
1005 (min cs isearch-barrier))))))
1006 (isearch-process-search-char (isearch-last-command-char)))
1009 (defun isearch-|-char ()
1010 "If in regexp search, jump to the barrier."
1014 (setq isearch-adjusted t)
1015 (goto-char isearch-barrier)))
1016 (isearch-process-search-char (isearch-last-command-char)))
1019 (defalias 'isearch-other-control-char 'isearch-other-meta-char)
1021 (defun isearch-other-meta-char ()
1022 "Exit the search normally and reread this key sequence.
1023 But only if `search-exit-option' is non-nil, the default.
1024 If it is the symbol `edit', the search string is edited in the minibuffer
1025 and the meta character is unread so that it applies to editing the string."
1027 (let* ((key (this-command-keys))
1028 (main-event (aref key 0))
1029 (keylist (listify-key-sequence key)))
1030 (cond ((and (= (length key) 1)
1031 (let ((lookup (lookup-key function-key-map key)))
1032 (not (or (null lookup) (integerp lookup)
1033 (keymapp lookup)))))
1034 ;; Handle a function key that translates into something else.
1035 ;; If the key has a global definition too,
1036 ;; exit and unread the key itself, so its global definition runs.
1037 ;; Otherwise, unread the translation,
1038 ;; so that the translated key takes effect within isearch.
1039 (cancel-kbd-macro-events)
1040 (if (lookup-key global-map key)
1043 (apply 'isearch-unread keylist))
1044 (apply 'isearch-unread
1045 (listify-key-sequence (lookup-key function-key-map key)))))
1047 ;; Handle an undefined shifted control character
1048 ;; by downshifting it if that makes it defined.
1049 ;; (As read-key-sequence would normally do,
1050 ;; if we didn't have a default definition.)
1051 (let ((mods (event-modifiers main-event)))
1052 (and (integerp main-event)
1054 (memq 'control mods)
1055 (lookup-key isearch-mode-map
1056 (let ((copy (copy-sequence key)))
1058 (- main-event (- ?\C-\S-a ?\C-a)))
1061 (setcar keylist (- main-event (- ?\C-\S-a ?\C-a)))
1062 (cancel-kbd-macro-events)
1063 (apply 'isearch-unread keylist))
1064 ((eq search-exit-option 'edit)
1065 (apply 'isearch-unread keylist)
1066 (isearch-edit-string))
1069 (cancel-kbd-macro-events)
1070 (apply 'isearch-unread keylist)
1071 ;; Properly handle scroll-bar and mode-line clicks
1072 ;; for which a dummy prefix event was generated as (aref key 0).
1073 (and (> (length key) 1)
1074 (symbolp (aref key 0))
1075 (listp (aref key 1))
1076 (not (numberp (posn-point (event-start (aref key 1)))))
1077 ;; Convert the event back into its raw form,
1078 ;; with the dummy prefix implicit in the mouse event,
1079 ;; so it will get split up once again.
1080 (progn (setq unread-command-events
1081 (cdr unread-command-events))
1082 (setq main-event (car unread-command-events))
1083 (setcar (cdr (event-start main-event))
1084 (car (nth 1 (event-start main-event))))))
1085 ;; If we got a mouse click, maybe it was read with the buffer
1086 ;; it was clicked on. If so, that buffer, not the current one,
1087 ;; is in isearch mode. So end the search in that buffer.
1088 (if (and (listp main-event)
1089 (setq window (posn-window (event-start main-event)))
1092 (set-buffer (window-buffer window))
1096 (isearch-process-search-string key key)))))
1098 (defun isearch-quote-char ()
1099 "Quote special characters for incremental search."
1101 (isearch-process-search-char (read-quoted-char (isearch-message t))))
1103 (defun isearch-return-char ()
1104 "Convert return into newline for incremental search.
1107 (isearch-process-search-char ?\n))
1109 (defun isearch-printing-char ()
1110 "Add this ordinary printing character to the search string and search."
1112 (if isearch-multibyte-characters-flag
1113 (isearch-process-search-multibyte-characters (isearch-last-command-char))
1114 (isearch-process-search-char (isearch-last-command-char))))
1116 (defun isearch-whitespace-chars ()
1117 "Match all whitespace chars, if in regexp mode.
1118 If you want to search for just a space, type C-q SPC."
1121 (if (and search-whitespace-regexp (not isearch-within-brackets)
1122 (not isearch-invalid-regexp))
1123 (isearch-process-search-string search-whitespace-regexp " ")
1124 (isearch-printing-char))
1126 ;; This way of doing word search doesn't correctly extend current search.
1127 ;; (setq isearch-word t)
1128 ;; (setq isearch-adjusted t)
1129 ;; (goto-char isearch-barrier)
1130 (isearch-printing-char))))
1132 (defun isearch-process-search-char (char)
1133 ;; Append the char to the search string, update the message and re-search.
1134 (isearch-process-search-string
1135 (isearch-char-to-string char)
1136 (isearch-text-char-description char)))
1138 (defun isearch-process-search-string (string message)
1139 (setq isearch-string (concat isearch-string string)
1140 isearch-message (concat isearch-message message))
1141 (isearch-search-and-update))
1146 (defun isearch-ring-adjust1 (advance)
1147 ;; Helper for isearch-ring-adjust
1148 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
1149 (length (length ring))
1150 (yank-pointer-name (if isearch-regexp
1151 'regexp-search-ring-yank-pointer
1152 'search-ring-yank-pointer))
1153 (yank-pointer (eval yank-pointer-name)))
1156 (set yank-pointer-name
1158 (mod (+ (or yank-pointer 0)
1161 (setq isearch-string (nth yank-pointer ring)
1162 isearch-message (mapconcat 'isearch-text-char-description
1163 isearch-string "")))))
1165 (defun isearch-ring-adjust (advance)
1166 ;; Helper for isearch-ring-advance and isearch-ring-retreat
1167 (isearch-ring-adjust1 advance)
1168 (if search-ring-update
1172 (isearch-edit-string)
1174 (isearch-push-state))
1176 (defun isearch-ring-advance ()
1177 "Advance to the next search string in the ring."
1178 ;; This could be more general to handle a prefix arg, but who would use it.
1180 (isearch-ring-adjust 'advance))
1182 (defun isearch-ring-retreat ()
1183 "Retreat to the previous search string in the ring."
1185 (isearch-ring-adjust nil))
1187 (defun isearch-ring-advance-edit (n)
1188 "Insert the next element of the search history into the minibuffer."
1190 (let* ((yank-pointer-name (if isearch-regexp
1191 'regexp-search-ring-yank-pointer
1192 'search-ring-yank-pointer))
1193 (yank-pointer (eval yank-pointer-name))
1194 (ring (if isearch-regexp regexp-search-ring search-ring))
1195 (length (length ring)))
1198 (set yank-pointer-name
1200 (mod (- (or yank-pointer 0) n)
1204 (insert (nth yank-pointer ring))
1205 (goto-char (point-max)))))
1207 (defun isearch-ring-retreat-edit (n)
1208 "Inserts the previous element of the search history into the minibuffer."
1210 (isearch-ring-advance-edit (- n)))
1212 ;;(defun isearch-ring-adjust-edit (advance)
1213 ;; "Use the next or previous search string in the ring while in minibuffer."
1214 ;; (isearch-ring-adjust1 advance)
1216 ;; (insert isearch-string))
1218 ;;(defun isearch-ring-advance-edit ()
1220 ;; (isearch-ring-adjust-edit 'advance))
1222 ;;(defun isearch-ring-retreat-edit ()
1223 ;; "Retreat to the previous search string in the ring while in the minibuffer."
1225 ;; (isearch-ring-adjust-edit nil))
1228 (defun isearch-complete1 ()
1229 ;; Helper for isearch-complete and isearch-complete-edit
1230 ;; Return t if completion OK, nil if no completion exists.
1231 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
1232 (alist (mapcar (function (lambda (string) (list string))) ring))
1233 (completion-ignore-case case-fold-search)
1234 (completion (try-completion isearch-string alist)))
1237 ;; isearch-string stays the same
1239 ((or completion ; not nil, must be a string
1240 (= 0 (length isearch-string))) ; shouldn't have to say this
1241 (if (equal completion isearch-string) ;; no extension?
1243 (if completion-auto-help
1244 (with-output-to-temp-buffer "*Isearch completions*"
1245 (display-completion-list
1246 (all-completions isearch-string alist))))
1249 (setq isearch-string completion))))
1251 (message "No completion") ; waits a second if in minibuffer
1254 (defun isearch-complete ()
1255 "Complete the search string from the strings on the search ring.
1256 The completed string is then editable in the minibuffer.
1257 If there is no completion possible, say so and continue searching."
1259 (if (isearch-complete1)
1260 (isearch-edit-string)
1265 (defun isearch-complete-edit ()
1266 "Same as `isearch-complete' except in the minibuffer."
1268 (setq isearch-string (buffer-string))
1269 (if (isearch-complete1)
1272 (insert isearch-string))))
1275 ;; The search status stack (and isearch window-local variables, not used).
1276 ;; Need a structure for this.
1278 (defun isearch-top-state ()
1279 (let ((cmd (car isearch-cmds)))
1280 (setq isearch-string (car cmd)
1281 isearch-message (car (cdr cmd))
1282 isearch-success (nth 3 cmd)
1283 isearch-forward (nth 4 cmd)
1284 isearch-other-end (nth 5 cmd)
1285 isearch-word (nth 6 cmd)
1286 isearch-invalid-regexp (nth 7 cmd)
1287 isearch-wrapped (nth 8 cmd)
1288 isearch-barrier (nth 9 cmd)
1289 isearch-within-brackets (nth 10 cmd)
1290 isearch-case-fold-search (nth 11 cmd))
1291 (goto-char (car (cdr (cdr cmd))))))
1293 (defun isearch-pop-state ()
1294 (setq isearch-cmds (cdr isearch-cmds))
1298 (defun isearch-push-state ()
1300 (cons (list isearch-string isearch-message (point)
1301 isearch-success isearch-forward isearch-other-end
1303 isearch-invalid-regexp isearch-wrapped isearch-barrier
1304 isearch-within-brackets isearch-case-fold-search)
1310 (defun isearch-message (&optional c-q-hack ellipsis)
1311 ;; Generate and print the message string.
1312 (let ((cursor-in-echo-area ellipsis)
1314 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
1316 (isearch-message-suffix c-q-hack ellipsis)
1320 (let ((message-log-max nil))
1321 (message "%s" m)))))
1323 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
1324 ;; If about to search, and previous search regexp was invalid,
1325 ;; check that it still is. If it is valid now,
1326 ;; let the message we display while searching say that it is valid.
1327 (and isearch-invalid-regexp ellipsis
1329 (progn (re-search-forward isearch-string (point) t)
1330 (setq isearch-invalid-regexp nil
1331 isearch-within-brackets nil))
1333 ;; If currently failing, display no ellipsis.
1334 (or isearch-success (setq ellipsis nil))
1335 (let ((m (concat (if isearch-success "" "failing ")
1336 (if (and isearch-wrapped
1338 (> (point) isearch-opoint)
1339 (< (point) isearch-opoint)))
1341 (if isearch-wrapped "wrapped ")
1342 (if isearch-word "word " "")
1343 (if isearch-regexp "regexp " "")
1344 (if nonincremental "search" "I-search")
1345 (if isearch-forward "" " backward")
1346 (if isearch-multibyte-characters-flag
1347 (concat " [" default-input-method-title "]: ")
1350 (aset m 0 (upcase (aref m 0)))
1354 (defun isearch-message-suffix (&optional c-q-hack ellipsis)
1355 (concat (if c-q-hack "^Q" "")
1356 (if isearch-invalid-regexp
1357 (concat " [" isearch-invalid-regexp "]")
1363 (defun isearch-search ()
1364 ;; Do the search with the current search string.
1365 (isearch-message nil t)
1366 (if (and (eq isearch-case-fold-search t) search-upper-case)
1367 (setq isearch-case-fold-search
1368 (isearch-no-upper-case-p isearch-string isearch-regexp)))
1369 (condition-case lossage
1370 (let ((inhibit-quit nil)
1371 (case-fold-search isearch-case-fold-search)
1373 (if isearch-regexp (setq isearch-invalid-regexp nil))
1374 (setq isearch-within-brackets nil)
1376 (setq isearch-success
1380 'word-search-forward 'word-search-backward))
1383 're-search-forward 're-search-backward))
1385 (if isearch-forward 'search-forward 'search-backward)))
1386 isearch-string nil t))
1387 ;; Clear RETRY unless we matched some invisible text
1388 ;; and we aren't supposed to do that.
1389 (if (or search-invisible
1390 (not isearch-success)
1392 (= (match-beginning 0) (match-end 0))
1393 (not (isearch-range-invisible
1394 (match-beginning 0) (match-end 0))))
1396 (setq isearch-just-started nil)
1398 (setq isearch-other-end
1399 (if isearch-forward (match-beginning 0) (match-end 0)))))
1401 (quit (isearch-unread ?\C-g)
1402 (setq isearch-success nil))
1405 (setq isearch-invalid-regexp (car (cdr lossage)))
1406 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
1407 isearch-invalid-regexp))
1409 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
1410 isearch-invalid-regexp)
1411 (setq isearch-invalid-regexp "incomplete input")))
1413 ;; stack overflow in regexp search.
1414 (setq isearch-invalid-regexp (car (cdr lossage)))))
1418 ;; Ding if failed this time after succeeding last time.
1419 (and (nth 3 (car isearch-cmds))
1421 (goto-char (nth 2 (car isearch-cmds)))))
1423 (defun isearch-range-invisible (beg end)
1424 "Return t if all the bext from BEG to END is invisible."
1426 ;; Check that invisibility runs up to END.
1429 ;; If the following character is currently invisible,
1430 ;; skip all characters with that same `invisible' property value.
1431 ;; Do that over and over.
1432 (while (and (< (point) end)
1434 (get-char-property (point) 'invisible)))
1435 (if (eq buffer-invisibility-spec t)
1437 (or (memq prop buffer-invisibility-spec)
1438 (assq prop buffer-invisibility-spec)))))
1439 (if (get-text-property (point) 'invisible)
1440 (goto-char (next-single-property-change (point) 'invisible
1442 (goto-char (next-overlay-change (point)))))
1443 ;; See if invisibility reaches up thru END.
1449 (defvar isearch-overlay nil)
1451 (defun isearch-highlight (beg end)
1452 (if (or (null search-highlight) (null window-system))
1454 (or isearch-overlay (setq isearch-overlay (make-overlay beg end)))
1455 (move-overlay isearch-overlay beg end (current-buffer))
1456 (overlay-put isearch-overlay 'face
1457 (if (internal-find-face 'isearch nil)
1458 'isearch 'region))))
1460 (defun isearch-dehighlight (totally)
1462 (delete-overlay isearch-overlay)))
1464 ;;; General utilities
1467 (defun isearch-no-upper-case-p (string regexp-flag)
1468 "Return t if there are no upper case chars in STRING.
1469 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
1470 since they have special meaning in a regexp."
1471 (let (quote-flag (i 0) (len (length string)) found)
1472 (while (and (not found) (< i len))
1473 (let ((char (aref string i)))
1474 (if (and regexp-flag (eq char ?\\))
1475 (setq quote-flag (not quote-flag))
1476 (if (and (not quote-flag) (not (eq char (downcase char))))
1481 ;; Portability functions to support various Emacs versions.
1483 (defun isearch-char-to-string (c)
1486 (defun isearch-text-char-description (c)
1487 (if (and (integerp c) (or (< c ?\ ) (= c ?\^?)))
1488 (text-char-description c)
1489 (isearch-char-to-string c)))
1491 ;; General function to unread characters or events.
1492 ;; Also insert them in a keyboard macro being defined.
1493 (defun isearch-unread (&rest char-or-events)
1494 (mapcar 'store-kbd-macro-event char-or-events)
1495 (setq unread-command-events
1496 (append char-or-events unread-command-events)))
1498 (defun isearch-last-command-char ()
1499 ;; General function to return the last command character.
1502 ;;; isearch.el ends here