gtkutil.c (xg_initialize): Initialize id_to_widget here instead
[bpt/emacs.git] / lisp / isearch.el
CommitLineData
55535639 1;;; isearch.el --- incremental search minor mode
3b1e4dd1 2
1f4139d5 3;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1999, 2000, 2001
1ea1fb7e 4;; Free Software Foundation, Inc.
3a801d0c 5
3b1e4dd1 6;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
0f09b616 7;; Maintainer: FSF
117132a6 8;; Keywords: matching
8e1cae6d 9
54d2ecd3 10;; This file is part of GNU Emacs.
8e1cae6d 11
59243403
RS
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
8e1cae6d 17;; GNU Emacs is distributed in the hope that it will be useful,
59243403
RS
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b578f267
EN
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
8e1cae6d 26
3b1e4dd1
ER
27;;; Commentary:
28
8e1cae6d
JB
29;; Instructions
30
08200510
RS
31;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
32;; isearch-mode behaves modally and does not return until the search
117132a6 33;; is completed. It uses a recursive-edit to behave this way.
08200510 34
8e1cae6d 35;; The key bindings active within isearch-mode are defined below in
08200510
RS
36;; `isearch-mode-map' which is given bindings close to the default
37;; characters of the original isearch.el. With `isearch-mode',
38;; however, you can bind multi-character keys and it should be easier
39;; to add new commands. One bug though: keys with meta-prefix cannot
40;; be longer than two chars. Also see minibuffer-local-isearch-map
41;; for bindings active during `isearch-edit-string'.
42
117132a6
DL
43;; isearch-mode should work even if you switch windows with the mouse,
44;; in which case isearch-mode is terminated automatically before the
45;; switch.
08200510
RS
46
47;; The search ring and completion commands automatically put you in
48;; the minibuffer to edit the string. This gives you a chance to
49;; modify the search string before executing the search. There are
50;; three commands to terminate the editing: C-s and C-r exit the
51;; minibuffer and search forward and reverse respectively, while C-m
52;; exits and does a nonincremental search.
53
54;; Exiting immediately from isearch uses isearch-edit-string instead
55;; of nonincremental-search, if search-nonincremental-instead is non-nil.
56;; The name of this option should probably be changed if we decide to
57;; keep the behavior. No point in forcing nonincremental search until
58;; the last possible moment.
59
60;; TODO
eb8c3be9 61;; - Integrate the emacs 19 generalized command history.
08200510
RS
62;; - Think about incorporating query-replace.
63;; - Hooks and options for failed search.
282d89c0 64
3b1e4dd1
ER
65;;; Change Log:
66
b578f267
EN
67;; Changes before those recorded in ChangeLog:
68
69;; Revision 1.4 92/09/14 16:26:02 liberte
70;; Added prefix args to isearch-forward, etc. to switch between
71;; string and regular expression searching.
72;; Added some support for lemacs.
73;; Added general isearch-highlight option - but only for lemacs so far.
74;; Added support for frame switching in emacs 19.
75;; Added word search option to isearch-edit-string.
76;; Renamed isearch-quit to isearch-abort.
77;; Numerous changes to comments and doc strings.
78;;
79;; Revision 1.3 92/06/29 13:10:08 liberte
80;; Moved modal isearch-mode handling into isearch-mode.
81;; Got rid of buffer-local isearch variables.
82;; isearch-edit-string used by ring adjustments, completion, and
83;; nonincremental searching. C-s and C-r are additional exit commands.
84;; Renamed all regex to regexp.
85;; Got rid of found-start and found-point globals.
86;; Generalized handling of upper-case chars.
87
88;; Revision 1.2 92/05/27 11:33:57 liberte
89;; Emacs version 19 has a search ring, which is supported here.
90;; Other fixes found in the version 19 isearch are included here.
91;;
92;; Also see variables search-caps-disable-folding,
93;; search-nonincremental-instead, search-whitespace-regexp, and
94;; commands isearch-toggle-regexp, isearch-edit-string.
95;;
96;; semi-modal isearching is supported.
97
98;; Changes for 1.1
99;; 3/18/92 Fixed invalid-regexp.
100;; 3/18/92 Fixed yanking in regexps.
282d89c0 101
3b1e4dd1 102;;; Code:
08200510
RS
103
104\f
191f025a 105;; Some additional options and constants.
08200510 106
9c1db929
RS
107(defgroup isearch nil
108 "Incremental search minor mode."
117132a6
DL
109 :link '(emacs-commentary-link "isearch")
110 :link '(custom-manual "(emacs)Incremental Search")
9c1db929
RS
111 :prefix "isearch-"
112 :prefix "search-"
113 :group 'matching)
fdf5afa4 114
9c1db929
RS
115
116(defcustom search-exit-option t
117 "*Non-nil means random control characters terminate incremental search."
118 :type 'boolean
119 :group 'isearch)
120
121(defcustom search-slow-window-lines 1
fdf5afa4
RS
122 "*Number of lines in slow search display windows.
123These are the short windows used during incremental search on slow terminals.
124Negative means put the slow search window at the top (normally it's at bottom)
9c1db929
RS
125and the value is minus the number of lines."
126 :type 'integer
127 :group 'isearch)
fdf5afa4 128
9c1db929 129(defcustom search-slow-speed 1200
fdf5afa4
RS
130 "*Highest terminal speed at which to use \"slow\" style incremental search.
131This is the style where a one-line window is created to show the line
9c1db929
RS
132that the search has reached."
133 :type 'integer
134 :group 'isearch)
8e1cae6d 135
9c1db929 136(defcustom search-upper-case 'not-yanks
8e1cae6d 137 "*If non-nil, upper case chars disable case fold searching.
08200510
RS
138That is, upper and lower case chars must match exactly.
139This applies no matter where the chars come from, but does not
fdf5afa4 140apply to chars in regexps that are prefixed with `\\'.
9c1db929
RS
141If this value is `not-yanks', yanked text is always downcased."
142 :type '(choice (const :tag "off" nil)
143 (const not-yanks)
5786b3ed 144 (other :tag "on" t))
9c1db929 145 :group 'isearch)
8e1cae6d 146
9c1db929 147(defcustom search-nonincremental-instead t
8e1cae6d 148 "*If non-nil, do a nonincremental search instead if exiting immediately.
08200510 149Actually, `isearch-edit-string' is called to let you enter the search
9c1db929
RS
150string, and RET terminates editing and does a nonincremental search."
151 :type 'boolean
152 :group 'isearch)
8e1cae6d 153
9c1db929 154(defcustom search-whitespace-regexp "\\s-+"
8e1cae6d 155 "*If non-nil, regular expression to match a sequence of whitespace chars.
e2b992cb 156This applies to regular expression incremental search.
dcb6bf2b
RS
157You might want to use something like \"[ \\t\\r\\n]+\" instead.
158In the Customization buffer, that is `[' followed by a space,
159a tab, a carriage return (control-M), a newline, and `]+'."
9c1db929
RS
160 :type 'regexp
161 :group 'isearch)
8e1cae6d 162
30178dde 163(defcustom search-highlight t
9c1db929
RS
164 "*Non-nil means incremental search highlights the current match."
165 :type 'boolean
166 :group 'isearch)
08200510 167
0352b205
RS
168(defcustom search-invisible 'open
169 "If t incremental search can match hidden text.
170nil means don't match invisible text.
171If the value is `open', if the text matched is made invisible by
172an overlay having an `invisible' property and that overlay has a property
173`isearch-open-invisible', then incremental search will show the contents.
cd59ea72
SM
174\(This applies when using `outline.el' and `hideshow.el'.)
175See also `reveal-mode' if you want overlays to automatically be opened
176whenever point is in one of them."
0352b205
RS
177 :type '(choice (const :tag "Match hidden text" t)
178 (const :tag "Open overlays" open)
79c7a4fa 179 (const :tag "Don't match hidden text" nil))
0352b205
RS
180 :group 'isearch)
181
182(defcustom isearch-hide-immediately t
68c18d6d
RS
183 "If non-nil, re-hide an invisible match right away.
184This variable makes a difference when `search-invisible' is set to `open'.
185It means that after search makes some invisible text visible
186to show the match, it makes the text invisible again when the match moves.
187Ordinarily the text becomes invisible again at the end of the search."
0352b205
RS
188 :type 'boolean
189 :group 'isearch)
86bfaffe 190
6848c9f1
KS
191(defcustom isearch-resume-enabled t
192 "*If non-nil, `isearch-resume' commands are added to the command history."
193 :type 'boolean
194 :group 'isearch)
195
08200510
RS
196(defvar isearch-mode-hook nil
197 "Function(s) to call after starting up an incremental search.")
198
199(defvar isearch-mode-end-hook nil
200 "Function(s) to call after terminating an incremental search.")
201
191f025a 202;; Search ring.
8e1cae6d
JB
203
204(defvar search-ring nil
205 "List of search string sequences.")
08200510 206(defvar regexp-search-ring nil
8e1cae6d
JB
207 "List of regular expression search string sequences.")
208
9c1db929
RS
209(defcustom search-ring-max 16
210 "*Maximum length of search ring before oldest elements are thrown away."
211 :type 'integer
212 :group 'isearch)
213(defcustom regexp-search-ring-max 16
214 "*Maximum length of regexp search ring before oldest elements are thrown away."
215 :type 'integer
216 :group 'isearch)
8e1cae6d
JB
217
218(defvar search-ring-yank-pointer nil
a5dcf63f
RS
219 "Index in `search-ring' of last string reused.
220nil if none yet.")
08200510 221(defvar regexp-search-ring-yank-pointer nil
a5dcf63f
RS
222 "Index in `regexp-search-ring' of last string reused.
223nil if none yet.")
8e1cae6d 224
9c1db929 225(defcustom search-ring-update nil
08200510 226 "*Non-nil if advancing or retreating in the search ring should cause search.
9c1db929
RS
227Default value, nil, means edit the string instead."
228 :type 'boolean
229 :group 'isearch)
08200510 230
191f025a 231;; Define isearch-mode keymap.
8e1cae6d 232
02b2f510
SM
233(defvar isearch-mode-map
234 (let* ((i 0)
235 (map (make-keymap)))
236 (or (vectorp (nth 1 map))
237 (char-table-p (nth 1 map))
238 (error "The initialization of isearch-mode-map must be updated"))
239 ;; Make all multibyte characters search for themselves.
240 (let ((l (generic-character-list))
241 (table (nth 1 map)))
242 (while l
243 (set-char-table-default table (car l) 'isearch-printing-char)
244 (setq l (cdr l))))
245 ;; Make function keys, etc, exit the search.
246 (define-key map [t] 'isearch-other-control-char)
247 ;; Control chars, by default, end isearch mode transparently.
248 ;; We need these explicit definitions because, in a dense keymap,
249 ;; the binding for t does not affect characters.
250 ;; We use a dense keymap to save space.
251 (while (< i ?\ )
252 (define-key map (make-string 1 i) 'isearch-other-control-char)
253 (setq i (1+ i)))
254
255 ;; Single-byte printing chars extend the search string by default.
256 (setq i ?\ )
257 (while (< i 256)
258 (define-key map (vector i) 'isearch-printing-char)
259 (setq i (1+ i)))
260
261 ;; To handle local bindings with meta char prefix keys, define
262 ;; another full keymap. This must be done for any other prefix
263 ;; keys as well, one full keymap per char of the prefix key. It
264 ;; would be simpler to disable the global keymap, and/or have a
265 ;; default local key binding for any key not otherwise bound.
266 (let ((meta-map (make-sparse-keymap)))
267 (define-key map (char-to-string meta-prefix-char) meta-map)
268 (define-key map [escape] meta-map))
269 (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
270
271 ;; Several non-printing chars change the searching behavior.
272 (define-key map "\C-s" 'isearch-repeat-forward)
273 (define-key map "\C-r" 'isearch-repeat-backward)
274 ;; Define M-C-s and M-C-r like C-s and C-r so that the same key
275 ;; combinations can be used to repeat regexp isearches that can
276 ;; be used to start these searches.
277 (define-key map "\M-\C-s" 'isearch-repeat-forward)
278 (define-key map "\M-\C-r" 'isearch-repeat-backward)
279 (define-key map "\177" 'isearch-delete-char)
280 (define-key map "\C-g" 'isearch-abort)
1f4139d5 281
02b2f510
SM
282 ;; This assumes \e is the meta-prefix-char.
283 (or (= ?\e meta-prefix-char)
284 (error "Inconsistency in isearch.el"))
285 (define-key map "\e\e\e" 'isearch-cancel)
286 (define-key map [escape escape escape] 'isearch-cancel)
8e1cae6d 287
02b2f510 288 (define-key map "\C-q" 'isearch-quote-char)
08200510 289
02b2f510
SM
290 (define-key map "\r" 'isearch-exit)
291 (define-key map "\C-j" 'isearch-printing-char)
292 (define-key map "\t" 'isearch-printing-char)
293 (define-key map " " 'isearch-whitespace-chars)
294 (define-key map [?\S-\ ] 'isearch-whitespace-chars)
8e1cae6d 295
868bf43a 296 (define-key map "\C-w" 'isearch-yank-word-or-char)
02b2f510 297 (define-key map "\C-y" 'isearch-yank-line)
08200510 298
02b2f510
SM
299 ;; Define keys for regexp chars * ? |.
300 ;; Nothing special for + because it matches at least once.
301 (define-key map "*" 'isearch-*-char)
302 (define-key map "?" 'isearch-*-char)
303 (define-key map "|" 'isearch-|-char)
08200510 304
191f025a
SM
305 ;; Turned off because I find I expect to get the global definition--rms.
306 ;; ;; Instead bind C-h to special help command for isearch-mode.
307 ;; (define-key map "\C-h" 'isearch-mode-help)
08200510 308
02b2f510
SM
309 (define-key map "\M-n" 'isearch-ring-advance)
310 (define-key map "\M-p" 'isearch-ring-retreat)
311 (define-key map "\M-y" 'isearch-yank-kill)
312
313 (define-key map "\M-\t" 'isearch-complete)
314
315 ;; Pass frame events transparently so they won't exit the search.
316 ;; In particular, if we have more than one display open, then a
317 ;; switch-frame might be generated by someone typing at another keyboard.
318 (define-key map [switch-frame] nil)
319 (define-key map [delete-frame] nil)
320 (define-key map [iconify-frame] nil)
321 (define-key map [make-frame-visible] nil)
3f482bc0 322 (define-key map [mouse-movement] nil)
02b2f510
SM
323 ;; For searching multilingual text.
324 (define-key map "\C-\\" 'isearch-toggle-input-method)
325 (define-key map "\C-^" 'isearch-toggle-specified-input-method)
326
327 ;; People expect to be able to paste with the mouse.
e4af1426 328 (define-key map [mouse-2] #'isearch-mouse-2)
02b2f510
SM
329 (define-key map [down-mouse-2] nil)
330
331 ;; Some bindings you may want to put in your isearch-mode-hook.
332 ;; Suggest some alternates...
333 (define-key map "\M-c" 'isearch-toggle-case-fold)
334 (define-key map "\M-r" 'isearch-toggle-regexp)
335 (define-key map "\M-e" 'isearch-edit-string)
336
337 map)
338 "Keymap for `isearch-mode'.")
339
340(defvar minibuffer-local-isearch-map
341 (let ((map (make-sparse-keymap)))
342 (set-keymap-parent map minibuffer-local-map)
343 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
344 (define-key map "\M-n" 'isearch-ring-advance-edit)
345 (define-key map "\M-p" 'isearch-ring-retreat-edit)
346 (define-key map "\M-\t" 'isearch-complete-edit)
347 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
348 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
349 map)
08200510 350 "Keymap for editing isearch strings in the minibuffer.")
8e1cae6d 351
8e1cae6d 352;; Internal variables declared globally for byte-compiler.
08200510
RS
353;; These are all set with setq while isearching
354;; and bound locally while editing the search string.
355
356(defvar isearch-forward nil) ; Searching in the forward direction.
357(defvar isearch-regexp nil) ; Searching for a regexp.
358(defvar isearch-word nil) ; Searching for words.
cd59ea72 359(defvar isearch-hidden nil) ; Non-nil if the string exists but is invisible.
08200510 360
191f025a
SM
361(defvar isearch-cmds nil
362 "Stack of search status sets.
363Each set is a list of the form:
364 (STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD
365 INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH)")
366
08200510
RS
367(defvar isearch-string "") ; The current search string.
368(defvar isearch-message "") ; text-char-description version of isearch-string
369
370(defvar isearch-success t) ; Searching is currently successful.
371(defvar isearch-invalid-regexp nil) ; Regexp not well formed.
c5f6b356 372(defvar isearch-within-brackets nil) ; Regexp has unclosed [.
08200510
RS
373(defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
374(defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
8e1cae6d 375(defvar isearch-barrier 0)
99ae9e9f 376(defvar isearch-just-started nil)
ddbe3d5f 377(defvar isearch-start-hscroll 0) ; hscroll when starting the search.
8e1cae6d 378
4453091d
RS
379; case-fold-search while searching.
380; either nil, t, or 'yes. 'yes means the same as t except that mixed
381; case in the search string is ignored.
382(defvar isearch-case-fold-search nil)
8e1cae6d 383
67085aba
GM
384(defvar isearch-last-case-fold-search nil)
385
ae1a21c6
MB
386;; Used to save default value while isearch is active
387(defvar isearch-original-minibuffer-message-timeout nil)
388
8e1cae6d
JB
389(defvar isearch-adjusted nil)
390(defvar isearch-slow-terminal-mode nil)
191f025a 391;; If t, using a small window.
08200510 392(defvar isearch-small-window nil)
8e1cae6d 393(defvar isearch-opoint 0)
191f025a 394;; The window configuration active at the beginning of the search.
08200510 395(defvar isearch-window-configuration nil)
8e1cae6d 396
08200510
RS
397;; Flag to indicate a yank occurred, so don't move the cursor.
398(defvar isearch-yank-flag nil)
8e1cae6d 399
191f025a
SM
400;; A function to be called after each input character is processed.
401;; (It is not called after characters that exit the search.)
402;; It is only set from an optional argument to `isearch-mode'.
08200510 403(defvar isearch-op-fun nil)
8e1cae6d 404
191f025a 405;; Is isearch-mode in a recursive edit for modal searching.
08200510 406(defvar isearch-recursive-edit nil)
8e1cae6d 407
191f025a 408;; Should isearch be terminated after doing one search?
08200510
RS
409(defvar isearch-nonincremental nil)
410
411;; New value of isearch-forward after isearch-edit-string.
412(defvar isearch-new-forward nil)
8e1cae6d 413
0352b205
RS
414;; Accumulate here the overlays opened during searching.
415(defvar isearch-opened-overlays nil)
8e1cae6d 416
99848db0
KH
417;; The value of input-method-function when isearch is invoked.
418(defvar isearch-input-method-function nil)
419
420;; A flag to tell if input-method-function is locally bound when
421;; isearch is invoked.
422(defvar isearch-input-method-local-p nil)
423
8e1cae6d
JB
424;; Minor-mode-alist changes - kind of redundant with the
425;; echo area, but if isearching in multiple windows, it can be useful.
426
427(or (assq 'isearch-mode minor-mode-alist)
428 (nconc minor-mode-alist
429 (list '(isearch-mode isearch-mode))))
430
08200510 431(defvar isearch-mode nil) ;; Name of the minor mode, if non-nil.
8e1cae6d
JB
432(make-variable-buffer-local 'isearch-mode)
433
fdf5afa4
RS
434(define-key global-map "\C-s" 'isearch-forward)
435(define-key esc-map "\C-s" 'isearch-forward-regexp)
436(define-key global-map "\C-r" 'isearch-backward)
437(define-key esc-map "\C-r" 'isearch-backward-regexp)
438
191f025a 439;; Entry points to isearch-mode.
8e1cae6d 440
eceee2c0 441(defun isearch-forward (&optional regexp-p no-recursive-edit)
8e1cae6d
JB
442 "\
443Do incremental search forward.
08200510
RS
444With a prefix argument, do an incremental regular expression search instead.
445\\<isearch-mode-map>
8e1cae6d 446As you type characters, they add to the search string and are found.
08200510 447The following non-printing keys are bound in `isearch-mode-map'.
8e1cae6d 448
08200510 449Type \\[isearch-delete-char] to cancel characters from end of search string.
8e1cae6d 450Type \\[isearch-exit] to exit, leaving point at location found.
08200510
RS
451Type LFD (C-j) to match end of line.
452Type \\[isearch-repeat-forward] to search again forward,\
453 \\[isearch-repeat-backward] to search again backward.
21d90805 454Type \\[isearch-yank-word-or-char] to yank word from buffer onto end of search\
08200510
RS
455 string and search for it.
456Type \\[isearch-yank-line] to yank rest of line onto end of search string\
457 and search for it.
8617e346
KH
458Type \\[isearch-yank-kill] to yank last killed text onto end of search string\
459 and search for it.
8e1cae6d 460Type \\[isearch-quote-char] to quote control character to search for it.
08200510
RS
461\\[isearch-abort] while searching or when search has failed cancels input\
462 back to what has
463 been found successfully.
464\\[isearch-abort] when search is successful aborts and moves point to\
465 starting point.
8e1cae6d 466
6c551d4e
EZ
467Type \\[isearch-toggle-case-fold] to toggle search case-sensitivity.
468Type \\[isearch-toggle-regexp] to toggle regular-expression mode.
469Type \\[isearch-edit-string] to edit the search string in the minibuffer.
470
8e1cae6d
JB
471Also supported is a search ring of the previous 16 search strings.
472Type \\[isearch-ring-advance] to search for the next item in the search ring.
08200510
RS
473Type \\[isearch-ring-retreat] to search for the previous item in the search\
474 ring.
475Type \\[isearch-complete] to complete the search string using the search ring.
8e1cae6d 476
1e14b095 477If an input method is turned on in the current buffer, that input
37b20c9b
KH
478method is also active while you are typing a characters to search. To
479toggle the input method, type \\[isearch-toggle-input-method]. It
480also toggles the input method in the current buffer.
481
482To use a different input method for searching, type
1e14b095 483\\[isearch-toggle-specified-input-method], and specify an input method
37b20c9b
KH
484you want to use.
485
08200510
RS
486The above keys, bound in `isearch-mode-map', are often controlled by
487 options; do M-x apropos on search-.* to find them.
8e1cae6d 488Other control and meta characters terminate the search
08200510 489 and are then executed normally (depending on `search-exit-option').
fd49e05c 490Likewise for function keys and mouse button events.
8e1cae6d 491
08200510
RS
492If this function is called non-interactively, it does not return to
493the calling function until the search is done."
8e1cae6d 494
eceee2c0 495 (interactive "P\np")
4ae7d00a 496 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
8e1cae6d 497
eceee2c0 498(defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
8e1cae6d
JB
499 "\
500Do incremental search forward for regular expression.
08200510 501With a prefix argument, do a regular string search instead.
8e1cae6d
JB
502Like ordinary incremental search except that your input
503is treated as a regexp. See \\[isearch-forward] for more info."
eceee2c0 504 (interactive "P\np")
4ae7d00a 505 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
8e1cae6d 506
eceee2c0 507(defun isearch-backward (&optional regexp-p no-recursive-edit)
8e1cae6d
JB
508 "\
509Do incremental search backward.
08200510 510With a prefix argument, do a regular expression search instead.
8e1cae6d 511See \\[isearch-forward] for more information."
eceee2c0 512 (interactive "P\np")
4ae7d00a 513 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
8e1cae6d 514
eceee2c0 515(defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
8e1cae6d
JB
516 "\
517Do incremental search backward for regular expression.
08200510 518With a prefix argument, do a regular string search instead.
8e1cae6d
JB
519Like ordinary incremental search except that your input
520is treated as a regexp. See \\[isearch-forward] for more info."
eceee2c0 521 (interactive "P\np")
4ae7d00a 522 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
08200510
RS
523
524
525(defun isearch-mode-help ()
526 (interactive)
527 (describe-function 'isearch-forward)
528 (isearch-update))
8e1cae6d
JB
529
530\f
8e1cae6d
JB
531;; isearch-mode only sets up incremental search for the minor mode.
532;; All the work is done by the isearch-mode commands.
533
08200510 534;; Not used yet:
d7fa5aa2 535;;(defvar isearch-commands '(isearch-forward isearch-backward
08200510
RS
536;; isearch-forward-regexp isearch-backward-regexp)
537;; "List of commands for which isearch-mode does not recursive-edit.")
538
539
540(defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
79ce455d
RS
541 "Start isearch minor mode. Called by `isearch-forward', etc.
542
543\\{isearch-mode-map}"
8e1cae6d
JB
544
545 ;; Initialize global vars.
546 (setq isearch-forward forward
547 isearch-regexp regexp
08200510 548 isearch-word word-p
8e1cae6d 549 isearch-op-fun op-fun
67085aba 550 isearch-last-case-fold-search isearch-case-fold-search
8e1cae6d
JB
551 isearch-case-fold-search case-fold-search
552 isearch-string ""
553 isearch-message ""
554 isearch-cmds nil
555 isearch-success t
556 isearch-wrapped nil
557 isearch-barrier (point)
558 isearch-adjusted nil
559 isearch-yank-flag nil
560 isearch-invalid-regexp nil
c5f6b356 561 isearch-within-brackets nil
0cabad13 562 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
8e1cae6d 563 (> (window-height)
fad241d3
RS
564 (* 4
565 (abs search-slow-window-lines))))
8e1cae6d
JB
566 isearch-other-end nil
567 isearch-small-window nil
99ae9e9f 568 isearch-just-started t
ddbe3d5f 569 isearch-start-hscroll (window-hscroll)
8e1cae6d 570
8e1cae6d 571 isearch-opoint (point)
a5dcf63f 572 search-ring-yank-pointer nil
0352b205 573 isearch-opened-overlays nil
99848db0
KH
574 isearch-input-method-function input-method-function
575 isearch-input-method-local-p (local-variable-p 'input-method-function)
ae1a21c6
MB
576 regexp-search-ring-yank-pointer nil
577
578 ;; Save the original value of `minibuffer-message-timeout', and
579 ;; set it to nil so that isearch's messages don't get timed out.
580 isearch-original-minibuffer-message-timeout minibuffer-message-timeout
581 minibuffer-message-timeout nil)
99848db0
KH
582
583 ;; We must bypass input method while reading key. When a user type
584 ;; printable character, appropriate input method is turned on in
380866a2 585 ;; minibuffer to read multibyte characters.
99848db0
KH
586 (or isearch-input-method-local-p
587 (make-local-variable 'input-method-function))
588 (setq input-method-function nil)
589
99ae9e9f 590 (looking-at "")
292a8dff
RS
591 (setq isearch-window-configuration
592 (if isearch-slow-terminal-mode (current-window-configuration) nil))
70418205 593
18ce7555
RS
594 ;; Maybe make minibuffer frame visible and/or raise it.
595 (let ((frame (window-frame (minibuffer-window))))
360e0dd5
RS
596 (unless (memq (frame-live-p frame) '(nil t))
597 (unless (frame-visible-p frame)
598 (make-frame-visible frame))
599 (if minibuffer-auto-raise
600 (raise-frame frame))))
18ce7555 601
8e1cae6d 602 (setq isearch-mode " Isearch") ;; forward? regexp?
1cd3732c 603 (force-mode-line-update)
8e1cae6d
JB
604
605 (isearch-push-state)
606
c7955222 607 (setq overriding-terminal-local-map isearch-mode-map)
8e1cae6d
JB
608 (isearch-update)
609 (run-hooks 'isearch-mode-hook)
08200510 610
bfe2d334 611 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
7e56ea04 612 (add-hook 'kbd-macro-termination-hook 'isearch-done)
6e5cd0ae 613
08200510
RS
614 ;; isearch-mode can be made modal (in the sense of not returning to
615 ;; the calling function until searching is completed) by entering
616 ;; a recursive-edit and exiting it when done isearching.
130bf67c
RS
617 (if recursive-edit
618 (let ((isearch-recursive-edit t))
619 (recursive-edit)))
0daa17f3 620 isearch-success)
8e1cae6d
JB
621
622
8e1cae6d
JB
623;; Some high level utilities. Others below.
624
625(defun isearch-update ()
191f025a 626 ;; Called after each command to update the display.
4c01d4bd
RS
627 (if (and (null unread-command-events)
628 (null executing-kbd-macro))
8e1cae6d 629 (progn
c982ab21
GM
630 (if (not (input-pending-p))
631 (isearch-message))
632 (if (and isearch-slow-terminal-mode
633 (not (or isearch-small-window
634 (pos-visible-in-window-p))))
635 (let ((found-point (point)))
636 (setq isearch-small-window t)
637 (move-to-window-line 0)
638 (let ((window-min-height 1))
639 (split-window nil (if (< search-slow-window-lines 0)
640 (1+ (- search-slow-window-lines))
641 (- (window-height)
642 (1+ search-slow-window-lines)))))
643 (if (< search-slow-window-lines 0)
644 (progn (vertical-motion (- 1 search-slow-window-lines))
645 (set-window-start (next-window) (point))
646 (set-window-hscroll (next-window)
647 (window-hscroll))
648 (set-window-hscroll (selected-window) 0))
649 (other-window 1))
ddbe3d5f
RS
650 (goto-char found-point))
651 ;; Keep same hscrolling as at the start of the search when possible
652 (let ((current-scroll (window-hscroll)))
653 (set-window-hscroll (selected-window) isearch-start-hscroll)
654 (unless (pos-visible-in-window-p)
655 (set-window-hscroll (selected-window) current-scroll))))
656 (if isearch-other-end
c982ab21
GM
657 (if (< isearch-other-end (point)) ; isearch-forward?
658 (isearch-highlight isearch-other-end (point))
659 (isearch-highlight (point) isearch-other-end))
660 (isearch-dehighlight nil))
661 ))
8e1cae6d
JB
662 (setq ;; quit-flag nil not for isearch-mode
663 isearch-adjusted nil
664 isearch-yank-flag nil)
a5cc922e
KH
665 (isearch-lazy-highlight-new-loop)
666 ;; We must prevent the point moving to the end of composition when a
667 ;; part of the composition has just been searched.
668 (setq disable-point-adjustment t))
8e1cae6d 669
0daa17f3 670(defun isearch-done (&optional nopush edit)
6848c9f1
KS
671 (if isearch-resume-enabled
672 (let ((command `(isearch-resume ,isearch-string ,isearch-regexp
673 ,isearch-word ,isearch-forward
674 ,isearch-message
675 ',isearch-case-fold-search)))
676 (unless (equal (car command-history) command)
677 (setq command-history (cons command command-history)))))
c40a4de1 678
bfe2d334 679 (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
7e56ea04 680 (remove-hook 'kbd-macro-termination-hook 'isearch-done)
d196f58d
GM
681 (setq isearch-lazy-highlight-start nil)
682
8e1cae6d 683 ;; Called by all commands that terminate isearch-mode.
35a4d143 684 ;; If NOPUSH is non-nil, we don't push the string on the search ring.
c7955222 685 (setq overriding-terminal-local-map nil)
08200510 686 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
ae1a21c6 687 (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
08200510 688 (isearch-dehighlight t)
67ecad4e 689 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
08200510
RS
690 (let ((found-start (window-start (selected-window)))
691 (found-point (point)))
70418205
RS
692 (if isearch-window-configuration
693 (set-window-configuration isearch-window-configuration))
08200510 694
d49b6338
RS
695 (if isearch-small-window
696 (goto-char found-point)
697 ;; Exiting the save-window-excursion clobbers window-start; restore it.
9821535a 698 (set-window-start (selected-window) found-start t))
d49b6338 699
08200510
RS
700 ;; If there was movement, mark the starting position.
701 ;; Maybe should test difference between and set mark iff > threshold.
702 (if (/= (point) isearch-opoint)
9821535a
RS
703 (or (and transient-mark-mode mark-active)
704 (progn
705 (push-mark isearch-opoint t)
f3acf6f5 706 (or executing-kbd-macro (> (minibuffer-depth) 0)
9821535a 707 (message "Mark saved where search started"))))))
08200510
RS
708
709 (setq isearch-mode nil)
99848db0
KH
710 (if isearch-input-method-local-p
711 (setq input-method-function isearch-input-method-function)
712 (kill-local-variable 'input-method-function))
713
1cd3732c 714 (force-mode-line-update)
8e1cae6d 715
df01192b
RS
716 ;; If we ended in the middle of some intangible text,
717 ;; move to the further end of that intangible text.
718 (let ((after (if (eobp) nil
719 (get-text-property (point) 'intangible)))
720 (before (if (bobp) nil
721 (get-text-property (1- (point)) 'intangible))))
722 (when (and before after (eq before after))
723 (if isearch-forward
724 (goto-char (next-single-property-change (point) 'intangible))
725 (goto-char (previous-single-property-change (point) 'intangible)))))
726
35a4d143 727 (if (and (> (length isearch-string) 0) (not nopush))
8e1cae6d 728 ;; Update the ring data.
73d2bf95 729 (isearch-update-ring isearch-string isearch-regexp))
8e1cae6d 730
8e1cae6d 731 (run-hooks 'isearch-mode-end-hook)
0daa17f3 732 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
08200510 733
73d2bf95
RS
734(defun isearch-update-ring (string &optional regexp)
735 "Add STRING to the beginning of the search ring.
736REGEXP says which ring to use."
737 (if regexp
738 (if (or (null regexp-search-ring)
fd89878d 739 (not (string= string (car regexp-search-ring))))
73d2bf95
RS
740 (progn
741 (setq regexp-search-ring
fd89878d 742 (cons string regexp-search-ring))
73d2bf95
RS
743 (if (> (length regexp-search-ring) regexp-search-ring-max)
744 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
745 nil))))
746 (if (or (null search-ring)
fd89878d 747 (not (string= string (car search-ring))))
73d2bf95 748 (progn
fd89878d 749 (setq search-ring (cons string search-ring))
73d2bf95
RS
750 (if (> (length search-ring) search-ring-max)
751 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
752
191f025a
SM
753;; Switching buffers should first terminate isearch-mode.
754;; ;; For Emacs 19, the frame switch event is handled.
755;; (defun isearch-switch-frame-handler ()
756;; (interactive) ;; Is this necessary?
757;; ;; First terminate isearch-mode.
758;; (isearch-done)
759;; (isearch-clean-overlays)
760;; (handle-switch-frame (car (cdr last-command-char))))
08200510 761
8e1cae6d 762\f
8e1cae6d
JB
763;; Commands active while inside of the isearch minor mode.
764
765(defun isearch-exit ()
766 "Exit search normally.
767However, if this is the first command after starting incremental
768search and `search-nonincremental-instead' is non-nil, do a
08200510 769nonincremental search instead via `isearch-edit-string'."
8e1cae6d
JB
770 (interactive)
771 (if (and search-nonincremental-instead
772 (= 0 (length isearch-string)))
08200510
RS
773 (let ((isearch-nonincremental t))
774 (isearch-edit-string)))
0352b205
RS
775 (isearch-done)
776 (isearch-clean-overlays))
8e1cae6d
JB
777
778
779(defun isearch-edit-string ()
08200510
RS
780 "Edit the search string in the minibuffer.
781The following additional command keys are active while editing.
782\\<minibuffer-local-isearch-map>
783\\[exit-minibuffer] to resume incremental searching with the edited string.
784\\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
785\\[isearch-forward-exit-minibuffer] to resume isearching forward.
8eb40e74 786\\[isearch-reverse-exit-minibuffer] to resume isearching backward.
08200510 787\\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
eb8c3be9 788\\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
08200510 789\\[isearch-complete-edit] to complete the search string using the search ring.
8eb40e74 790\\<isearch-mode-map>
21d90805 791If first char entered is \\[isearch-yank-word-or-char], then do word search instead."
08200510
RS
792
793 ;; This code is very hairy for several reasons, explained in the code.
794 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
795 ;; If there were a way to catch any change of buffer from the minibuffer,
796 ;; this could be simplified greatly.
eb8c3be9 797 ;; Editing doesn't back up the search point. Should it?
8e1cae6d 798 (interactive)
08200510 799 (condition-case err
e900ced4
RS
800 (progn
801 (let ((isearch-nonincremental isearch-nonincremental)
802
803 ;; Locally bind all isearch global variables to protect them
804 ;; from recursive isearching.
805 ;; isearch-string -message and -forward are not bound
806 ;; so they may be changed. Instead, save the values.
807 (isearch-new-string isearch-string)
808 (isearch-new-message isearch-message)
809 (isearch-new-forward isearch-forward)
810 (isearch-new-word isearch-word)
811
812 (isearch-regexp isearch-regexp)
813 (isearch-op-fun isearch-op-fun)
814 (isearch-cmds isearch-cmds)
815 (isearch-success isearch-success)
816 (isearch-wrapped isearch-wrapped)
817 (isearch-barrier isearch-barrier)
818 (isearch-adjusted isearch-adjusted)
819 (isearch-yank-flag isearch-yank-flag)
820 (isearch-invalid-regexp isearch-invalid-regexp)
821 (isearch-within-brackets isearch-within-brackets)
822 ;;; Don't bind this. We want isearch-search, below, to set it.
823 ;;; And the old value won't matter after that.
824 ;;; (isearch-other-end isearch-other-end)
825 ;;; Perhaps some of these other variables should be bound for a
826 ;;; shorter period, ending before the next isearch-search.
827 ;;; But there doesn't seem to be a real bug, so let's not risk it now.
828 (isearch-opoint isearch-opoint)
829 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
830 (isearch-small-window isearch-small-window)
831 (isearch-recursive-edit isearch-recursive-edit)
832 ;; Save current configuration so we can restore it here.
833 (isearch-window-configuration (current-window-configuration))
ae1a21c6
MB
834
835 ;; Temporarily restore `minibuffer-message-timeout'.
836 (minibuffer-message-timeout
837 isearch-original-minibuffer-message-timeout)
838 (isearch-original-minibuffer-message-timeout
839 isearch-original-minibuffer-message-timeout)
e900ced4
RS
840 )
841
842 ;; Actually terminate isearching until editing is done.
843 ;; This is so that the user can do anything without failure,
844 ;; like switch buffers and start another isearch, and return.
845 (condition-case err
846 (isearch-done t t)
847 (exit nil)) ; was recursive editing
848
849 (isearch-message) ;; for read-char
850 (unwind-protect
851 (let* (;; Why does following read-char echo?
852 ;;(echo-keystrokes 0) ;; not needed with above message
853 (e (let ((cursor-in-echo-area t))
854 (read-event)))
855 ;; Binding minibuffer-history-symbol to nil is a work-around
856 ;; for some incompatibility with gmhist.
857 (minibuffer-history-symbol)
858 (message-log-max nil))
859 ;; If the first character the user types when we prompt them
860 ;; for a string is the yank-word character, then go into
861 ;; word-search mode. Otherwise unread that character and
862 ;; read a key the normal way.
863 ;; Word search does not apply (yet) to regexp searches,
864 ;; no check is made here.
865 (message (isearch-message-prefix nil nil t))
88715f05
RS
866 (if (memq (lookup-key isearch-mode-map (vector e))
867 '(isearch-yank-word
868 isearch-yank-word-or-char))
e900ced4
RS
869 (setq isearch-word t;; so message-prefix is right
870 isearch-new-word t)
871 (cancel-kbd-macro-events)
872 (isearch-unread e))
873 (setq cursor-in-echo-area nil)
874 (setq isearch-new-string
875 (let (junk-ring)
876 (read-from-minibuffer
877 (isearch-message-prefix nil nil isearch-nonincremental)
878 isearch-string
879 minibuffer-local-isearch-map nil
880 'junk-ring))
881 isearch-new-message
882 (mapconcat 'isearch-text-char-description
883 isearch-new-string "")))
884 ;; Always resume isearching by restarting it.
885 (isearch-mode isearch-forward
886 isearch-regexp
887 isearch-op-fun
888 nil
889 isearch-word)
890
891 ;; Copy new local values to isearch globals
892 (setq isearch-string isearch-new-string
893 isearch-message isearch-new-message
894 isearch-forward isearch-new-forward
895 isearch-word isearch-new-word))
896
897 ;; Empty isearch-string means use default.
898 (if (= 0 (length isearch-string))
899 (setq isearch-string (or (car (if isearch-regexp
900 regexp-search-ring
901 search-ring))
8cc3c821
RS
902 "")
903
904 isearch-message
905 (mapconcat 'isearch-text-char-description
906 isearch-string ""))
e900ced4
RS
907 ;; This used to set the last search string,
908 ;; but I think it is not right to do that here.
909 ;; Only the string actually used should be saved.
910 ))
911
912 ;; Push the state as of before this C-s.
913 (isearch-push-state)
08200510
RS
914
915 ;; Reinvoke the pending search.
08200510
RS
916 (isearch-search)
917 (isearch-update)
918 (if isearch-nonincremental
919 (progn
920 ;; (sit-for 1) ;; needed if isearch-done does: (message "")
921 (isearch-done))))
8e1cae6d 922
08200510
RS
923 (quit ; handle abort-recursive-edit
924 (isearch-abort) ;; outside of let to restore outside global values
925 )))
926
927(defun isearch-nonincremental-exit-minibuffer ()
928 (interactive)
929 (setq isearch-nonincremental t)
930 (exit-minibuffer))
931
932(defun isearch-forward-exit-minibuffer ()
933 (interactive)
934 (setq isearch-new-forward t)
935 (exit-minibuffer))
8e1cae6d 936
08200510 937(defun isearch-reverse-exit-minibuffer ()
8e1cae6d 938 (interactive)
08200510
RS
939 (setq isearch-new-forward nil)
940 (exit-minibuffer))
941
19993c54
RS
942(defun isearch-cancel ()
943 "Terminate the search and go back to the starting point."
944 (interactive)
945 (goto-char isearch-opoint)
946 (isearch-done t)
0352b205 947 (isearch-clean-overlays)
19993c54 948 (signal 'quit nil)) ; and pass on quit signal
08200510
RS
949
950(defun isearch-abort ()
b7852303 951 "Abort incremental search mode if searching is successful, signaling quit.
08200510 952Otherwise, revert to previous successful search and continue searching.
b7852303 953Use `isearch-exit' to quit without signaling."
08200510 954 (interactive)
eb8c3be9 955;; (ding) signal instead below, if quitting
8e1cae6d
JB
956 (discard-input)
957 (if isearch-success
958 ;; If search is successful, move back to starting point
959 ;; and really do quit.
960 (progn (goto-char isearch-opoint)
509ed182 961 (setq isearch-success nil)
35a4d143 962 (isearch-done t) ; exit isearch
0352b205 963 (isearch-clean-overlays)
a5dcf63f 964 (signal 'quit nil)) ; and pass on quit signal
925a67ca
RS
965 ;; If search is failing, or has an incomplete regexp,
966 ;; rub out until it is once more successful.
967 (while (or (not isearch-success) isearch-invalid-regexp)
968 (isearch-pop-state))
8e1cae6d
JB
969 (isearch-update)))
970
8e1cae6d
JB
971(defun isearch-repeat (direction)
972 ;; Utility for isearch-repeat-forward and -backward.
973 (if (eq isearch-forward (eq direction 'forward))
974 ;; C-s in forward or C-r in reverse.
975 (if (equal isearch-string "")
976 ;; If search string is empty, use last one.
977 (setq isearch-string
8e1cae6d 978 (or (if isearch-regexp
a5dcf63f
RS
979 (car regexp-search-ring)
980 (car search-ring))
135f293b 981 (error "No previous search string"))
8e1cae6d 982 isearch-message
08200510 983 (mapconcat 'isearch-text-char-description
67085aba
GM
984 isearch-string "")
985 isearch-case-fold-search isearch-last-case-fold-search)
8e1cae6d
JB
986 ;; If already have what to search for, repeat it.
987 (or isearch-success
02b2f510 988 (progn
8e1cae6d
JB
989 (goto-char (if isearch-forward (point-min) (point-max)))
990 (setq isearch-wrapped t))))
991 ;; C-s in reverse or C-r in forward, change direction.
992 (setq isearch-forward (not isearch-forward)))
993
994 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
6fefdc4b
RS
995
996 (if (equal isearch-string "")
997 (setq isearch-success t)
99ae9e9f
KH
998 (if (and isearch-success (equal (match-end 0) (match-beginning 0))
999 (not isearch-just-started))
8e1cae6d
JB
1000 ;; If repeating a search that found
1001 ;; an empty string, ensure we advance.
6fefdc4b
RS
1002 (if (if isearch-forward (eobp) (bobp))
1003 ;; If there's nowhere to advance to, fail (and wrap next time).
1004 (progn
1005 (setq isearch-success nil)
1006 (ding))
1007 (forward-char (if isearch-forward 1 -1))
1008 (isearch-search))
1009 (isearch-search)))
1010
8e1cae6d
JB
1011 (isearch-push-state)
1012 (isearch-update))
1013
1014(defun isearch-repeat-forward ()
1015 "Repeat incremental search forwards."
1016 (interactive)
1017 (isearch-repeat 'forward))
1018
1019(defun isearch-repeat-backward ()
1020 "Repeat incremental search backwards."
1021 (interactive)
1022 (isearch-repeat 'backward))
1023
1024(defun isearch-toggle-regexp ()
1025 "Toggle regexp searching on or off."
1026 ;; The status stack is left unchanged.
1027 (interactive)
1028 (setq isearch-regexp (not isearch-regexp))
08200510 1029 (if isearch-regexp (setq isearch-word nil))
8e1cae6d
JB
1030 (isearch-update))
1031
4453091d
RS
1032(defun isearch-toggle-case-fold ()
1033 "Toggle case folding in searching on or off."
1034 (interactive)
1035 (setq isearch-case-fold-search
1036 (if isearch-case-fold-search nil 'yes))
a56687f1
KH
1037 (let ((message-log-max nil))
1038 (message "%s%s [case %ssensitive]"
1039 (isearch-message-prefix nil nil isearch-nonincremental)
1040 isearch-message
1041 (if isearch-case-fold-search "in" "")))
4453091d
RS
1042 (setq isearch-adjusted t)
1043 (sit-for 1)
1044 (isearch-update))
1045
8e1cae6d 1046(defun isearch-delete-char ()
d6b8a1c0 1047 "Discard last input item and move point back.
8e1cae6d
JB
1048If no previous match was done, just beep."
1049 (interactive)
1050 (if (null (cdr isearch-cmds))
1051 (ding)
1052 (isearch-pop-state))
1053 (isearch-update))
1054
1055
9cf081fa
KH
1056(defun isearch-yank-string (string)
1057 "Pull STRING into search string."
1058 ;; Downcase the string if not supposed to case-fold yanked strings.
1059 (if (and isearch-case-fold-search
1060 (eq 'not-yanks search-upper-case))
1061 (setq string (downcase string)))
1062 (if isearch-regexp (setq string (regexp-quote string)))
1063 (setq isearch-string (concat isearch-string string)
1064 isearch-message
1065 (concat isearch-message
1066 (mapconcat 'isearch-text-char-description
1067 string ""))
1068 ;; Don't move cursor in reverse search.
1069 isearch-yank-flag t)
8e1cae6d
JB
1070 (isearch-search-and-update))
1071
30d47262
RS
1072(defun isearch-yank-kill ()
1073 "Pull string from kill ring into search string."
1074 (interactive)
9cf081fa
KH
1075 (isearch-yank-string (current-kill 0)))
1076
1077(defun isearch-yank-x-selection ()
117132a6 1078 "Pull current X selection into search string."
9cf081fa
KH
1079 (interactive)
1080 (isearch-yank-string (x-get-selection)))
8e1cae6d 1081
e4af1426 1082
191f025a 1083(defun isearch-mouse-2 (click)
e4af1426 1084 "Handle mouse-2 in Isearch mode.
117132a6 1085For a click in the echo area, invoke `isearch-yank-x-selection'.
e4af1426 1086Otherwise invoke whatever mouse-2 is bound to outside of Isearch."
191f025a 1087 (interactive "e")
e4af1426
GM
1088 (let* ((w (posn-window (event-start click)))
1089 (overriding-terminal-local-map nil)
1090 (key (vector (event-basic-type click)))
191f025a
SM
1091 ;; FIXME: `key-binding' should accept an event as argument
1092 ;; and do all the overlay/text-properties lookup etc...
1093 (binding (with-current-buffer
1094 (if (window-live-p w) (window-buffer w) (current-buffer))
1095 (key-binding key))))
117132a6
DL
1096 (if (and (window-minibuffer-p w)
1097 (not (minibuffer-window-active-p w))) ; in echo area
1098 (isearch-yank-x-selection)
cd59ea72 1099 (when (functionp binding)
191f025a 1100 (call-interactively binding)))))
e4af1426 1101
117132a6 1102
29e53a0a
KF
1103(defun isearch-yank-internal (jumpform)
1104 "Pull the text from point to the point reached by JUMPFORM.
1105JUMPFORM is a lambda expression that takes no arguments and returns a
1106buffer position, possibly having moved point to that position. For
1107example, it might move point forward by a word and return point, or it
1108might return the position of the end of the line."
9cf081fa
KH
1109 (isearch-yank-string
1110 (save-excursion
1111 (and (not isearch-forward) isearch-other-end
1112 (goto-char isearch-other-end))
29e53a0a
KF
1113 (buffer-substring-no-properties (point) (funcall jumpform)))))
1114
1115(defun isearch-yank-char ()
1116 "Pull next letter from buffer into search string."
1117 (interactive)
1118 (isearch-yank-internal (lambda () (forward-char 1) (point))))
1119
868bf43a
RS
1120(defun isearch-yank-word-or-char ()
1121 "Pull next character or word from buffer into search string."
1122 (interactive)
21d90805
KF
1123 (isearch-yank-internal
1124 (lambda ()
1125 (if (or (= (char-syntax (or (char-after) 0)) ?w)
1126 (= (char-syntax (or (char-after (1+ (point))) 0)) ?w))
1127 (forward-word 1)
1128 (forward-char 1)) (point))))
868bf43a 1129
29e53a0a
KF
1130(defun isearch-yank-word ()
1131 "Pull next word from buffer into search string."
1132 (interactive)
1133 (isearch-yank-internal (lambda () (forward-word 1) (point))))
8e1cae6d
JB
1134
1135(defun isearch-yank-line ()
1136 "Pull rest of line from buffer into search string."
1137 (interactive)
8fd4d684 1138 (isearch-yank-internal 'line-end-position))
8e1cae6d
JB
1139
1140
1141(defun isearch-search-and-update ()
1142 ;; Do the search and update the display.
191f025a
SM
1143 (when (or isearch-success
1144 ;; unsuccessful regexp search may become
1145 ;; successful by addition of characters which
1146 ;; make isearch-string valid
cd59ea72
SM
1147 isearch-regexp
1148 ;; If the string was found but was completely invisible,
1149 ;; it might now be partly visible, so try again.
1150 (prog1 isearch-hidden (setq isearch-hidden nil)))
8e1cae6d
JB
1151 ;; In reverse search, adding stuff at
1152 ;; the end may cause zero or many more chars to be
1153 ;; matched, in the string following point.
1154 ;; Allow all those possibilities without moving point as
1155 ;; long as the match does not extend past search origin.
1156 (if (and (not isearch-forward) (not isearch-adjusted)
1157 (condition-case ()
99ae9e9f 1158 (let ((case-fold-search isearch-case-fold-search))
ec0a2f45
KH
1159 (if (and (eq case-fold-search t) search-upper-case)
1160 (setq case-fold-search
1161 (isearch-no-upper-case-p isearch-string isearch-regexp)))
99ae9e9f
KH
1162 (looking-at (if isearch-regexp isearch-string
1163 (regexp-quote isearch-string))))
8e1cae6d 1164 (error nil))
bd6a8414 1165 (or isearch-yank-flag
191f025a 1166 (<= (match-end 0)
bd6a8414 1167 (min isearch-opoint isearch-barrier))))
d64b1d96 1168 (progn
191f025a 1169 (setq isearch-success t
d64b1d96
RS
1170 isearch-invalid-regexp nil
1171 isearch-within-brackets nil
1172 isearch-other-end (match-end 0))
1173 (if (and (eq isearch-case-fold-search t) search-upper-case)
1174 (setq isearch-case-fold-search
1175 (isearch-no-upper-case-p isearch-string isearch-regexp))))
8e1cae6d
JB
1176 ;; Not regexp, not reverse, or no match at point.
1177 (if (and isearch-other-end (not isearch-adjusted))
1178 (goto-char (if isearch-forward isearch-other-end
191f025a
SM
1179 (min isearch-opoint
1180 isearch-barrier
8e1cae6d
JB
1181 (1+ isearch-other-end)))))
1182 (isearch-search)
1183 ))
1184 (isearch-push-state)
1185 (if isearch-op-fun (funcall isearch-op-fun))
1186 (isearch-update))
1187
1188
1189;; *, ?, and | chars can make a regexp more liberal.
08200510 1190;; They can make a regexp match sooner or make it succeed instead of failing.
8e1cae6d
JB
1191;; So go back to place last successful search started
1192;; or to the last ^S/^R (barrier), whichever is nearer.
08200510 1193;; + needs no special handling because the string must match at least once.
8e1cae6d
JB
1194
1195(defun isearch-*-char ()
1196 "Handle * and ? specially in regexps."
1197 (interactive)
191f025a 1198 (if isearch-regexp
bd6a8414
RS
1199 (let ((idx (length isearch-string)))
1200 (while (and (> idx 0)
1201 (eq (aref isearch-string (1- idx)) ?\\))
1202 (setq idx (1- idx)))
1203 (when (= (mod (- (length isearch-string) idx) 2) 0)
1204 (setq isearch-adjusted t)
1205 ;; Get the isearch-other-end from before the last search.
1206 ;; We want to start from there,
1207 ;; so that we don't retreat farther than that.
1208 ;; (car isearch-cmds) is after last search;
1209 ;; (car (cdr isearch-cmds)) is from before it.
1210 (let ((cs (nth 5 (car (cdr isearch-cmds)))))
1211 (setq cs (or cs isearch-barrier))
1212 (goto-char
1213 (if isearch-forward
1214 (max cs isearch-barrier)
1215 (min cs isearch-barrier)))))))
117132a6 1216 (isearch-process-search-char last-command-char))
8e1cae6d
JB
1217
1218
8e1cae6d
JB
1219(defun isearch-|-char ()
1220 "If in regexp search, jump to the barrier."
1221 (interactive)
1222 (if isearch-regexp
1223 (progn
1224 (setq isearch-adjusted t)
1225 (goto-char isearch-barrier)))
117132a6 1226 (isearch-process-search-char last-command-char))
8e1cae6d
JB
1227
1228
b457cc3b 1229(defalias 'isearch-other-control-char 'isearch-other-meta-char)
8e1cae6d
JB
1230
1231(defun isearch-other-meta-char ()
8f90f594 1232 "Exit the search normally and reread this key sequence.
35a4d143
RS
1233But only if `search-exit-option' is non-nil, the default.
1234If it is the symbol `edit', the search string is edited in the minibuffer
1235and the meta character is unread so that it applies to editing the string."
8e1cae6d 1236 (interactive)
c6431f12
KH
1237 (let* ((key (this-command-keys))
1238 (main-event (aref key 0))
1239 (keylist (listify-key-sequence key)))
24b5caec 1240 (cond ((and (= (length key) 1)
d94eb6eb 1241 (let ((lookup (lookup-key function-key-map key)))
3f866b53
KH
1242 (not (or (null lookup) (integerp lookup)
1243 (keymapp lookup)))))
24b5caec
RS
1244 ;; Handle a function key that translates into something else.
1245 ;; If the key has a global definition too,
1246 ;; exit and unread the key itself, so its global definition runs.
1247 ;; Otherwise, unread the translation,
1248 ;; so that the translated key takes effect within isearch.
d94eb6eb 1249 (cancel-kbd-macro-events)
24b5caec 1250 (if (lookup-key global-map key)
02b2f510 1251 (progn
24b5caec
RS
1252 (isearch-done)
1253 (apply 'isearch-unread keylist))
a5cc922e
KH
1254 (setq keylist
1255 (listify-key-sequence (lookup-key function-key-map key)))
1256 (while keylist
1257 (setq key (car keylist))
1258 ;; If KEY is a printing char, we handle it here
1259 ;; directly to avoid the input method and keyboard
1260 ;; coding system translating it.
1261 (if (and (integerp key)
ed5c183b 1262 (>= key ?\ ) (/= key 127) (< key 256))
a5cc922e
KH
1263 (progn
1264 (isearch-process-search-char key)
1265 (setq keylist (cdr keylist)))
1266 ;; As the remaining keys in KEYLIST can't be handled
1267 ;; here, we must reread them.
1268 (apply 'isearch-unread keylist)
1269 (setq keylist nil)))))
24b5caec 1270 (
c6431f12
KH
1271 ;; Handle an undefined shifted control character
1272 ;; by downshifting it if that makes it defined.
1273 ;; (As read-key-sequence would normally do,
1274 ;; if we didn't have a default definition.)
1275 (let ((mods (event-modifiers main-event)))
1276 (and (integerp main-event)
1277 (memq 'shift mods)
1278 (memq 'control mods)
1279 (lookup-key isearch-mode-map
1280 (let ((copy (copy-sequence key)))
1281 (aset copy 0
1282 (- main-event (- ?\C-\S-a ?\C-a)))
1283 copy)
1284 nil)))
1285 (setcar keylist (- main-event (- ?\C-\S-a ?\C-a)))
d94eb6eb 1286 (cancel-kbd-macro-events)
c6431f12
KH
1287 (apply 'isearch-unread keylist))
1288 ((eq search-exit-option 'edit)
1289 (apply 'isearch-unread keylist)
1290 (isearch-edit-string))
1291 (search-exit-option
1292 (let (window)
d94eb6eb 1293 (cancel-kbd-macro-events)
c6431f12 1294 (apply 'isearch-unread keylist)
3fb01f36
GM
1295
1296 ;; Properly handle scroll-bar and mode-line clicks for
1297 ;; which a dummy prefix event was generated as (aref key
1298 ;; 0). Note that we don't have to modify the event
1299 ;; anymore in 21 because read_key_sequence no longer modifies
1300 ;; events to produce fake prefix keys.
1301 (when (and (> (length key) 1)
1302 (symbolp (aref key 0))
1303 (listp (aref key 1))
191f025a 1304 (not (numberp (posn-point
3fb01f36 1305 (event-start (aref key 1))))))
17635d50
GM
1306 (pop unread-command-events)
1307 (setq main-event (car unread-command-events)))
3fb01f36 1308
346f18dc
GM
1309 ;; If we got a mouse click event, that event contains the
1310 ;; window clicked on. maybe it was read with the buffer
c6431f12
KH
1311 ;; it was clicked on. If so, that buffer, not the current one,
1312 ;; is in isearch mode. So end the search in that buffer.
346f18dc
GM
1313
1314 ;; ??? I have no idea what this if checks for, but it's
1315 ;; obviously wrong for the case that a down-mouse event
1316 ;; on another window invokes this function. The event
1317 ;; will contain the window clicked on and that window's
1318 ;; buffer is certainaly not always in Isearch mode.
1319 ;;
1320 ;; Leave the code in, but check for current buffer not
1321 ;; being in Isearch mode for now, until someone tells
1322 ;; what it's really supposed to do.
1323 ;;
1324 ;; --gerd 2001-08-10.
1325
1326 (if (and (not isearch-mode)
1327 (listp main-event)
c6431f12 1328 (setq window (posn-window (event-start main-event)))
4fd017e7
RS
1329 (windowp window)
1330 (or (> (minibuffer-depth) 0)
1331 (not (window-minibuffer-p window))))
c6431f12
KH
1332 (save-excursion
1333 (set-buffer (window-buffer window))
0352b205
RS
1334 (isearch-done)
1335 (isearch-clean-overlays))
1336 (isearch-done)
1337 (isearch-clean-overlays))))
c6431f12
KH
1338 (t;; otherwise nil
1339 (isearch-process-search-string key key)))))
8e1cae6d 1340
8e1cae6d
JB
1341(defun isearch-quote-char ()
1342 "Quote special characters for incremental search."
1343 (interactive)
8bc15fa8 1344 (let ((char (read-quoted-char (isearch-message t))))
3c75023f 1345 ;; Assume character codes 0200 - 0377 stand for characters in some
c20d35d5
KH
1346 ;; single-byte character set, and convert them to Emacs
1347 ;; characters.
8bc15fa8 1348 (and enable-multibyte-characters
3c75023f 1349 (>= char ?\200)
8bc15fa8 1350 (<= char ?\377)
c20d35d5 1351 (setq char (unibyte-char-to-multibyte char)))
8bc15fa8 1352 (isearch-process-search-char char)))
8e1cae6d 1353
8e1cae6d
JB
1354(defun isearch-return-char ()
1355 "Convert return into newline for incremental search.
1356Obsolete."
1357 (interactive)
1358 (isearch-process-search-char ?\n))
1359
8e1cae6d 1360(defun isearch-printing-char ()
b68c164d 1361 "Add this ordinary printing character to the search string and search."
8e1cae6d 1362 (interactive)
117132a6 1363 (let ((char last-command-char))
45b94eb2
KH
1364 (if (= char ?\S-\ )
1365 (setq char ?\ ))
af56433d
RS
1366 (if (and enable-multibyte-characters
1367 (>= char ?\200)
1368 (<= char ?\377))
3c487103
KH
1369 (if (keyboard-coding-system)
1370 (isearch-process-search-multibyte-characters char)
1371 (isearch-process-search-char (unibyte-char-to-multibyte char)))
af56433d
RS
1372 (if current-input-method
1373 (isearch-process-search-multibyte-characters char)
1374 (isearch-process-search-char char)))))
8e1cae6d
JB
1375
1376(defun isearch-whitespace-chars ()
08200510 1377 "Match all whitespace chars, if in regexp mode.
fad241d3 1378If you want to search for just a space, type \\<isearch-mode-map>\\[isearch-quote-char] SPC."
8e1cae6d 1379 (interactive)
08200510 1380 (if isearch-regexp
9da6682f
RS
1381 (if (and search-whitespace-regexp (not isearch-within-brackets)
1382 (not isearch-invalid-regexp))
08200510
RS
1383 (isearch-process-search-string search-whitespace-regexp " ")
1384 (isearch-printing-char))
1385 (progn
eb8c3be9 1386 ;; This way of doing word search doesn't correctly extend current search.
08200510
RS
1387 ;; (setq isearch-word t)
1388 ;; (setq isearch-adjusted t)
1389 ;; (goto-char isearch-barrier)
1390 (isearch-printing-char))))
8e1cae6d
JB
1391
1392(defun isearch-process-search-char (char)
1393 ;; Append the char to the search string, update the message and re-search.
191f025a
SM
1394 (isearch-process-search-string
1395 (char-to-string char)
8f3c1d76 1396 (if (>= char ?\200)
01a6ef79
RS
1397 (char-to-string char)
1398 (isearch-text-char-description char))))
8e1cae6d
JB
1399
1400(defun isearch-process-search-string (string message)
1401 (setq isearch-string (concat isearch-string string)
1402 isearch-message (concat isearch-message message))
1403 (isearch-search-and-update))
1404
1405\f
8e1cae6d
JB
1406;; Search Ring
1407
08200510
RS
1408(defun isearch-ring-adjust1 (advance)
1409 ;; Helper for isearch-ring-adjust
1410 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
8e1cae6d
JB
1411 (length (length ring))
1412 (yank-pointer-name (if isearch-regexp
08200510 1413 'regexp-search-ring-yank-pointer
8e1cae6d
JB
1414 'search-ring-yank-pointer))
1415 (yank-pointer (eval yank-pointer-name)))
1416 (if (zerop length)
1417 ()
1418 (set yank-pointer-name
1419 (setq yank-pointer
ffbc30b2
PE
1420 (mod (+ (or yank-pointer 0)
1421 (if advance -1 1))
1422 length)))
a5dcf63f 1423 (setq isearch-string (nth yank-pointer ring)
08200510
RS
1424 isearch-message (mapconcat 'isearch-text-char-description
1425 isearch-string "")))))
1426
1427(defun isearch-ring-adjust (advance)
1428 ;; Helper for isearch-ring-advance and isearch-ring-retreat
08200510 1429 (isearch-ring-adjust1 advance)
08200510
RS
1430 (if search-ring-update
1431 (progn
1432 (isearch-search)
1433 (isearch-update))
1434 (isearch-edit-string)
2ff20b7e
RS
1435 )
1436 (isearch-push-state))
8e1cae6d
JB
1437
1438(defun isearch-ring-advance ()
1439 "Advance to the next search string in the ring."
08200510 1440 ;; This could be more general to handle a prefix arg, but who would use it.
8e1cae6d
JB
1441 (interactive)
1442 (isearch-ring-adjust 'advance))
1443
1444(defun isearch-ring-retreat ()
1445 "Retreat to the previous search string in the ring."
1446 (interactive)
1447 (isearch-ring-adjust nil))
1448
a5dcf63f 1449(defun isearch-ring-advance-edit (n)
117132a6
DL
1450 "Insert the next element of the search history into the minibuffer.
1451With prefix arg N, insert the Nth element."
a5dcf63f
RS
1452 (interactive "p")
1453 (let* ((yank-pointer-name (if isearch-regexp
1454 'regexp-search-ring-yank-pointer
1455 'search-ring-yank-pointer))
1456 (yank-pointer (eval yank-pointer-name))
1457 (ring (if isearch-regexp regexp-search-ring search-ring))
1458 (length (length ring)))
1459 (if (zerop length)
1460 ()
1461 (set yank-pointer-name
1462 (setq yank-pointer
ffbc30b2
PE
1463 (mod (- (or yank-pointer 0) n)
1464 length)))
a5dcf63f 1465
b7b66466 1466 (delete-field)
35a4d143 1467 (insert (nth yank-pointer ring))
49c13105 1468 (goto-char (point-max)))))
a5dcf63f
RS
1469
1470(defun isearch-ring-retreat-edit (n)
117132a6
DL
1471 "Insert the previous element of the search history into the minibuffer.
1472With prefix arg N, insert the Nth element."
a5dcf63f
RS
1473 (interactive "p")
1474 (isearch-ring-advance-edit (- n)))
1475
1476;;(defun isearch-ring-adjust-edit (advance)
1477;; "Use the next or previous search string in the ring while in minibuffer."
1478;; (isearch-ring-adjust1 advance)
1479;; (erase-buffer)
1480;; (insert isearch-string))
1481
1482;;(defun isearch-ring-advance-edit ()
1483;; (interactive)
1484;; (isearch-ring-adjust-edit 'advance))
1485
1486;;(defun isearch-ring-retreat-edit ()
1487;; "Retreat to the previous search string in the ring while in the minibuffer."
1488;; (interactive)
1489;; (isearch-ring-adjust-edit nil))
08200510
RS
1490
1491
1492(defun isearch-complete1 ()
1493 ;; Helper for isearch-complete and isearch-complete-edit
1494 ;; Return t if completion OK, nil if no completion exists.
1495 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
1496 (alist (mapcar (function (lambda (string) (list string))) ring))
1497 (completion-ignore-case case-fold-search)
1498 (completion (try-completion isearch-string alist)))
1499 (cond
1500 ((eq completion t)
1501 ;; isearch-string stays the same
1502 t)
1503 ((or completion ; not nil, must be a string
b7852303 1504 (= 0 (length isearch-string))) ; shouldn't have to say this
08200510 1505 (if (equal completion isearch-string) ;; no extension?
36bcac3f
RS
1506 (progn
1507 (if completion-auto-help
1508 (with-output-to-temp-buffer "*Isearch completions*"
1509 (display-completion-list
1510 (all-completions isearch-string alist))))
1511 t)
1512 (and completion
1513 (setq isearch-string completion))))
08200510
RS
1514 (t
1515 (message "No completion") ; waits a second if in minibuffer
1516 nil))))
1517
1518(defun isearch-complete ()
1519 "Complete the search string from the strings on the search ring.
1520The completed string is then editable in the minibuffer.
1521If there is no completion possible, say so and continue searching."
1522 (interactive)
1523 (if (isearch-complete1)
1524 (isearch-edit-string)
1525 ;; else
1526 (sit-for 1)
1527 (isearch-update)))
8e1cae6d 1528
08200510
RS
1529(defun isearch-complete-edit ()
1530 "Same as `isearch-complete' except in the minibuffer."
1531 (interactive)
1532 (setq isearch-string (buffer-string))
1533 (if (isearch-complete1)
8e1cae6d 1534 (progn
b7b66466 1535 (delete-field)
08200510 1536 (insert isearch-string))))
8e1cae6d
JB
1537
1538\f
8e1cae6d 1539;; The search status stack (and isearch window-local variables, not used).
08200510 1540;; Need a structure for this.
8e1cae6d
JB
1541
1542(defun isearch-top-state ()
8e1cae6d
JB
1543 (let ((cmd (car isearch-cmds)))
1544 (setq isearch-string (car cmd)
1545 isearch-message (car (cdr cmd))
1546 isearch-success (nth 3 cmd)
1547 isearch-forward (nth 4 cmd)
1548 isearch-other-end (nth 5 cmd)
08200510
RS
1549 isearch-word (nth 6 cmd)
1550 isearch-invalid-regexp (nth 7 cmd)
1551 isearch-wrapped (nth 8 cmd)
c5f6b356 1552 isearch-barrier (nth 9 cmd)
f551b97d
RS
1553 isearch-within-brackets (nth 10 cmd)
1554 isearch-case-fold-search (nth 11 cmd))
8e1cae6d
JB
1555 (goto-char (car (cdr (cdr cmd))))))
1556
1557(defun isearch-pop-state ()
8e1cae6d 1558 (setq isearch-cmds (cdr isearch-cmds))
1f4139d5 1559 (isearch-top-state))
8e1cae6d
JB
1560
1561(defun isearch-push-state ()
1562 (setq isearch-cmds
1563 (cons (list isearch-string isearch-message (point)
1564 isearch-success isearch-forward isearch-other-end
08200510 1565 isearch-word
c5f6b356 1566 isearch-invalid-regexp isearch-wrapped isearch-barrier
f551b97d 1567 isearch-within-brackets isearch-case-fold-search)
8e1cae6d
JB
1568 isearch-cmds)))
1569
8e1cae6d 1570\f
8e1cae6d
JB
1571;; Message string
1572
1573(defun isearch-message (&optional c-q-hack ellipsis)
1574 ;; Generate and print the message string.
1575 (let ((cursor-in-echo-area ellipsis)
1576 (m (concat
08200510 1577 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
8e1cae6d
JB
1578 isearch-message
1579 (isearch-message-suffix c-q-hack ellipsis)
1580 )))
a56687f1
KH
1581 (if c-q-hack
1582 m
1583 (let ((message-log-max nil))
1584 (message "%s" m)))))
8e1cae6d 1585
08200510 1586(defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
8e1cae6d
JB
1587 ;; If about to search, and previous search regexp was invalid,
1588 ;; check that it still is. If it is valid now,
1589 ;; let the message we display while searching say that it is valid.
1590 (and isearch-invalid-regexp ellipsis
1591 (condition-case ()
1592 (progn (re-search-forward isearch-string (point) t)
8eb40e74
KH
1593 (setq isearch-invalid-regexp nil
1594 isearch-within-brackets nil))
8e1cae6d
JB
1595 (error nil)))
1596 ;; If currently failing, display no ellipsis.
1597 (or isearch-success (setq ellipsis nil))
1598 (let ((m (concat (if isearch-success "" "failing ")
7badea30
RS
1599 (if (and isearch-wrapped
1600 (if isearch-forward
1601 (> (point) isearch-opoint)
1602 (< (point) isearch-opoint)))
1603 "over")
8e1cae6d 1604 (if isearch-wrapped "wrapped ")
08200510 1605 (if isearch-word "word " "")
8e1cae6d 1606 (if isearch-regexp "regexp " "")
08200510 1607 (if nonincremental "search" "I-search")
f46d5091 1608 (if isearch-forward "" " backward")
5b56d4e4
KH
1609 (if current-input-method
1610 (concat " [" current-input-method-title "]: ")
f46d5091 1611 ": ")
8e1cae6d 1612 )))
360e0dd5
RS
1613 (propertize (concat (upcase (substring m 0 1)) (substring m 1))
1614 'face 'minibuffer-prompt)))
8e1cae6d
JB
1615
1616(defun isearch-message-suffix (&optional c-q-hack ellipsis)
1617 (concat (if c-q-hack "^Q" "")
1618 (if isearch-invalid-regexp
1619 (concat " [" isearch-invalid-regexp "]")
1620 "")))
1621
1622\f
191f025a
SM
1623;; Searching
1624
1625(defvar isearch-search-fun-function nil "Override `isearch-function-fun'.")
1626
1627(defun isearch-search-fun ()
1628 "Return the function to use for the search.
1629Can be changed via `isearch-search-fun-function' for special needs."
1630 (if isearch-search-fun-function
1631 (funcall isearch-search-fun-function)
1632 (cond
1633 (isearch-word
1634 (if isearch-forward 'word-search-forward 'word-search-backward))
1635 (isearch-regexp
1636 (if isearch-forward 're-search-forward 're-search-backward))
1637 (t
1638 (if isearch-forward 'search-forward 'search-backward)))))
8e1cae6d
JB
1639
1640(defun isearch-search ()
1641 ;; Do the search with the current search string.
1642 (isearch-message nil t)
4453091d 1643 (if (and (eq isearch-case-fold-search t) search-upper-case)
b78559b0
RS
1644 (setq isearch-case-fold-search
1645 (isearch-no-upper-case-p isearch-string isearch-regexp)))
8e1cae6d 1646 (condition-case lossage
79c7a4fa
RS
1647 (let ((inhibit-point-motion-hooks search-invisible)
1648 (inhibit-quit nil)
86bfaffe
RS
1649 (case-fold-search isearch-case-fold-search)
1650 (retry t))
8e1cae6d 1651 (if isearch-regexp (setq isearch-invalid-regexp nil))
c5f6b356 1652 (setq isearch-within-brackets nil)
86bfaffe
RS
1653 (while retry
1654 (setq isearch-success
1655 (funcall
191f025a 1656 (isearch-search-fun)
86bfaffe
RS
1657 isearch-string nil t))
1658 ;; Clear RETRY unless we matched some invisible text
1659 ;; and we aren't supposed to do that.
0352b205 1660 (if (or (eq search-invisible t)
86bfaffe
RS
1661 (not isearch-success)
1662 (bobp) (eobp)
1663 (= (match-beginning 0) (match-end 0))
1664 (not (isearch-range-invisible
1665 (match-beginning 0) (match-end 0))))
1666 (setq retry nil)))
99ae9e9f 1667 (setq isearch-just-started nil)
8e1cae6d
JB
1668 (if isearch-success
1669 (setq isearch-other-end
1670 (if isearch-forward (match-beginning 0) (match-end 0)))))
1671
d32696d4 1672 (quit (isearch-unread ?\C-g)
8e1cae6d
JB
1673 (setq isearch-success nil))
1674
191f025a 1675 (invalid-regexp
8e1cae6d 1676 (setq isearch-invalid-regexp (car (cdr lossage)))
c5f6b356
RS
1677 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
1678 isearch-invalid-regexp))
8e1cae6d
JB
1679 (if (string-match
1680 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
1681 isearch-invalid-regexp)
f1c03125
RS
1682 (setq isearch-invalid-regexp "incomplete input")))
1683 (error
c982ab21 1684 ;; stack overflow in regexp search.
c5348233 1685 (setq isearch-invalid-regexp (format "%s" lossage))))
8e1cae6d
JB
1686
1687 (if isearch-success
1688 nil
1689 ;; Ding if failed this time after succeeding last time.
1690 (and (nth 3 (car isearch-cmds))
1691 (ding))
1692 (goto-char (nth 2 (car isearch-cmds)))))
1693
0352b205 1694
191f025a 1695;; Called when opening an overlay, and we are still in isearch.
0352b205 1696(defun isearch-open-overlay-temporary (ov)
0352b205
RS
1697 (if (not (null (overlay-get ov 'isearch-open-invisible-temporary)))
1698 ;; Some modes would want to open the overlays temporary during
1699 ;; isearch in their own way, they should set the
1700 ;; `isearch-open-invisible-temporary' to a function doing this.
1701 (funcall (overlay-get ov 'isearch-open-invisible-temporary) ov nil)
1702 ;; Store the values for the `invisible' and `intangible'
1703 ;; properties, and then set them to nil. This way the text hidden
1704 ;; by this overlay becomes visible.
1705
380866a2 1706 ;; Do we really need to set the `intangible' property to t? Can we
0352b205
RS
1707 ;; have the point inside an overlay with an `intangible' property?
1708 ;; In 19.34 this does not exist so I cannot test it.
1709 (overlay-put ov 'isearch-invisible (overlay-get ov 'invisible))
1710 (overlay-put ov 'isearch-intangible (overlay-get ov 'intangible))
1711 (overlay-put ov 'invisible nil)
1712 (overlay-put ov 'intangible nil)))
1713
1714
191f025a
SM
1715;; This is called at the end of isearch. It will open the overlays
1716;; that contain the latest match. Obviously in case of a C-g the
1717;; point returns to the original location which surely is not contain
1718;; in any of these overlays, se we are safe in this case too.
0352b205 1719(defun isearch-open-necessary-overlays (ov)
191f025a 1720 (let ((inside-overlay (and (> (point) (overlay-start ov))
0352b205
RS
1721 (< (point) (overlay-end ov))))
1722 ;; If this exists it means that the overlay was opened using
1723 ;; this function, not by us tweaking the overlay properties.
1724 (fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
1725 (when (or inside-overlay (not fct-temp))
1726 ;; restore the values for the `invisible' and `intangible'
1727 ;; properties
1728 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
1729 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
1730 (overlay-put ov 'isearch-invisible nil)
1731 (overlay-put ov 'isearch-intangible nil))
1732 (if inside-overlay
1733 (funcall (overlay-get ov 'isearch-open-invisible) ov)
1734 (if fct-temp
1735 (funcall fct-temp ov t)))))
1736
191f025a
SM
1737;; This is called when exiting isearch. It closes the temporary
1738;; opened overlays, except the ones that contain the latest match.
0352b205
RS
1739(defun isearch-clean-overlays ()
1740 (when isearch-opened-overlays
02b2f510 1741 (mapc 'isearch-open-necessary-overlays isearch-opened-overlays)
0352b205
RS
1742 (setq isearch-opened-overlays nil)))
1743
fc0eccfc
GM
1744
1745(defun isearch-intersects-p (start0 end0 start1 end1)
1746 "Return t if regions START0..END0 and START1..END1 intersect."
eaa493df
GM
1747 (or (and (>= start0 start1) (< start0 end1))
1748 (and (> end0 start1) (<= end0 end1))
1749 (and (>= start1 start0) (< start1 end0))
1750 (and (> end1 start0) (<= end1 end0))))
fc0eccfc
GM
1751
1752
191f025a
SM
1753;; Verify if the current match is outside of each element of
1754;; `isearch-opened-overlays', if so close that overlay.
fc0eccfc
GM
1755
1756(defun isearch-close-unnecessary-overlays (begin end)
1757 (let ((overlays isearch-opened-overlays))
0352b205 1758 (setq isearch-opened-overlays nil)
fc0eccfc
GM
1759 (dolist (ov overlays)
1760 (if (isearch-intersects-p begin end (overlay-start ov) (overlay-end ov))
1761 (push ov isearch-opened-overlays)
1762 (let ((fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
1763 (if fct-temp
1764 ;; If this exists it means that the overlay was opened
1765 ;; using this function, not by us tweaking the overlay
1766 ;; properties.
1767 (funcall fct-temp ov t)
1768 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
1769 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
1770 (overlay-put ov 'isearch-invisible nil)
1771 (overlay-put ov 'isearch-intangible nil)))))))
1772
0352b205 1773
86bfaffe 1774(defun isearch-range-invisible (beg end)
79c7a4fa 1775 "Return t if all the text from BEG to END is invisible."
cd59ea72
SM
1776 (when (/= beg end)
1777 ;; Check that invisibility runs up to END.
1778 (save-excursion
1779 (goto-char beg)
1780 (let (;; can-be-opened keeps track if we can open some overlays.
1781 (can-be-opened (eq search-invisible 'open))
1782 ;; the list of overlays that could be opened
1783 (crt-overlays nil))
1784 (when (and can-be-opened isearch-hide-immediately)
1785 (isearch-close-unnecessary-overlays beg end))
1786 ;; If the following character is currently invisible,
1787 ;; skip all characters with that same `invisible' property value.
1788 ;; Do that over and over.
1789 (while (and (< (point) end)
1790 (let ((prop
1791 (get-char-property (point) 'invisible)))
1792 (if (eq buffer-invisibility-spec t)
1793 prop
1794 (or (memq prop buffer-invisibility-spec)
1795 (assq prop buffer-invisibility-spec)))))
1796 (if (get-text-property (point) 'invisible)
1797 (progn
1798 (goto-char (next-single-property-change (point) 'invisible
1799 nil end))
1800 ;; if text is hidden by an `invisible' text property
1801 ;; we cannot open it at all.
1802 (setq can-be-opened nil))
1803 (when can-be-opened
1804 (let ((overlays (overlays-at (point)))
1805 ov-list
1806 o
1807 invis-prop)
1808 (while overlays
1809 (setq o (car overlays)
1810 invis-prop (overlay-get o 'invisible))
1811 (if (if (eq buffer-invisibility-spec t)
1812 invis-prop
1813 (or (memq invis-prop buffer-invisibility-spec)
1814 (assq invis-prop buffer-invisibility-spec)))
1815 (if (overlay-get o 'isearch-open-invisible)
1816 (setq ov-list (cons o ov-list))
1817 ;; We found one overlay that cannot be
1818 ;; opened, that means the whole chunk
1819 ;; cannot be opened.
1820 (setq can-be-opened nil)))
1821 (setq overlays (cdr overlays)))
1822 (if can-be-opened
1823 ;; It makes sense to append to the open
1824 ;; overlays list only if we know that this is
1825 ;; t.
1826 (setq crt-overlays (append ov-list crt-overlays)))))
1827 (goto-char (next-overlay-change (point)))))
1828 ;; See if invisibility reaches up thru END.
1829 (if (>= (point) end)
1830 (if (and can-be-opened (consp crt-overlays))
1831 (progn
1832 (setq isearch-opened-overlays
1833 (append isearch-opened-overlays crt-overlays))
1834 (mapc 'isearch-open-overlay-temporary crt-overlays)
1835 nil)
1836 (setq isearch-hidden t)))))))
08200510
RS
1837
1838\f
191f025a 1839;; Highlighting
08200510 1840
b78559b0 1841(defvar isearch-overlay nil)
08200510 1842
b78559b0 1843(defun isearch-highlight (beg end)
8005142f 1844 (unless (null search-highlight)
4fb2ad98
MB
1845 (cond (isearch-overlay
1846 ;; Overlay already exists, just move it.
4fb2ad98
MB
1847 (move-overlay isearch-overlay beg end (current-buffer)))
1848
1849 (t
1850 ;; Overlay doesn't exist, create it.
1851 (setq isearch-overlay (make-overlay beg end))
c982ab21
GM
1852 (overlay-put isearch-overlay 'face isearch)
1853 (overlay-put isearch-overlay 'priority 1) ;higher than lazy overlays
1854 ))))
b78559b0
RS
1855
1856(defun isearch-dehighlight (totally)
4fb2ad98 1857 (when isearch-overlay
4fb2ad98
MB
1858 (delete-overlay isearch-overlay)))
1859
08200510 1860
191f025a 1861;; General utilities
08200510 1862
08200510 1863
b78559b0
RS
1864(defun isearch-no-upper-case-p (string regexp-flag)
1865 "Return t if there are no upper case chars in STRING.
b7852303 1866If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
b78559b0 1867since they have special meaning in a regexp."
59057198
RS
1868 (let (quote-flag (i 0) (len (length string)) found)
1869 (while (and (not found) (< i len))
1870 (let ((char (aref string i)))
1871 (if (and regexp-flag (eq char ?\\))
1872 (setq quote-flag (not quote-flag))
1873 (if (and (not quote-flag) (not (eq char (downcase char))))
f4be3f89
RS
1874 (setq found t))
1875 (setq quote-flag nil)))
59057198
RS
1876 (setq i (1+ i)))
1877 (not found)))
08200510 1878
b78559b0 1879;; Portability functions to support various Emacs versions.
8e1cae6d 1880
08200510 1881(defun isearch-text-char-description (c)
14373677
SM
1882 (cond
1883 ((< c ?\ ) (format "^%c" (+ c 64)))
1884 ((= c ?\^?) "^?")
1885 (t (char-to-string c))))
08200510 1886
bd1bd125 1887;; General function to unread characters or events.
99ae9e9f 1888;; Also insert them in a keyboard macro being defined.
8f90f594 1889(defun isearch-unread (&rest char-or-events)
02b2f510 1890 (mapc 'store-kbd-macro-event char-or-events)
bd1bd125
RS
1891 (setq unread-command-events
1892 (append char-or-events unread-command-events)))
08200510 1893
44336afb 1894\f
191f025a
SM
1895;; isearch-lazy-highlight feature
1896;; by Bob Glickstein <http://www.zanshin.com/~bobg/>
1897
1898;; When active, *every* match for the current search string is
1899;; highlighted: the current one using the normal isearch match color
1900;; and all the others using `isearch-lazy-highlight-face'. The extra
1901;; highlighting makes it easier to anticipate where the cursor will
1902;; land each time you press C-s or C-r to repeat a pending search.
1903;; Highlighting of these additional matches happens in a deferred
1904;; fashion using "idle timers," so the cycles needed do not rob
1905;; isearch of its usual snappy response.
1906
1907;; IMPLEMENTATION NOTE: This depends on some isearch internals.
1908;; Specifically:
1909;; - `isearch-update' is expected to be called (at least) every time
1910;; the search string or window-start changes;
1911;; - `isearch-string' is expected to contain the current search
1912;; string as entered by the user;
1913;; - the type of the current search is expected to be given by
1914;; `isearch-word' and `isearch-regexp';
1915;; - the direction of the current search is expected to be given by
1916;; `isearch-forward';
1917;; - the variable `isearch-invalid-regexp' is expected to be true
1918;; iff `isearch-string' is an invalid regexp.
44336afb 1919
44336afb
GM
1920(defgroup isearch-lazy-highlight nil
1921 "Lazy highlighting feature for incremental search."
1922 :prefix "isearch-lazy-highlight-"
39f2174e 1923 :version "21.1"
44336afb
GM
1924 :group 'isearch)
1925
1926(defcustom isearch-lazy-highlight t
1927 "*Controls the lazy-highlighting during incremental searches.
1928When non-nil, all text in the buffer matching the current search
1929string is highlighted lazily (see `isearch-lazy-highlight-initial-delay'
1930and `isearch-lazy-highlight-interval')."
1931 :type 'boolean
1932 :group 'isearch-lazy-highlight)
1933
1934(defcustom isearch-lazy-highlight-cleanup t
1935 "*Controls whether to remove extra highlighting after a search.
1936If this is nil, extra highlighting can be \"manually\" removed with
1937\\[isearch-lazy-highlight-cleanup]."
1938 :type 'boolean
1939 :group 'isearch-lazy-highlight)
1940
871e0439 1941(defcustom isearch-lazy-highlight-initial-delay 0.25
44336afb
GM
1942 "*Seconds to wait before beginning to lazily highlight all matches."
1943 :type 'number
1944 :group 'isearch-lazy-highlight)
1945
b8fbd474 1946(defcustom isearch-lazy-highlight-interval 0 ; 0.0625
44336afb
GM
1947 "*Seconds between lazily highlighting successive matches."
1948 :type 'number
1949 :group 'isearch-lazy-highlight)
1950
c982ab21
GM
1951(defcustom isearch-lazy-highlight-max-at-a-time 20
1952 "*Maximum matches to highlight at a time (for `isearch-lazy-highlight').
1953Larger values may reduce isearch's responsiveness to user input;
1954smaller values make matches highlight slowly.
1955A value of nil means highlight all matches."
68ebbb95
GM
1956 :type '(choice (const :tag "All" nil)
1957 (integer :tag "Some"))
1958 :group 'isearch-lazy-highlight)
1959
18ca20aa
GM
1960(defgroup isearch-faces nil
1961 "Lazy highlighting feature for incremental search."
1962 :version "21.1"
1963 :group 'isearch)
1964
1965(defface isearch
29910493
EZ
1966 '((((type tty pc) (class color))
1967 (:background "magenta4" :foreground "cyan1"))
1968 (((class color) (background light))
b4d7a2ec
RS
1969 ;; The background must not be too dark, for that means
1970 ;; the character is hard to see when the cursor is there.
5bcf0054 1971 (:background "magenta2" :foreground "lightskyblue1"))
29910493
EZ
1972 (((class color) (background dark))
1973 (:background "palevioletred2" :foreground "brown4"))
1974 (t (:inverse-video t)))
1975 "Face for highlighting Isearch matches."
18ca20aa
GM
1976 :group 'isearch-faces)
1977(defvar isearch 'isearch)
1978
1979(defface isearch-lazy-highlight-face
29910493
EZ
1980 '((((type tty pc) (class color))
1981 (:background "turquoise3"))
1982 (((class color) (background light))
1983 (:background "paleturquoise"))
1984 (((class color) (background dark))
1985 (:background "paleturquoise4"))
1986 (t (:underline t)))
1987 "Face for lazy highlighting of Isearch matches other than the current one."
18ca20aa
GM
1988 :group 'isearch-faces)
1989(defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face)
44336afb
GM
1990
1991(defvar isearch-lazy-highlight-overlays nil)
c982ab21 1992(defvar isearch-lazy-highlight-wrapped nil)
44336afb
GM
1993(defvar isearch-lazy-highlight-start nil)
1994(defvar isearch-lazy-highlight-end nil)
1995(defvar isearch-lazy-highlight-timer nil)
1996(defvar isearch-lazy-highlight-last-string nil)
c982ab21
GM
1997(defvar isearch-lazy-highlight-window nil)
1998(defvar isearch-lazy-highlight-window-start nil)
46daf6c7
GM
1999(defvar isearch-lazy-highlight-case-fold-search nil)
2000(defvar isearch-lazy-highlight-regexp nil)
44336afb 2001
c982ab21
GM
2002(defun isearch-lazy-highlight-cleanup (&optional force)
2003 "Stop lazy highlighting and remove extra highlighting from current buffer.
2004FORCE non-nil means do it whether or not `isearch-lazy-highlight-cleanup'
2005is nil. This function is called when exiting an incremental search if
2006`isearch-lazy-highlight-cleanup' is non-nil."
44336afb 2007 (interactive '(t))
c982ab21
GM
2008 (if (or force isearch-lazy-highlight-cleanup)
2009 (while isearch-lazy-highlight-overlays
2010 (delete-overlay (car isearch-lazy-highlight-overlays))
2011 (setq isearch-lazy-highlight-overlays
2012 (cdr isearch-lazy-highlight-overlays))))
2013 (when isearch-lazy-highlight-timer
2014 (cancel-timer isearch-lazy-highlight-timer)
2015 (setq isearch-lazy-highlight-timer nil)))
44336afb
GM
2016
2017(defun isearch-lazy-highlight-new-loop ()
c982ab21 2018 "Cleanup any previous `isearch-lazy-highlight' loop and begin a new one.
44336afb 2019This happens when `isearch-update' is invoked (which can cause the
c982ab21 2020search string to change or the window to scroll)."
67ecad4e 2021 (when (and isearch-lazy-highlight
4c01d4bd 2022 (null executing-kbd-macro)
c982ab21
GM
2023 (sit-for 0) ;make sure (window-start) is credible
2024 (or (not (equal isearch-string
2025 isearch-lazy-highlight-last-string))
2026 (not (eq (selected-window)
2027 isearch-lazy-highlight-window))
46daf6c7
GM
2028 (not (eq isearch-lazy-highlight-case-fold-search
2029 isearch-case-fold-search))
2030 (not (eq isearch-lazy-highlight-regexp
2031 isearch-regexp))
c982ab21
GM
2032 (not (= (window-start)
2033 isearch-lazy-highlight-window-start))))
2034 ;; something important did indeed change
2035 (isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays
2036 (when (not isearch-invalid-regexp)
2037 (setq isearch-lazy-highlight-window (selected-window)
2038 isearch-lazy-highlight-window-start (window-start)
2039 isearch-lazy-highlight-start (point)
2040 isearch-lazy-highlight-end (point)
2041 isearch-lazy-highlight-last-string isearch-string
46daf6c7
GM
2042 isearch-lazy-highlight-case-fold-search isearch-case-fold-search
2043 isearch-lazy-highlight-regexp isearch-regexp
c982ab21
GM
2044 isearch-lazy-highlight-wrapped nil)
2045 (setq isearch-lazy-highlight-timer
2046 (run-with-idle-timer isearch-lazy-highlight-initial-delay nil
2047 'isearch-lazy-highlight-update)))))
2048
2049(defun isearch-lazy-highlight-search ()
2050 "Search ahead for the next or previous match, for lazy highlighting.
2051Attempt to do the search exactly the way the pending isearch would."
191f025a
SM
2052 (let ((case-fold-search isearch-case-fold-search))
2053 (funcall (isearch-search-fun)
c982ab21
GM
2054 isearch-string
2055 (if isearch-forward
2056 (if isearch-lazy-highlight-wrapped
2057 isearch-lazy-highlight-start
2058 (window-end))
2059 (if isearch-lazy-highlight-wrapped
2060 isearch-lazy-highlight-end
2061 (window-start)))
2062 t)))
44336afb
GM
2063
2064(defun isearch-lazy-highlight-update ()
c982ab21
GM
2065 "Update highlighting of other matches for current search."
2066 (let ((max isearch-lazy-highlight-max-at-a-time)
2067 (looping t)
2068 nomore)
7742ee19
RS
2069 (save-excursion
2070 (save-match-data
c982ab21
GM
2071 (goto-char (if isearch-forward
2072 isearch-lazy-highlight-end
2073 isearch-lazy-highlight-start))
2074 (while looping
2075 (let ((found (isearch-lazy-highlight-search)))
2076 (when max
2077 (setq max (1- max))
2078 (if (<= max 0)
2079 (setq looping nil)))
2080 (if found
2081 (let ((mb (match-beginning 0))
2082 (me (match-end 0)))
2083 (if (= mb me) ;zero-length match
2084 (forward-char 1)
2085
2086 ;; non-zero-length match
2087 (let ((ov (make-overlay mb me)))
2088 (overlay-put ov 'face isearch-lazy-highlight-face)
2089 (overlay-put ov 'priority 0) ;lower than main overlay
2090 (overlay-put ov 'window (selected-window))
2091 (push ov isearch-lazy-highlight-overlays)))
2092 (if isearch-forward
2093 (setq isearch-lazy-highlight-end (point))
2094 (setq isearch-lazy-highlight-start (point))))
2095
2096 ;; not found
2097 (if isearch-lazy-highlight-wrapped
2098 (setq looping nil
2099 nomore t)
2100 (setq isearch-lazy-highlight-wrapped t)
2101 (if isearch-forward
2102 (progn
2103 (setq isearch-lazy-highlight-end (window-start))
2104 (goto-char (window-start)))
2105 (setq isearch-lazy-highlight-start (window-end))
2106 (goto-char (window-end)))))))
2107 (unless nomore
2108 (setq isearch-lazy-highlight-timer
2109 (run-at-time isearch-lazy-highlight-interval nil
2110 'isearch-lazy-highlight-update)))))))
44336afb 2111
c40a4de1
GM
2112(defun isearch-resume (search regexp word forward message case-fold)
2113 "Resume an incremental search.
2114SEARCH is the string or regexp searched for.
2115REGEXP non-nil means the resumed search was a regexp search.
2116WORD non-nil means resume a word search.
2117FORWARD non-nil means resume a forward search.
2118MESSAGE is the echo-area message recorded for the search resumed.
2119CASE-FOLD non-nil means the search was case-insensitive."
2120 (isearch-mode forward regexp nil nil word)
2121 (setq isearch-string search
2122 isearch-message message
2123 isearch-case-fold-search case-fold)
2124 (isearch-search))
191f025a 2125
3b1e4dd1 2126;;; isearch.el ends here