Allow 'browse-url-emacs' to fetch URL in the selected window
[emacs.git] / lisp / isearch.el
blob84b121af9ef0efecc021f04a2ac63378becc117b
1 ;;; isearch.el --- incremental search minor mode -*- lexical-binding: t -*-
3 ;; Copyright (C) 1992-1997, 1999-2018 Free Software Foundation, Inc.
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: matching
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
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 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Instructions
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.
33 ;; The key bindings active within isearch-mode are defined below in
34 ;; `isearch-mode-map'. Also see minibuffer-local-isearch-map
35 ;; for bindings active during `isearch-edit-string'.
37 ;; isearch-mode should work even if you switch windows with the mouse,
38 ;; in which case isearch-mode is terminated automatically before the
39 ;; switch.
41 ;; The search ring and completion commands automatically put you in
42 ;; the minibuffer to edit the string. This gives you a chance to
43 ;; modify the search string before executing the search. There are
44 ;; three commands to terminate the editing: C-s and C-r exit the
45 ;; minibuffer and search forward and reverse respectively, while C-m
46 ;; exits and searches in the last search direction.
48 ;; Exiting immediately from isearch uses isearch-edit-string instead
49 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
50 ;; The name of this option should probably be changed if we decide to
51 ;; keep the behavior. No point in forcing nonincremental search until
52 ;; the last possible moment.
54 ;;; Code:
56 (eval-when-compile (require 'cl-lib))
58 ;; Some additional options and constants.
60 (defgroup isearch nil
61 "Incremental search minor mode."
62 :link '(emacs-commentary-link "isearch")
63 :link '(custom-manual "(emacs)Incremental Search")
64 :prefix "isearch-"
65 :prefix "search-"
66 :group 'matching)
69 (defcustom search-exit-option t
70 "Defines what control characters do in incremental search.
71 If t, random control and meta characters terminate the search
72 and are then executed normally.
73 If `edit', edit the search string instead of exiting.
74 If `move', extend the search string by motion commands
75 that have the `isearch-move' property on their symbols.
76 If `shift-move', extend the search string by motion commands
77 while holding down the shift key.
78 Both `move' and `shift-move' extend the search string by yanking text
79 that ends at the new position after moving point in the current buffer.
80 If `append', the characters which you type that are not interpreted by
81 the incremental search are simply appended to the search string.
82 If nil, run the command without exiting Isearch."
83 :type '(choice (const :tag "Terminate incremental search" t)
84 (const :tag "Edit the search string" edit)
85 (const :tag "Extend the search string by motion commands" move)
86 (const :tag "Extend the search string by shifted motion keys" shift-move)
87 (const :tag "Append control characters to the search string" append)
88 (const :tag "Don't terminate incremental search" nil))
89 :version "27.1")
91 (defcustom search-slow-window-lines 1
92 "Number of lines in slow search display windows.
93 These are the short windows used during incremental search on slow terminals.
94 Negative means put the slow search window at the top (normally it's at bottom)
95 and the value is minus the number of lines."
96 :type 'integer)
98 (defcustom search-slow-speed 1200
99 "Highest terminal speed at which to use \"slow\" style incremental search.
100 This is the style where a one-line window is created to show the line
101 that the search has reached."
102 :type 'integer)
104 (defcustom search-upper-case 'not-yanks
105 "If non-nil, upper case chars disable case fold searching.
106 That is, upper and lower case chars must match exactly.
107 This applies no matter where the chars come from, but does not
108 apply to chars in regexps that are prefixed with `\\'.
109 If this value is `not-yanks', text yanked into the search string
110 in Isearch mode is always downcased."
111 :type '(choice (const :tag "off" nil)
112 (const not-yanks)
113 (other :tag "on" t)))
115 (defcustom search-nonincremental-instead t
116 "If non-nil, do a nonincremental search instead of exiting immediately.
117 This affects the behavior of `isearch-exit' and any key bound to that
118 command: if this variable is nil, `isearch-exit' always exits the search;
119 if the value is non-nil, and the search string is empty, `isearch-exit'
120 starts a nonincremental search instead. (Actually, `isearch-edit-string'
121 is called to let you enter the search string, and RET terminates editing
122 and does a nonincremental search.)"
123 :type 'boolean)
125 (defcustom search-whitespace-regexp (purecopy "\\s-+")
126 "If non-nil, regular expression to match a sequence of whitespace chars.
127 When you enter a space or spaces in the incremental search, it
128 will match any sequence matched by this regexp. As an exception,
129 spaces are treated normally in regexp incremental search if they
130 occur in a regexp construct like [...] or *, + or ?.
132 If the value is a string, it applies to both ordinary and
133 regexp incremental search. If the value is nil, or
134 `isearch-lax-whitespace' is nil for ordinary incremental search, or
135 `isearch-regexp-lax-whitespace' is nil for regexp incremental search,
136 then each space you type matches literally, against one space.
138 You might want to use something like \"[ \\t\\r\\n]+\" instead.
139 In the Customization buffer, that is `[' followed by a space,
140 a tab, a carriage return (control-M), a newline, and `]+'."
141 :type '(choice (const :tag "Match Spaces Literally" nil)
142 regexp)
143 :version "24.3")
145 (defcustom search-invisible 'open
146 "If t incremental search/query-replace can match hidden text.
147 A nil value means don't match invisible text.
148 When the value is `open', if the text matched is made invisible by
149 an overlay having a non-nil `invisible' property, and that overlay
150 has a non-nil property `isearch-open-invisible', then incremental
151 search will show the hidden text. (This applies when using `outline.el'
152 and `hideshow.el'.)
154 To temporarily change the value for an active incremental search,
155 use \\<isearch-mode-map>\\[isearch-toggle-invisible].
157 See also the related option `isearch-hide-immediately'.
159 See also `reveal-mode' if you want overlays to automatically be opened
160 whenever point is in one of them."
161 :type '(choice (const :tag "Match hidden text" t)
162 (const :tag "Open overlays" open)
163 (const :tag "Don't match hidden text" nil)))
165 (defcustom isearch-hide-immediately t
166 "If non-nil, re-hide an invisible match right away.
167 This variable makes a difference when `search-invisible' is set to `open'.
168 If non-nil, invisible matches are re-hidden as soon as the match moves
169 off the invisible text surrounding the match.
170 If nil then do not re-hide opened invisible text when the match moves.
171 Whatever the value, all opened invisible text is hidden again after exiting
172 the search, with the exception of the last successful match, if any."
173 :type 'boolean)
175 (defcustom isearch-resume-in-command-history nil
176 "If non-nil, `isearch-resume' commands are added to the command history.
177 This allows you to resume earlier Isearch sessions through the
178 command history."
179 :type 'boolean)
181 (defvar isearch-mode-hook nil
182 "Function(s) to call after starting up an incremental search.")
184 (defvar isearch-update-post-hook nil
185 "Function(s) to call after isearch has found matches in the buffer.")
187 (defvar isearch-mode-end-hook nil
188 "Function(s) to call after terminating an incremental search.
189 When these functions are called, `isearch-mode-end-hook-quit'
190 is non-nil if the user quits the search.")
192 (defvar isearch-mode-end-hook-quit nil
193 "Non-nil while running `isearch-mode-end-hook' if the user quits the search.")
195 (defvar isearch-message-function nil
196 "Function to call to display the search prompt.
197 If nil, use function `isearch-message'.")
199 (defvar isearch-wrap-function nil
200 "Function to call to wrap the search when search is failed.
201 If nil, move point to the beginning of the buffer for a forward search,
202 or to the end of the buffer for a backward search.")
204 (defvar isearch-push-state-function nil
205 "Function to save a function restoring the mode-specific Isearch state
206 to the search status stack.")
208 (defvar isearch-filter-predicate #'isearch-filter-visible
209 "Predicate that filters the search hits that would normally be available.
210 Search hits that dissatisfy the predicate are skipped. The function
211 has two arguments: the positions of start and end of text matched by
212 the search. If this function returns nil, continue searching without
213 stopping at this match.
214 If you use `add-function' to modify this variable, you can use the
215 `isearch-message-prefix' advice property to specify the prefix string
216 displayed in the search message.")
218 ;; Search ring.
220 (defvar search-ring nil
221 "List of search string sequences.")
222 (defvar regexp-search-ring nil
223 "List of regular expression search string sequences.")
225 (defcustom search-ring-max 16
226 "Maximum length of search ring before oldest elements are thrown away."
227 :type 'integer)
228 (defcustom regexp-search-ring-max 16
229 "Maximum length of regexp search ring before oldest elements are thrown away."
230 :type 'integer)
232 (defvar search-ring-yank-pointer nil
233 "Index in `search-ring' of last string reused.
234 It is nil if none yet.")
235 (defvar regexp-search-ring-yank-pointer nil
236 "Index in `regexp-search-ring' of last string reused.
237 It is nil if none yet.")
239 (defcustom search-ring-update nil
240 "Non-nil if advancing or retreating in the search ring should cause search.
241 Default value, nil, means edit the string instead."
242 :type 'boolean)
244 (autoload 'char-fold-to-regexp "char-fold")
246 (defcustom search-default-mode nil
247 "Default mode to use when starting isearch.
248 Value is nil, t, or a function.
250 If nil, default to literal searches (note that `case-fold-search'
251 and `isearch-lax-whitespace' may still be applied).\\<isearch-mode-map>
252 If t, default to regexp searches (as if typing `\\[isearch-toggle-regexp]' during
253 isearch).
255 If a function, use that function as an `isearch-regexp-function'.
256 Example functions (and the keys to toggle them during isearch)
257 are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp'
258 \(`\\[isearch-toggle-symbol]'), and `char-fold-to-regexp' \(`\\[isearch-toggle-char-fold]')."
259 ;; :type is set below by `isearch-define-mode-toggle'.
260 :type '(choice (const :tag "Literal search" nil)
261 (const :tag "Regexp search" t)
262 (function :tag "Other"))
263 :version "25.1")
265 ;;; isearch highlight customization.
267 (defcustom search-highlight t
268 "Non-nil means incremental search highlights the current match."
269 :type 'boolean)
271 (defface isearch
272 '((((class color) (min-colors 88) (background light))
273 ;; The background must not be too dark, for that means
274 ;; the character is hard to see when the cursor is there.
275 (:background "magenta3" :foreground "lightskyblue1"))
276 (((class color) (min-colors 88) (background dark))
277 (:background "palevioletred2" :foreground "brown4"))
278 (((class color) (min-colors 16))
279 (:background "magenta4" :foreground "cyan1"))
280 (((class color) (min-colors 8))
281 (:background "magenta4" :foreground "cyan1"))
282 (t (:inverse-video t)))
283 "Face for highlighting Isearch matches."
284 :group 'isearch
285 :group 'basic-faces)
286 (defvar isearch-face 'isearch)
288 (defface isearch-fail
289 '((((class color) (min-colors 88) (background light))
290 (:background "RosyBrown1"))
291 (((class color) (min-colors 88) (background dark))
292 (:background "red4"))
293 (((class color) (min-colors 16))
294 (:background "red"))
295 (((class color) (min-colors 8))
296 (:background "red"))
297 (((class color grayscale))
298 :foreground "grey")
299 (t (:inverse-video t)))
300 "Face for highlighting failed part in Isearch echo-area message."
301 :version "23.1")
303 (defcustom isearch-lazy-highlight t
304 "Controls the lazy-highlighting during incremental search.
305 When non-nil, all text in the buffer matching the current search
306 string is highlighted lazily (see `lazy-highlight-initial-delay'
307 and `lazy-highlight-interval').
309 When multiple windows display the current buffer, the
310 highlighting is displayed only on the selected window, unless
311 this variable is set to the symbol `all-windows'."
312 :type '(choice boolean
313 (const :tag "On, and applied to all windows" all-windows))
314 :group 'lazy-highlight
315 :group 'isearch)
317 ;;; Lazy highlight customization.
319 (defgroup lazy-highlight nil
320 "Lazy highlighting feature for matching strings."
321 :prefix "lazy-highlight-"
322 :version "21.1"
323 :group 'isearch
324 :group 'matching)
326 (defcustom lazy-highlight-cleanup t
327 "Controls whether to remove extra highlighting after a search.
328 If this is nil, extra highlighting can be \"manually\" removed with
329 \\[lazy-highlight-cleanup]."
330 :type 'boolean
331 :group 'lazy-highlight)
333 (defcustom lazy-highlight-initial-delay 0.25
334 "Seconds to wait before beginning to lazily highlight all matches."
335 :type 'number
336 :group 'lazy-highlight)
338 (defcustom lazy-highlight-interval 0 ; 0.0625
339 "Seconds between lazily highlighting successive matches."
340 :type 'number
341 :group 'lazy-highlight)
343 (defcustom lazy-highlight-max-at-a-time nil ; 20 (bug#25751)
344 "Maximum matches to highlight at a time (for `lazy-highlight').
345 Larger values may reduce Isearch's responsiveness to user input;
346 smaller values make matches highlight slowly.
347 A value of nil means highlight all matches shown on the screen."
348 :type '(choice (const :tag "All" nil)
349 (integer :tag "Some"))
350 :group 'lazy-highlight)
352 (defface lazy-highlight
353 '((((class color) (min-colors 88) (background light))
354 (:background "paleturquoise"))
355 (((class color) (min-colors 88) (background dark))
356 (:background "paleturquoise4"))
357 (((class color) (min-colors 16))
358 (:background "turquoise3"))
359 (((class color) (min-colors 8))
360 (:background "turquoise3"))
361 (t (:underline t)))
362 "Face for lazy highlighting of matches other than the current one."
363 :group 'lazy-highlight
364 :group 'basic-faces)
367 ;; Define isearch help map.
369 (defvar isearch-help-map
370 (let ((map (make-sparse-keymap)))
371 (define-key map (char-to-string help-char) 'isearch-help-for-help)
372 (define-key map [help] 'isearch-help-for-help)
373 (define-key map [f1] 'isearch-help-for-help)
374 (define-key map "?" 'isearch-help-for-help)
375 (define-key map "b" 'isearch-describe-bindings)
376 (define-key map "k" 'isearch-describe-key)
377 (define-key map "m" 'isearch-describe-mode)
378 (define-key map "q" 'help-quit)
379 map)
380 "Keymap for characters following the Help key for Isearch mode.")
382 (eval-when-compile (require 'help-macro))
384 (make-help-screen isearch-help-for-help-internal
385 (purecopy "Type a help option: [bkm] or ?")
386 "You have typed %THIS-KEY%, the help character. Type a Help option:
387 \(Type \\<help-map>\\[help-quit] to exit the Help command.)
389 b Display all Isearch key bindings.
390 k KEYS Display full documentation of Isearch key sequence.
391 m Display documentation of Isearch mode.
393 You can't type here other help keys available in the global help map,
394 but outside of this help window when you type them in Isearch mode,
395 they exit Isearch mode before displaying global help."
396 isearch-help-map)
398 (defvar isearch--display-help-action '(nil (inhibit-same-window . t)))
400 (defun isearch-help-for-help ()
401 "Display Isearch help menu."
402 (interactive)
403 (let ((display-buffer-overriding-action isearch--display-help-action))
404 (isearch-help-for-help-internal))
405 (isearch-update))
407 (defun isearch-describe-bindings ()
408 "Show a list of all keys defined in Isearch mode, and their definitions.
409 This is like `describe-bindings', but displays only Isearch keys."
410 (interactive)
411 (let ((display-buffer-overriding-action isearch--display-help-action))
412 (with-help-window "*Help*"
413 (with-current-buffer standard-output
414 (princ "Isearch Mode Bindings:\n")
415 (princ (substitute-command-keys "\\{isearch-mode-map}"))))))
417 (defun isearch-describe-key ()
418 "Display documentation of the function invoked by isearch key."
419 (interactive)
420 (let ((display-buffer-overriding-action isearch--display-help-action))
421 (call-interactively 'describe-key))
422 (isearch-update))
424 (defun isearch-describe-mode ()
425 "Display documentation of Isearch mode."
426 (interactive)
427 (let ((display-buffer-overriding-action isearch--display-help-action))
428 (describe-function 'isearch-forward))
429 (isearch-update))
431 (defalias 'isearch-mode-help 'isearch-describe-mode)
434 ;; Define isearch-mode keymap.
436 (defvar isearch-mode-map
437 (let ((i 0)
438 (map (make-keymap)))
439 (or (char-table-p (nth 1 map))
440 (error "The initialization of isearch-mode-map must be updated"))
441 ;; Make all multibyte characters search for themselves.
442 (set-char-table-range (nth 1 map) (cons #x100 (max-char))
443 'isearch-printing-char)
445 ;; Single-byte printing chars extend the search string by default.
446 (setq i ?\s)
447 (while (< i 256)
448 (define-key map (vector i) 'isearch-printing-char)
449 (setq i (1+ i)))
451 ;; To handle local bindings with meta char prefix keys, define
452 ;; another full keymap. This must be done for any other prefix
453 ;; keys as well, one full keymap per char of the prefix key. It
454 ;; would be simpler to disable the global keymap, and/or have a
455 ;; default local key binding for any key not otherwise bound.
456 (let ((meta-map (make-sparse-keymap)))
457 (define-key map (char-to-string meta-prefix-char) meta-map))
459 ;; Several non-printing chars change the searching behavior.
460 (define-key map "\C-s" 'isearch-repeat-forward)
461 (define-key map "\C-r" 'isearch-repeat-backward)
462 ;; Define M-C-s and M-C-r like C-s and C-r so that the same key
463 ;; combinations can be used to repeat regexp isearches that can
464 ;; be used to start these searches.
465 (define-key map "\M-\C-s" 'isearch-repeat-forward)
466 (define-key map "\M-\C-r" 'isearch-repeat-backward)
467 (define-key map "\177" 'isearch-delete-char)
468 (define-key map [backspace] 'undefined) ;bug#20466.
469 (define-key map "\C-g" 'isearch-abort)
471 ;; This assumes \e is the meta-prefix-char.
472 (or (= ?\e meta-prefix-char)
473 (error "Inconsistency in isearch.el"))
474 (define-key map "\e\e\e" 'isearch-cancel)
476 (define-key map "\C-q" 'isearch-quote-char)
478 (define-key map "\r" 'isearch-exit)
479 (define-key map [return] 'isearch-exit)
480 (define-key map "\C-j" 'isearch-printing-char)
481 (define-key map "\t" 'isearch-printing-char)
482 (define-key map [?\S-\ ] 'isearch-printing-char)
484 (define-key map "\C-w" 'isearch-yank-word-or-char)
485 (define-key map "\M-\C-w" 'isearch-yank-symbol-or-char)
486 (define-key map "\M-\C-d" 'isearch-del-char)
487 (define-key map "\M-\C-y" 'isearch-yank-char)
488 (define-key map "\C-y" 'isearch-yank-kill)
489 (define-key map "\M-s\C-e" 'isearch-yank-line)
491 (define-key map (char-to-string help-char) isearch-help-map)
492 (define-key map [help] isearch-help-map)
493 (define-key map [f1] isearch-help-map)
495 (define-key map "\M-n" 'isearch-ring-advance)
496 (define-key map "\M-p" 'isearch-ring-retreat)
497 (define-key map "\M-y" 'isearch-yank-pop)
499 (define-key map "\M-\t" 'isearch-complete)
501 ;; Pass frame events transparently so they won't exit the search.
502 ;; In particular, if we have more than one display open, then a
503 ;; switch-frame might be generated by someone typing at another keyboard.
504 (define-key map [switch-frame] nil)
505 (define-key map [delete-frame] nil)
506 (define-key map [iconify-frame] nil)
507 (define-key map [make-frame-visible] nil)
508 (define-key map [mouse-movement] nil)
509 (define-key map [language-change] nil)
511 ;; For searching multilingual text.
512 (define-key map "\C-\\" 'isearch-toggle-input-method)
513 (define-key map "\C-^" 'isearch-toggle-specified-input-method)
515 ;; People expect to be able to paste with the mouse.
516 (define-key map [mouse-2] #'isearch-mouse-2)
517 (define-key map [down-mouse-2] nil)
518 (define-key map [xterm-paste] #'isearch-xterm-paste)
520 ;; Some bindings you may want to put in your isearch-mode-hook.
521 ;; Suggest some alternates...
522 (define-key map "\M-c" 'isearch-toggle-case-fold)
523 (define-key map "\M-r" 'isearch-toggle-regexp)
524 (define-key map "\M-e" 'isearch-edit-string)
526 (put 'isearch-edit-string :advertised-binding "\M-se")
528 (define-key map "\M-se" 'isearch-edit-string)
529 ;; More toggles defined by `isearch-define-mode-toggle'.
531 (define-key map [?\M-%] 'isearch-query-replace)
532 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
533 (define-key map "\M-so" 'isearch-occur)
534 (define-key map "\M-shr" 'isearch-highlight-regexp)
536 ;; The key translations defined in the C-x 8 prefix should add
537 ;; characters to the search string. See iso-transl.el.
538 (define-key map "\C-x8\r" 'isearch-char-by-name)
540 map)
541 "Keymap for `isearch-mode'.")
543 (defvar minibuffer-local-isearch-map
544 (let ((map (make-sparse-keymap)))
545 (set-keymap-parent map minibuffer-local-map)
546 (define-key map "\r" 'exit-minibuffer)
547 (define-key map "\M-\t" 'isearch-complete-edit)
548 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
549 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
550 (define-key map "\C-f" 'isearch-yank-char-in-minibuffer)
551 (define-key map [right] 'isearch-yank-char-in-minibuffer)
552 map)
553 "Keymap for editing Isearch strings in the minibuffer.")
555 ;; Internal variables declared globally for byte-compiler.
556 ;; These are all set with setq while isearching
557 ;; and bound locally while editing the search string.
559 (defvar isearch-forward nil) ; Searching in the forward direction.
560 (defvar isearch-regexp nil) ; Searching for a regexp.
561 (defvar isearch-regexp-function nil
562 "Regexp-based search mode for words/symbols.
563 If the value is a function (e.g. `isearch-symbol-regexp'), it is
564 called to convert a plain search string to a regexp used by
565 regexp search functions.
566 The symbol property `isearch-message-prefix' put on this function
567 specifies the prefix string displayed in the search message.
569 This variable is set and changed during isearch. To change the
570 default behavior used for searches, see `search-default-mode'
571 instead.")
572 ;; We still support setting this to t for backwards compatibility.
573 (define-obsolete-variable-alias 'isearch-word
574 'isearch-regexp-function "25.1")
576 (defvar isearch-lax-whitespace t
577 "If non-nil, a space will match a sequence of whitespace chars.
578 When you enter a space or spaces in ordinary incremental search, it
579 will match any sequence matched by the regexp defined by the variable
580 `search-whitespace-regexp'. If the value is nil, each space you type
581 matches literally, against one space. You can toggle the value of this
582 variable by the command `isearch-toggle-lax-whitespace'.")
584 (defvar isearch-regexp-lax-whitespace nil
585 "If non-nil, a space will match a sequence of whitespace chars.
586 When you enter a space or spaces in regexp incremental search, it
587 will match any sequence matched by the regexp defined by the variable
588 `search-whitespace-regexp'. If the value is nil, each space you type
589 matches literally, against one space. You can toggle the value of this
590 variable by the command `isearch-toggle-lax-whitespace'.")
592 (defvar isearch-cmds nil
593 "Stack of search status elements.
594 Each element is an `isearch--state' struct where the slots are
595 [STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD/REGEXP-FUNCTION
596 ERROR WRAPPED BARRIER CASE-FOLD-SEARCH POP-FUN]")
598 (defvar isearch-string "") ; The current search string.
599 (defvar isearch-message "") ; text-char-description version of isearch-string
601 (defvar isearch-message-prefix-add nil) ; Additional text for the message prefix
602 (defvar isearch-message-suffix-add nil) ; Additional text for the message suffix
604 (defvar isearch-success t) ; Searching is currently successful.
605 (defvar isearch-error nil) ; Error message for failed search.
606 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
607 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
608 (defvar isearch-barrier 0
609 "Recorded minimum/maximal point for the current search.")
610 (defvar isearch-just-started nil)
611 (defvar isearch-start-hscroll 0) ; hscroll when starting the search.
613 ;; case-fold-search while searching.
614 ;; either nil, t, or 'yes. 'yes means the same as t except that mixed
615 ;; case in the search string is ignored.
616 (defvar isearch-case-fold-search nil)
618 ;; search-invisible while searching.
619 ;; either nil, t, or 'open. 'open means the same as t except that
620 ;; opens hidden overlays.
621 (defvar isearch-invisible search-invisible)
623 (defvar isearch-last-case-fold-search nil)
625 ;; Used to save default value while isearch is active
626 (defvar isearch-original-minibuffer-message-timeout nil)
628 (defvar isearch-adjusted nil)
629 (defvar isearch-slow-terminal-mode nil)
630 ;; If t, using a small window.
631 (defvar isearch-small-window nil)
632 (defvar isearch-opoint 0)
633 ;; The window configuration active at the beginning of the search.
634 (defvar isearch-window-configuration nil)
636 ;; Flag to indicate a yank occurred, so don't move the cursor.
637 (defvar isearch-yank-flag nil)
639 ;; A function to be called after each input character is processed.
640 ;; (It is not called after characters that exit the search.)
641 ;; It is only set from an optional argument to `isearch-mode'.
642 (defvar isearch-op-fun nil)
644 ;; Is isearch-mode in a recursive edit for modal searching.
645 (defvar isearch-recursive-edit nil)
647 ;; Should isearch be terminated after doing one search?
648 (defvar isearch-nonincremental nil)
650 ;; New value of isearch-nonincremental after isearch-edit-string.
651 (defvar isearch-new-nonincremental nil)
653 ;; New value of isearch-forward after isearch-edit-string.
654 (defvar isearch-new-forward nil)
656 ;; Accumulate here the overlays opened during searching.
657 (defvar isearch-opened-overlays nil)
659 ;; Non-nil if the string exists but is invisible.
660 (defvar isearch-hidden nil)
662 ;; The value of input-method-function when isearch is invoked.
663 (defvar isearch-input-method-function nil)
665 ;; A flag to tell if input-method-function is locally bound when
666 ;; isearch is invoked.
667 (defvar isearch-input-method-local-p nil)
669 (defvar isearch--saved-overriding-local-map nil)
671 ;; Minor-mode-alist changes - kind of redundant with the
672 ;; echo area, but if isearching in multiple windows, it can be useful.
674 (or (assq 'isearch-mode minor-mode-alist)
675 (nconc minor-mode-alist
676 (list '(isearch-mode isearch-mode))))
678 (defvar-local isearch-mode nil) ;; Name of the minor mode, if non-nil.
680 (define-key global-map "\C-s" 'isearch-forward)
681 (define-key esc-map "\C-s" 'isearch-forward-regexp)
682 (define-key global-map "\C-r" 'isearch-backward)
683 (define-key esc-map "\C-r" 'isearch-backward-regexp)
684 (define-key search-map "w" 'isearch-forward-word)
685 (define-key search-map "_" 'isearch-forward-symbol)
686 (define-key search-map "." 'isearch-forward-symbol-at-point)
688 ;; Entry points to isearch-mode.
690 (defun isearch-forward (&optional regexp-p no-recursive-edit)
692 Do incremental search forward.
693 With a prefix argument, do an incremental regular expression search instead.
694 \\<isearch-mode-map>
695 As you type characters, they add to the search string and are found.
696 The following non-printing keys are bound in `isearch-mode-map'.
698 Type \\[isearch-delete-char] to cancel last input item from end of search string.
699 Type \\[isearch-exit] to exit, leaving point at location found.
700 Type LFD (C-j) to match end of line.
701 Type \\[isearch-repeat-forward] to search again forward,\
702 \\[isearch-repeat-backward] to search again backward.
703 Type \\[isearch-yank-word-or-char] to yank next word or character in buffer
704 onto the end of the search string, and search for it.
705 Type \\[isearch-del-char] to delete character from end of search string.
706 Type \\[isearch-yank-char] to yank char from buffer onto end of search\
707 string and search for it.
708 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
709 and search for it.
710 Type \\[isearch-yank-kill] to yank the last string of killed text.
711 Type \\[isearch-yank-pop] to replace string just yanked into search prompt
712 with string killed before it.
713 Type \\[isearch-quote-char] to quote control character to search for it.
714 Type \\[isearch-char-by-name] to add a character to search by Unicode name,\
715 with completion.
716 \\[isearch-abort] while searching or when search has failed cancels input\
717 back to what has
718 been found successfully.
719 \\[isearch-abort] when search is successful aborts and moves point to\
720 starting point.
722 If you try to exit with the search string still empty, it invokes
723 nonincremental search.
725 Type \\[isearch-toggle-case-fold] to toggle search case-sensitivity.
726 Type \\[isearch-toggle-invisible] to toggle search in invisible text.
727 Type \\[isearch-toggle-regexp] to toggle regular-expression mode.
728 Type \\[isearch-toggle-word] to toggle word mode.
729 Type \\[isearch-toggle-symbol] to toggle symbol mode.
730 Type \\[isearch-toggle-char-fold] to toggle character folding.
732 Type \\[isearch-toggle-lax-whitespace] to toggle whitespace matching.
733 In incremental searches, a space or spaces normally matches any whitespace
734 defined by the variable `search-whitespace-regexp'; see also the variables
735 `isearch-lax-whitespace' and `isearch-regexp-lax-whitespace'.
737 Type \\[isearch-edit-string] to edit the search string in the minibuffer.
739 Also supported is a search ring of the previous 16 search strings.
740 Type \\[isearch-ring-advance] to search for the next item in the search ring.
741 Type \\[isearch-ring-retreat] to search for the previous item in the search\
742 ring.
743 Type \\[isearch-complete] to complete the search string using the search ring.
745 Type \\[isearch-query-replace] to run `query-replace' with string to\
746 replace from last search string.
747 Type \\[isearch-query-replace-regexp] to run `query-replace-regexp'\
748 with the last search string.
749 Type \\[isearch-occur] to run `occur' that shows\
750 the last search string.
751 Type \\[isearch-highlight-regexp] to run `highlight-regexp'\
752 that highlights the last search string.
754 Type \\[isearch-describe-bindings] to display all Isearch key bindings.
755 Type \\[isearch-describe-key] to display documentation of Isearch key.
756 Type \\[isearch-describe-mode] to display documentation of Isearch mode.
758 If an input method is turned on in the current buffer, that input
759 method is also active while you are typing characters to search.
760 To toggle the input method, type \\[isearch-toggle-input-method]. \
761 It also toggles the input
762 method in the current buffer.
764 To use a different input method for searching, type \
765 \\[isearch-toggle-specified-input-method],
766 and specify an input method you want to use.
768 The above keys, bound in `isearch-mode-map', are often controlled by
769 options; do \\[apropos] on search-.* to find them.
770 Other control and meta characters terminate the search
771 and are then executed normally (depending on `search-exit-option').
772 Likewise for function keys and mouse button events.
774 If this function is called non-interactively with a nil NO-RECURSIVE-EDIT,
775 it does not return to the calling function until the search is done.
776 See the function `isearch-mode' for more information."
778 (interactive "P\np")
779 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
781 (defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
782 "Do incremental search forward for regular expression.
783 With a prefix argument, do a regular string search instead.
784 Like ordinary incremental search except that your input is treated
785 as a regexp. See the command `isearch-forward' for more information.
787 In incremental searches, a space or spaces normally matches any
788 whitespace defined by the variable `search-whitespace-regexp'.
789 To search for a literal space and nothing else, enter C-q SPC.
790 To toggle whitespace matching, use `isearch-toggle-lax-whitespace'.
791 This command does not support character folding."
792 (interactive "P\np")
793 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
795 (defun isearch-forward-word (&optional not-word no-recursive-edit)
796 "Do incremental search forward for a sequence of words.
797 With a prefix argument, do a regular string search instead.
798 Like ordinary incremental search except that your input is treated
799 as a sequence of words without regard to how the words are separated.
800 See the command `isearch-forward' for more information.
801 This command does not support character folding, and lax space matching
802 has no effect on it."
803 (interactive "P\np")
804 (isearch-mode t nil nil (not no-recursive-edit) (null not-word)))
806 (defun isearch-forward-symbol (&optional _not-symbol no-recursive-edit)
807 "Do incremental search forward for a symbol.
808 The prefix argument is currently unused.
809 Like ordinary incremental search except that your input is treated
810 as a symbol surrounded by symbol boundary constructs \\_< and \\_>.
811 See the command `isearch-forward' for more information.
812 This command does not support character folding, and lax space matching
813 has no effect on it."
814 (interactive "P\np")
815 (isearch-mode t nil nil (not no-recursive-edit) 'isearch-symbol-regexp))
817 (defun isearch-backward (&optional regexp-p no-recursive-edit)
818 "Do incremental search backward.
819 With a prefix argument, do a regular expression search instead.
820 See the command `isearch-forward' for more information."
821 (interactive "P\np")
822 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
824 (defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
825 "Do incremental search backward for regular expression.
826 With a prefix argument, do a regular string search instead.
827 Like ordinary incremental search except that your input is treated
828 as a regexp. See the command `isearch-forward-regexp' for more information."
829 (interactive "P\np")
830 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
832 (defun isearch-forward-symbol-at-point ()
833 "Do incremental search forward for a symbol found near point.
834 Like ordinary incremental search except that the symbol found at point
835 is added to the search string initially as a regexp surrounded
836 by symbol boundary constructs \\_< and \\_>.
837 See the command `isearch-forward-symbol' for more information."
838 (interactive)
839 (isearch-forward-symbol nil 1)
840 (let ((bounds (find-tag-default-bounds)))
841 (cond
842 (bounds
843 (when (< (car bounds) (point))
844 (goto-char (car bounds)))
845 (isearch-yank-string
846 (buffer-substring-no-properties (car bounds) (cdr bounds))))
848 (setq isearch-error "No symbol at point")
849 (isearch-push-state)
850 (isearch-update)))))
853 ;; isearch-mode only sets up incremental search for the minor mode.
854 ;; All the work is done by the isearch-mode commands.
856 ;; Not used yet:
857 ;;(defvar isearch-commands '(isearch-forward isearch-backward
858 ;; isearch-forward-regexp isearch-backward-regexp)
859 ;; "List of commands for which isearch-mode does not recursive-edit.")
861 (defun isearch-mode (forward &optional regexp op-fun recursive-edit regexp-function)
862 "Start Isearch minor mode.
863 It is called by the function `isearch-forward' and other related functions.
865 The non-nil arg FORWARD means searching in the forward direction.
867 The non-nil arg REGEXP does an incremental regular expression search.
869 The arg OP-FUN is a function to be called after each input character
870 is processed. (It is not called after characters that exit the search.)
872 When the arg RECURSIVE-EDIT is non-nil, this function behaves modally and
873 does not return to the calling function until the search is completed.
874 To behave this way it enters a recursive-edit and exits it when done
875 isearching.
877 The arg REGEXP-FUNCTION, if non-nil, should be a function. It is
878 used to set the value of `isearch-regexp-function'."
880 ;; Initialize global vars.
881 (setq isearch-forward forward
882 isearch-regexp (or regexp
883 (and (not regexp-function)
884 (eq search-default-mode t)))
885 isearch-regexp-function (or regexp-function
886 (and (functionp search-default-mode)
887 (not regexp)
888 search-default-mode))
889 isearch-op-fun op-fun
890 isearch-last-case-fold-search isearch-case-fold-search
891 isearch-case-fold-search case-fold-search
892 isearch-invisible search-invisible
893 isearch-string ""
894 isearch-message ""
895 isearch-cmds nil
896 isearch-success t
897 isearch-wrapped nil
898 isearch-barrier (point)
899 isearch-adjusted nil
900 isearch-yank-flag nil
901 isearch-error nil
902 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
903 (> (window-height)
904 (* 4
905 (abs search-slow-window-lines))))
906 isearch-other-end nil
907 isearch-small-window nil
908 isearch-just-started t
909 isearch-start-hscroll (window-hscroll)
911 isearch-opoint (point)
912 search-ring-yank-pointer nil
913 isearch-opened-overlays nil
914 isearch-input-method-function input-method-function
915 isearch-input-method-local-p (local-variable-p 'input-method-function)
916 regexp-search-ring-yank-pointer nil
918 ;; Save the original value of `minibuffer-message-timeout', and
919 ;; set it to nil so that isearch's messages don't get timed out.
920 isearch-original-minibuffer-message-timeout minibuffer-message-timeout
921 minibuffer-message-timeout nil)
923 ;; We must bypass input method while reading key. When a user type
924 ;; printable character, appropriate input method is turned on in
925 ;; minibuffer to read multibyte characters.
926 (or isearch-input-method-local-p
927 (make-local-variable 'input-method-function))
928 (setq input-method-function nil)
930 (looking-at "")
931 (setq isearch-window-configuration
932 (if isearch-slow-terminal-mode (current-window-configuration) nil))
934 ;; Maybe make minibuffer frame visible and/or raise it.
935 (let ((frame (window-frame (minibuffer-window))))
936 (unless (memq (frame-live-p frame) '(nil t))
937 (unless (frame-visible-p frame)
938 (make-frame-visible frame))
939 (if minibuffer-auto-raise
940 (raise-frame frame))))
942 (setq isearch-mode " Isearch") ;; forward? regexp?
943 (force-mode-line-update)
945 (setq overriding-terminal-local-map isearch-mode-map)
946 (run-hooks 'isearch-mode-hook)
947 ;; Remember the initial map possibly modified
948 ;; by external packages in isearch-mode-hook. (Bug#16035)
949 (setq isearch--saved-overriding-local-map overriding-terminal-local-map)
951 ;; Pushing the initial state used to be before running isearch-mode-hook,
952 ;; but a hook might set `isearch-push-state-function' used in
953 ;; `isearch-push-state' to save mode-specific initial state. (Bug#4994)
954 (isearch-push-state)
956 (isearch-update)
958 (add-hook 'pre-command-hook 'isearch-pre-command-hook)
959 (add-hook 'post-command-hook 'isearch-post-command-hook)
960 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
961 (add-hook 'kbd-macro-termination-hook 'isearch-done)
963 ;; isearch-mode can be made modal (in the sense of not returning to
964 ;; the calling function until searching is completed) by entering
965 ;; a recursive-edit and exiting it when done isearching.
966 (if recursive-edit
967 (let ((isearch-recursive-edit t))
968 (recursive-edit)))
969 isearch-success)
972 ;; Some high level utilities. Others below.
973 (defvar isearch--current-buffer nil)
975 (defun isearch-update ()
976 "This is called after every isearch command to update the display.
977 The second last thing it does is to run `isearch-update-post-hook'.
978 The last thing is to trigger a new round of lazy highlighting."
979 (unless (eq (current-buffer) isearch--current-buffer)
980 (when (buffer-live-p isearch--current-buffer)
981 (with-current-buffer isearch--current-buffer
982 (setq cursor-sensor-inhibit (delq 'isearch cursor-sensor-inhibit))))
983 (setq isearch--current-buffer (current-buffer))
984 (make-local-variable 'cursor-sensor-inhibit)
985 ;; Suspend things like cursor-intangible during Isearch so we can search
986 ;; even within intangible text.
987 (push 'isearch cursor-sensor-inhibit))
989 (if (and (null unread-command-events)
990 (null executing-kbd-macro))
991 (progn
992 (if (not (input-pending-p))
993 (funcall (or isearch-message-function #'isearch-message)))
994 (if (and isearch-slow-terminal-mode
995 (not (or isearch-small-window
996 (pos-visible-in-window-group-p))))
997 (let ((found-point (point)))
998 (setq isearch-small-window t)
999 (move-to-window-line 0)
1000 (let ((window-min-height 1))
1001 (split-window nil (if (< search-slow-window-lines 0)
1002 (1+ (- search-slow-window-lines))
1003 (- (window-height)
1004 (1+ search-slow-window-lines)))))
1005 (if (< search-slow-window-lines 0)
1006 (progn (vertical-motion (- 1 search-slow-window-lines))
1007 (set-window-start (next-window) (point))
1008 (set-window-hscroll (next-window)
1009 (window-hscroll))
1010 (set-window-hscroll (selected-window) 0))
1011 (other-window 1))
1012 (goto-char found-point))
1013 ;; Keep same hscrolling as at the start of the search when possible
1014 (let ((current-scroll (window-hscroll))
1015 visible-p)
1016 (set-window-hscroll (selected-window) isearch-start-hscroll)
1017 (setq visible-p (pos-visible-in-window-group-p nil nil t))
1018 (if (or (not visible-p)
1019 ;; When point is not visible because of hscroll,
1020 ;; pos-visible-in-window-group-p returns non-nil, but
1021 ;; the X coordinate it returns is 1 pixel beyond
1022 ;; the last visible one.
1023 (>= (car visible-p)
1024 (* (window-max-chars-per-line) (frame-char-width))))
1025 (set-window-hscroll (selected-window) current-scroll))))
1026 (if isearch-other-end
1027 (if (< isearch-other-end (point)) ; isearch-forward?
1028 (isearch-highlight isearch-other-end (point))
1029 (isearch-highlight (point) isearch-other-end))
1030 (isearch-dehighlight))))
1031 (setq ;; quit-flag nil not for isearch-mode
1032 isearch-adjusted nil
1033 isearch-yank-flag nil)
1034 ;; We must prevent the point moving to the end of composition when a
1035 ;; part of the composition has just been searched.
1036 (setq disable-point-adjustment t)
1037 (run-hooks 'isearch-update-post-hook)
1038 (when isearch-lazy-highlight
1039 (isearch-lazy-highlight-new-loop)))
1041 (defun isearch-done (&optional nopush edit)
1042 "Exit Isearch mode.
1043 For successful search, pass no args.
1044 For a failing search, NOPUSH is t.
1045 For going to the minibuffer to edit the search string,
1046 NOPUSH is t and EDIT is t."
1048 (if isearch-resume-in-command-history
1049 (let ((command `(isearch-resume ,isearch-string ,isearch-regexp
1050 ,isearch-regexp-function ,isearch-forward
1051 ,isearch-message
1052 ',isearch-case-fold-search)))
1053 (unless (equal (car command-history) command)
1054 (setq command-history (cons command command-history)))))
1056 (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
1057 (remove-hook 'post-command-hook 'isearch-post-command-hook)
1058 (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
1059 (remove-hook 'kbd-macro-termination-hook 'isearch-done)
1060 (setq isearch-lazy-highlight-start nil)
1061 (when (buffer-live-p isearch--current-buffer)
1062 (with-current-buffer isearch--current-buffer
1063 (setq isearch--current-buffer nil)
1064 (setq cursor-sensor-inhibit (delq 'isearch cursor-sensor-inhibit))))
1066 ;; Called by all commands that terminate isearch-mode.
1067 ;; If NOPUSH is non-nil, we don't push the string on the search ring.
1068 (setq overriding-terminal-local-map nil)
1069 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
1070 (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
1071 (isearch-dehighlight)
1072 (lazy-highlight-cleanup lazy-highlight-cleanup)
1073 (let ((found-start (window-group-start))
1074 (found-point (point)))
1075 (when isearch-window-configuration
1076 (set-window-configuration isearch-window-configuration)
1077 (if isearch-small-window
1078 (goto-char found-point)
1079 ;; set-window-configuration clobbers window-start; restore it.
1080 ;; This has an annoying side effect of clearing the last_modiff
1081 ;; field of the window, which can cause unwanted scrolling,
1082 ;; so don't do it unless truly necessary.
1083 (set-window-group-start (selected-window) found-start t))))
1085 (setq isearch-mode nil)
1086 (if isearch-input-method-local-p
1087 (setq input-method-function isearch-input-method-function)
1088 (kill-local-variable 'input-method-function))
1090 (force-mode-line-update)
1092 ;; If we ended in the middle of some intangible text,
1093 ;; move to the further end of that intangible text.
1094 (let ((after (if (eobp) nil
1095 (get-text-property (point) 'intangible)))
1096 (before (if (bobp) nil
1097 (get-text-property (1- (point)) 'intangible))))
1098 (when (and before after (eq before after))
1099 (goto-char
1100 (if isearch-forward
1101 (next-single-property-change (point) 'intangible)
1102 (previous-single-property-change (point) 'intangible)))))
1104 (if (and (> (length isearch-string) 0) (not nopush))
1105 ;; Update the ring data.
1106 (isearch-update-ring isearch-string isearch-regexp))
1108 (let ((isearch-mode-end-hook-quit (and nopush (not edit))))
1109 (run-hooks 'isearch-mode-end-hook))
1111 ;; If there was movement, mark the starting position.
1112 ;; Maybe should test difference between and set mark only if > threshold.
1113 (if (/= (point) isearch-opoint)
1114 (or (and transient-mark-mode mark-active)
1115 (progn
1116 (push-mark isearch-opoint t)
1117 (or executing-kbd-macro (> (minibuffer-depth) 0) edit
1118 (message "Mark saved where search started")))))
1120 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
1122 (defun isearch-update-ring (string &optional regexp)
1123 "Add STRING to the beginning of the search ring.
1124 REGEXP if non-nil says use the regexp search ring."
1125 (add-to-history
1126 (if regexp 'regexp-search-ring 'search-ring)
1127 string
1128 (if regexp regexp-search-ring-max search-ring-max)))
1130 ;; Switching buffers should first terminate isearch-mode.
1131 ;; ;; For Emacs 19, the frame switch event is handled.
1132 ;; (defun isearch-switch-frame-handler ()
1133 ;; (interactive) ;; Is this necessary?
1134 ;; ;; First terminate isearch-mode.
1135 ;; (isearch-done)
1136 ;; (isearch-clean-overlays)
1137 ;; (handle-switch-frame (car (cdr last-command-event))))
1140 ;; The search status structure and stack.
1142 (cl-defstruct (isearch--state
1143 (:constructor nil)
1144 (:copier nil)
1145 (:constructor isearch--get-state
1146 (&aux
1147 (string isearch-string)
1148 (message isearch-message)
1149 (point (point))
1150 (success isearch-success)
1151 (forward isearch-forward)
1152 (other-end isearch-other-end)
1153 (word isearch-regexp-function)
1154 (error isearch-error)
1155 (wrapped isearch-wrapped)
1156 (barrier isearch-barrier)
1157 (case-fold-search isearch-case-fold-search)
1158 (pop-fun (if isearch-push-state-function
1159 (funcall isearch-push-state-function))))))
1160 (string nil :read-only t)
1161 (message nil :read-only t)
1162 (point nil :read-only t)
1163 (success nil :read-only t)
1164 (forward nil :read-only t)
1165 (other-end nil :read-only t)
1166 (word nil :read-only t)
1167 (error nil :read-only t)
1168 (wrapped nil :read-only t)
1169 (barrier nil :read-only t)
1170 (case-fold-search nil :read-only t)
1171 (pop-fun nil :read-only t))
1173 (defun isearch--set-state (cmd)
1174 (setq isearch-string (isearch--state-string cmd)
1175 isearch-message (isearch--state-message cmd)
1176 isearch-success (isearch--state-success cmd)
1177 isearch-forward (isearch--state-forward cmd)
1178 isearch-other-end (isearch--state-other-end cmd)
1179 isearch-regexp-function (isearch--state-word cmd)
1180 isearch-error (isearch--state-error cmd)
1181 isearch-wrapped (isearch--state-wrapped cmd)
1182 isearch-barrier (isearch--state-barrier cmd)
1183 isearch-case-fold-search (isearch--state-case-fold-search cmd))
1184 (if (functionp (isearch--state-pop-fun cmd))
1185 (funcall (isearch--state-pop-fun cmd) cmd))
1186 (goto-char (isearch--state-point cmd)))
1188 (defun isearch-pop-state ()
1189 (setq isearch-cmds (cdr isearch-cmds))
1190 (isearch--set-state (car isearch-cmds)))
1192 (defun isearch-push-state ()
1193 (push (isearch--get-state) isearch-cmds))
1196 ;; Commands active while inside of the isearch minor mode.
1198 (defun isearch-exit ()
1199 "Exit search normally.
1200 However, if this is the first command after starting incremental
1201 search and `search-nonincremental-instead' is non-nil, do a
1202 nonincremental search instead via `isearch-edit-string'."
1203 (interactive)
1204 (if (and search-nonincremental-instead
1205 (= 0 (length isearch-string)))
1206 (let ((isearch-nonincremental t))
1207 (isearch-edit-string)) ;; this calls isearch-done as well
1208 (isearch-done))
1209 (isearch-clean-overlays))
1211 (defun isearch-fail-pos (&optional msg)
1212 "Return position of first mismatch in search string, or nil if none.
1213 If MSG is non-nil, use variable `isearch-message', otherwise `isearch-string'."
1214 (let ((cmds isearch-cmds)
1215 (curr-msg (if msg isearch-message isearch-string))
1216 succ-msg)
1217 (when (or (not isearch-success) isearch-error)
1218 (while (and cmds
1219 (or (not (isearch--state-success (car cmds)))
1220 (isearch--state-error (car cmds))))
1221 (pop cmds))
1222 (setq succ-msg (and cmds (if msg (isearch--state-message (car cmds))
1223 (isearch--state-string (car cmds)))))
1224 (if (and (stringp succ-msg)
1225 (< (length succ-msg) (length curr-msg))
1226 (equal succ-msg
1227 (substring curr-msg 0 (length succ-msg))))
1228 (length succ-msg)
1229 0))))
1231 (defvar isearch-new-regexp-function nil
1232 "Holds the next `isearch-regexp-function' inside `with-isearch-suspended'.
1233 If this is set inside code wrapped by the macro
1234 `with-isearch-suspended', then the value set will be used as the
1235 `isearch-regexp-function' once isearch resumes.")
1236 (define-obsolete-variable-alias 'isearch-new-word
1237 'isearch-new-regexp-function "25.1")
1239 (defvar isearch-suspended nil)
1241 (defmacro with-isearch-suspended (&rest body)
1242 "Exit Isearch mode, run BODY, and reinvoke the pending search.
1243 You can update the global isearch variables by setting new values to
1244 `isearch-new-string', `isearch-new-message', `isearch-new-forward',
1245 `isearch-new-regexp-function', `isearch-new-case-fold', `isearch-new-nonincremental'."
1246 ;; This code is very hairy for several reasons, explained in the code.
1247 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
1248 ;; If there were a way to catch any change of buffer from the minibuffer,
1249 ;; this could be simplified greatly.
1250 ;; Editing doesn't back up the search point. Should it?
1251 `(condition-case nil
1252 (progn
1253 (let ((isearch-new-nonincremental isearch-nonincremental)
1255 ;; Locally bind all isearch global variables to protect them
1256 ;; from recursive isearching.
1257 ;; isearch-string -message and -forward are not bound
1258 ;; so they may be changed. Instead, save the values.
1259 (isearch-new-string isearch-string)
1260 (isearch-new-message isearch-message)
1261 (isearch-new-forward isearch-forward)
1262 (isearch-new-regexp-function isearch-regexp-function)
1263 (isearch-new-case-fold isearch-case-fold-search)
1265 (isearch-regexp isearch-regexp)
1266 (isearch-op-fun isearch-op-fun)
1267 (isearch-cmds isearch-cmds)
1268 (isearch-success isearch-success)
1269 (isearch-wrapped isearch-wrapped)
1270 (isearch-barrier isearch-barrier)
1271 (isearch-adjusted isearch-adjusted)
1272 (isearch-yank-flag isearch-yank-flag)
1273 (isearch-error isearch-error)
1275 (multi-isearch-file-list-new multi-isearch-file-list)
1276 (multi-isearch-buffer-list-new multi-isearch-buffer-list)
1277 (multi-isearch-next-buffer-function multi-isearch-next-buffer-current-function)
1278 (multi-isearch-current-buffer-new multi-isearch-current-buffer)
1279 ;;; Don't bind this. We want isearch-search, below, to set it.
1280 ;;; And the old value won't matter after that.
1281 ;;; (isearch-other-end isearch-other-end)
1282 ;;; Perhaps some of these other variables should be bound for a
1283 ;;; shorter period, ending before the next isearch-search.
1284 ;;; But there doesn't seem to be a real bug, so let's not risk it now.
1285 (isearch-opoint isearch-opoint)
1286 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
1287 (isearch-small-window isearch-small-window)
1288 (isearch-recursive-edit isearch-recursive-edit)
1289 ;; Save current configuration so we can restore it here.
1290 (isearch-window-configuration (current-window-configuration))
1292 ;; This could protect the index of the search rings,
1293 ;; but we can't reliably count the number of typed M-p
1294 ;; in `read-from-minibuffer' to adjust the index accordingly.
1295 ;; So when the following is commented out, `isearch-mode'
1296 ;; below resets the index to the predictable value nil.
1297 ;; (search-ring-yank-pointer search-ring-yank-pointer)
1298 ;; (regexp-search-ring-yank-pointer regexp-search-ring-yank-pointer)
1300 ;; Temporarily restore `minibuffer-message-timeout'.
1301 (minibuffer-message-timeout
1302 isearch-original-minibuffer-message-timeout)
1303 (isearch-original-minibuffer-message-timeout
1304 isearch-original-minibuffer-message-timeout)
1305 old-point old-other-end)
1307 (setq isearch-suspended t)
1309 ;; Actually terminate isearching until editing is done.
1310 ;; This is so that the user can do anything without failure,
1311 ;; like switch buffers and start another isearch, and return.
1312 (condition-case nil
1313 (isearch-done t t)
1314 (exit nil)) ; was recursive editing
1316 ;; Save old point and isearch-other-end before reading from minibuffer
1317 ;; that can change their values.
1318 (setq old-point (point) old-other-end isearch-other-end)
1320 (unwind-protect
1321 (progn ,@body)
1323 (setq isearch-suspended nil)
1325 ;; Always resume isearching by restarting it.
1326 (isearch-mode isearch-forward
1327 isearch-regexp
1328 isearch-op-fun
1330 isearch-regexp-function)
1332 ;; Copy new local values to isearch globals
1333 (setq isearch-string isearch-new-string
1334 isearch-message isearch-new-message
1335 isearch-forward isearch-new-forward
1336 isearch-nonincremental isearch-new-nonincremental
1337 isearch-regexp-function isearch-new-regexp-function
1338 isearch-case-fold-search isearch-new-case-fold
1339 multi-isearch-current-buffer multi-isearch-current-buffer-new
1340 multi-isearch-file-list multi-isearch-file-list-new
1341 multi-isearch-buffer-list multi-isearch-buffer-list-new)
1343 ;; Restore the minibuffer message before moving point.
1344 (funcall (or isearch-message-function #'isearch-message) nil t)
1346 ;; Set point at the start (end) of old match if forward (backward),
1347 ;; so after exiting minibuffer isearch resumes at the start (end)
1348 ;; of this match and can find it again.
1349 (if (and old-other-end (eq old-point (point))
1350 (eq isearch-forward isearch-new-forward))
1351 (goto-char old-other-end)))
1353 ;; Empty isearch-string means use default.
1354 (when (= 0 (length isearch-string))
1355 (setq isearch-string (or (car (if isearch-regexp
1356 regexp-search-ring
1357 search-ring))
1360 isearch-message
1361 (mapconcat 'isearch-text-char-description
1362 isearch-string ""))
1363 ;; After taking the last element, adjust ring to previous one.
1364 (isearch-ring-adjust1 nil)))
1366 ;; This used to push the state as of before this C-s, but it adds
1367 ;; an inconsistent state where part of variables are from the
1368 ;; previous search (e.g. `isearch-success'), and part of variables
1369 ;; are just entered from the minibuffer (e.g. `isearch-string').
1370 ;; (isearch-push-state)
1372 ;; Reinvoke the pending search.
1373 (isearch-search)
1374 (isearch-push-state) ; this pushes the correct state
1375 (isearch-update)
1376 (if isearch-nonincremental
1377 (progn
1378 ;; (sit-for 1) ;; needed if isearch-done does: (message "")
1379 (isearch-done)
1380 ;; The search done message is confusing when the string
1381 ;; is empty, so erase it.
1382 (if (equal isearch-string "")
1383 (message "")))))
1385 (quit ; handle abort-recursive-edit
1386 (setq isearch-suspended nil)
1387 (isearch-abort) ;; outside of let to restore outside global values
1390 (defvar minibuffer-history-symbol) ;; from external package gmhist.el
1392 (defun isearch-edit-string ()
1393 "Edit the search string in the minibuffer.
1394 The following additional command keys are active while editing.
1395 \\<minibuffer-local-isearch-map>
1396 \\[exit-minibuffer] to resume incremental searching with the edited string.
1397 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
1398 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
1399 \\[isearch-complete-edit] to complete the search string using the search ring."
1400 (interactive)
1401 (with-isearch-suspended
1402 (let* ((message-log-max nil)
1403 ;; Don't add a new search string to the search ring here
1404 ;; in `read-from-minibuffer'. It should be added only
1405 ;; by `isearch-update-ring' called from `isearch-done'.
1406 (history-add-new-input nil)
1407 ;; Binding minibuffer-history-symbol to nil is a work-around
1408 ;; for some incompatibility with gmhist.
1409 (minibuffer-history-symbol))
1410 (setq isearch-new-string
1411 (read-from-minibuffer
1412 (isearch-message-prefix nil isearch-nonincremental)
1413 (cons isearch-string (1+ (or (isearch-fail-pos)
1414 (length isearch-string))))
1415 minibuffer-local-isearch-map nil
1416 (if isearch-regexp
1417 (cons 'regexp-search-ring
1418 (1+ (or regexp-search-ring-yank-pointer -1)))
1419 (cons 'search-ring
1420 (1+ (or search-ring-yank-pointer -1))))
1421 nil t)
1422 isearch-new-message
1423 (mapconcat 'isearch-text-char-description
1424 isearch-new-string "")))))
1426 (defun isearch-nonincremental-exit-minibuffer ()
1427 (interactive)
1428 (setq isearch-new-nonincremental t)
1429 (exit-minibuffer))
1430 ;; It makes no sense to change the value of `isearch-new-nonincremental'
1431 ;; from nil to t during `isearch-edit-string'. Thus marked as obsolete.
1432 (make-obsolete 'isearch-nonincremental-exit-minibuffer 'exit-minibuffer "24.4")
1434 (defun isearch-forward-exit-minibuffer ()
1435 "Resume isearching forward from the minibuffer that edits the search string."
1436 (interactive)
1437 (setq isearch-new-forward t isearch-new-nonincremental nil)
1438 (exit-minibuffer))
1440 (defun isearch-reverse-exit-minibuffer ()
1441 "Resume isearching backward from the minibuffer that edits the search string."
1442 (interactive)
1443 (setq isearch-new-forward nil isearch-new-nonincremental nil)
1444 (exit-minibuffer))
1446 (defun isearch-cancel ()
1447 "Terminate the search and go back to the starting point."
1448 (interactive)
1449 (if (and isearch-push-state-function isearch-cmds)
1450 ;; For defined push-state function, restore the first state.
1451 ;; This calls pop-state function and restores original point.
1452 (let ((isearch-cmds (last isearch-cmds)))
1453 (isearch--set-state (car isearch-cmds)))
1454 (goto-char isearch-opoint))
1455 (isearch-done t) ; Exit isearch..
1456 (isearch-clean-overlays)
1457 (signal 'quit nil)) ; ..and pass on quit signal.
1459 (defun isearch-abort ()
1460 "Abort incremental search mode if searching is successful, signaling quit.
1461 Otherwise, revert to previous successful search and continue searching.
1462 Use `isearch-exit' to quit without signaling."
1463 (interactive)
1464 ;; (ding) signal instead below, if quitting
1465 (discard-input)
1466 (if (and isearch-success (not isearch-error))
1467 ;; If search is successful and has no incomplete regexp,
1468 ;; move back to starting point and really do quit.
1469 (progn
1470 (setq isearch-success nil)
1471 (isearch-cancel))
1472 ;; If search is failing, or has an incomplete regexp,
1473 ;; rub out until it is once more successful.
1474 (while (or (not isearch-success) isearch-error)
1475 (isearch-pop-state))
1476 (isearch-update)))
1478 (defun isearch-repeat (direction)
1479 ;; Utility for isearch-repeat-forward and -backward.
1480 (if (eq isearch-forward (eq direction 'forward))
1481 ;; C-s in forward or C-r in reverse.
1482 (if (equal isearch-string "")
1483 ;; If search string is empty, use last one.
1484 (if (null (if isearch-regexp regexp-search-ring search-ring))
1485 (setq isearch-error "No previous search string")
1486 (setq isearch-string
1487 (car (if isearch-regexp regexp-search-ring search-ring))
1488 isearch-message
1489 (mapconcat 'isearch-text-char-description
1490 isearch-string "")
1491 isearch-case-fold-search isearch-last-case-fold-search)
1492 ;; After taking the last element, adjust ring to previous one.
1493 (isearch-ring-adjust1 nil))
1494 ;; If already have what to search for, repeat it.
1495 (or isearch-success
1496 (progn
1497 ;; Set isearch-wrapped before calling isearch-wrap-function
1498 (setq isearch-wrapped t)
1499 (if isearch-wrap-function
1500 (funcall isearch-wrap-function)
1501 (goto-char (if isearch-forward (point-min) (point-max)))))))
1502 ;; C-s in reverse or C-r in forward, change direction.
1503 (setq isearch-forward (not isearch-forward)
1504 isearch-success t))
1506 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
1508 (if (equal isearch-string "")
1509 (setq isearch-success t)
1510 (if (and isearch-success
1511 (equal (point) isearch-other-end)
1512 (not isearch-just-started))
1513 ;; If repeating a search that found
1514 ;; an empty string, ensure we advance.
1515 (if (if isearch-forward (eobp) (bobp))
1516 ;; If there's nowhere to advance to, fail (and wrap next time).
1517 (progn
1518 (setq isearch-success nil)
1519 (ding))
1520 (forward-char (if isearch-forward 1 -1))
1521 (isearch-search))
1522 (isearch-search)))
1524 (isearch-push-state)
1525 (isearch-update))
1527 (defun isearch-repeat-forward ()
1528 "Repeat incremental search forwards."
1529 (interactive)
1530 (isearch-repeat 'forward))
1532 (defun isearch-repeat-backward ()
1533 "Repeat incremental search backwards."
1534 (interactive)
1535 (isearch-repeat 'backward))
1538 ;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
1539 (defmacro isearch-define-mode-toggle (mode key function &optional docstring &rest body)
1540 "Define a command called `isearch-toggle-MODE' and bind it to `M-s KEY'.
1541 The first line of the command's docstring is auto-generated, the
1542 remainder may be provided in DOCSTRING.
1543 If FUNCTION is a symbol, this command first toggles the value of
1544 `isearch-regexp-function' between nil and FUNCTION. Also set the
1545 `isearch-message-prefix' property of FUNCTION.
1546 The command then executes BODY and updates the isearch prompt."
1547 (declare (indent defun))
1548 (let ((command-name (intern (format "isearch-toggle-%s" mode)))
1549 (key (concat "\M-s" key)))
1550 `(progn
1551 (defun ,command-name ()
1552 ,(format "Toggle %s searching on or off.%s" mode
1553 (if docstring (concat "\n" docstring) ""))
1554 (interactive)
1555 ,@(when function
1556 `((setq isearch-regexp-function
1557 (unless (eq isearch-regexp-function #',function)
1558 #',function))
1559 (setq isearch-regexp nil)))
1560 ,@body
1561 (setq isearch-success t isearch-adjusted t)
1562 (isearch-update))
1563 (define-key isearch-mode-map ,key #',command-name)
1564 ,@(when (and function (symbolp function))
1565 `((put ',function 'isearch-message-prefix ,(format "%s " mode))
1566 (put ',function :advertised-binding ,key)
1567 (cl-callf (lambda (types) (cons 'choice
1568 (cons '(const :tag ,(capitalize (format "%s search" mode)) ,function)
1569 (cdr types))))
1570 (get 'search-default-mode 'custom-type)))))))
1572 (isearch-define-mode-toggle word "w" word-search-regexp "\
1573 Turning on word search turns off regexp mode.")
1574 (isearch-define-mode-toggle symbol "_" isearch-symbol-regexp "\
1575 Turning on symbol search turns off regexp mode.")
1576 (isearch-define-mode-toggle char-fold "'" char-fold-to-regexp "\
1577 Turning on character-folding turns off regexp mode.")
1578 (put 'char-fold-to-regexp 'isearch-message-prefix "char-fold ")
1580 (isearch-define-mode-toggle regexp "r" nil nil
1581 (setq isearch-regexp (not isearch-regexp))
1582 (if isearch-regexp (setq isearch-regexp-function nil)))
1584 (defun isearch--momentary-message (string)
1585 "Print STRING at the end of the isearch prompt for 1 second"
1586 (let ((message-log-max nil))
1587 (message "%s%s [%s]"
1588 (isearch-message-prefix nil isearch-nonincremental)
1589 isearch-message
1590 string))
1591 (sit-for 1))
1593 (isearch-define-mode-toggle lax-whitespace " " nil
1594 "In ordinary search, toggles the value of the variable
1595 `isearch-lax-whitespace'. In regexp search, toggles the
1596 value of the variable `isearch-regexp-lax-whitespace'."
1597 (isearch--momentary-message
1598 (if (if isearch-regexp
1599 (setq isearch-regexp-lax-whitespace (not isearch-regexp-lax-whitespace))
1600 (setq isearch-lax-whitespace (not isearch-lax-whitespace)))
1601 "match spaces loosely"
1602 "match spaces literally")))
1604 (isearch-define-mode-toggle case-fold "c" nil
1605 "Toggles the value of the variable `isearch-case-fold-search'."
1606 (isearch--momentary-message
1607 (if (setq isearch-case-fold-search
1608 (if isearch-case-fold-search nil 'yes))
1609 "case insensitive"
1610 "case sensitive")))
1612 (isearch-define-mode-toggle invisible "i" nil
1613 "This determines whether to search inside invisible text or not.
1614 Toggles the variable `isearch-invisible' between values
1615 nil and a non-nil value of the option `search-invisible'
1616 \(or `open' if `search-invisible' is nil)."
1617 "match %svisible text"
1618 (isearch--momentary-message
1619 (if (setq isearch-invisible
1620 (if isearch-invisible
1621 nil (or search-invisible 'open)))
1622 "match invisible text"
1623 "match visible text")))
1626 ;; Word search
1628 (defun word-search-regexp (string &optional lax)
1629 "Return a regexp which matches words, ignoring punctuation.
1630 Given STRING, a string of words separated by word delimiters,
1631 compute a regexp that matches those exact words separated by
1632 arbitrary punctuation. If the string begins or ends in whitespace,
1633 the beginning or the end of the string matches arbitrary whitespace.
1634 Otherwise if LAX is non-nil, the beginning or the end of the string
1635 need not match a word boundary.
1637 Used in `word-search-forward', `word-search-backward',
1638 `word-search-forward-lax', `word-search-backward-lax'."
1639 (cond
1640 ((equal string "") "")
1641 ((string-match-p "\\`\\W+\\'" string) "\\W+")
1642 (t (concat
1643 (if (string-match-p "\\`\\W" string) "\\W+"
1644 "\\<")
1645 (mapconcat 'regexp-quote (split-string string "\\W+" t) "\\W+")
1646 (if (string-match-p "\\W\\'" string) "\\W+"
1647 (unless lax "\\>"))))))
1649 (defun word-search-backward (string &optional bound noerror count)
1650 "Search backward from point for STRING, ignoring differences in punctuation.
1651 Set point to the beginning of the occurrence found, and return point.
1652 An optional second argument bounds the search; it is a buffer position.
1653 The match found must not begin before that position. A value of nil
1654 means search to the beginning of the accessible portion of the buffer.
1655 Optional third argument, if t, means if fail just return nil (no error).
1656 If not nil and not t, position at limit of search and return nil.
1657 Optional fourth argument COUNT, if a positive number, means to search
1658 for COUNT successive occurrences. If COUNT is negative, search
1659 forward, instead of backward, for -COUNT occurrences. A value of
1660 nil means the same as 1.
1661 With COUNT positive, the match found is the COUNTth to last one (or
1662 last, if COUNT is 1 or nil) in the buffer located entirely before
1663 the origin of the search; correspondingly with COUNT negative.
1665 Relies on the function `word-search-regexp' to convert a sequence
1666 of words in STRING to a regexp used to search words without regard
1667 to punctuation.
1668 This command does not support character folding, and lax space matching
1669 has no effect on it."
1670 (interactive "sWord search backward: ")
1671 (re-search-backward (word-search-regexp string nil) bound noerror count))
1673 (defun word-search-forward (string &optional bound noerror count)
1674 "Search forward from point for STRING, ignoring differences in punctuation.
1675 Set point to the end of the occurrence found, and return point.
1676 An optional second argument bounds the search; it is a buffer position.
1677 The match found must not end after that position. A value of nil
1678 means search to the end of the accessible portion of the buffer.
1679 Optional third argument, if t, means if fail just return nil (no error).
1680 If not nil and not t, move to limit of search and return nil.
1681 Optional fourth argument COUNT, if a positive number, means to search
1682 for COUNT successive occurrences. If COUNT is negative, search
1683 backward, instead of forward, for -COUNT occurrences. A value of
1684 nil means the same as 1.
1685 With COUNT positive, the match found is the COUNTth one (or first,
1686 if COUNT is 1 or nil) in the buffer located entirely after the
1687 origin of the search; correspondingly with COUNT negative.
1689 Relies on the function `word-search-regexp' to convert a sequence
1690 of words in STRING to a regexp used to search words without regard
1691 to punctuation.
1692 This command does not support character folding, and lax space matching
1693 has no effect on it."
1694 (interactive "sWord search: ")
1695 (re-search-forward (word-search-regexp string nil) bound noerror count))
1697 (defun word-search-backward-lax (string &optional bound noerror count)
1698 "Search backward from point for STRING, ignoring differences in punctuation.
1699 Set point to the beginning of the occurrence found, and return point.
1701 Unlike `word-search-backward', the end of STRING need not match a word
1702 boundary, unless STRING ends in whitespace.
1704 An optional second argument bounds the search; it is a buffer position.
1705 The match found must not begin before that position. A value of nil
1706 means search to the beginning of the accessible portion of the buffer.
1707 Optional third argument, if t, means if fail just return nil (no error).
1708 If not nil and not t, position at limit of search and return nil.
1709 Optional fourth argument COUNT, if a positive number, means to search
1710 for COUNT successive occurrences. If COUNT is negative, search
1711 forward, instead of backward, for -COUNT occurrences. A value of
1712 nil means the same as 1.
1713 With COUNT positive, the match found is the COUNTth to last one (or
1714 last, if COUNT is 1 or nil) in the buffer located entirely before
1715 the origin of the search; correspondingly with COUNT negative.
1717 Relies on the function `word-search-regexp' to convert a sequence
1718 of words in STRING to a regexp used to search words without regard
1719 to punctuation.
1720 This command does not support character folding, and lax space matching
1721 has no effect on it."
1722 (interactive "sWord search backward: ")
1723 (re-search-backward (word-search-regexp string t) bound noerror count))
1725 (defun word-search-forward-lax (string &optional bound noerror count)
1726 "Search forward from point for STRING, ignoring differences in punctuation.
1727 Set point to the end of the occurrence found, and return point.
1729 Unlike `word-search-forward', the end of STRING need not match a word
1730 boundary, unless STRING ends in whitespace.
1732 An optional second argument bounds the search; it is a buffer position.
1733 The match found must not end after that position. A value of nil
1734 means search to the end of the accessible portion of the buffer.
1735 Optional third argument, if t, means if fail just return nil (no error).
1736 If not nil and not t, move to limit of search and return nil.
1737 Optional fourth argument COUNT, if a positive number, means to search
1738 for COUNT successive occurrences. If COUNT is negative, search
1739 backward, instead of forward, for -COUNT occurrences. A value of
1740 nil means the same as 1.
1741 With COUNT positive, the match found is the COUNTth one (or first,
1742 if COUNT is 1 or nil) in the buffer located entirely after the
1743 origin of the search; correspondingly with COUNT negative.
1745 Relies on the function `word-search-regexp' to convert a sequence
1746 of words in STRING to a regexp used to search words without regard
1747 to punctuation.
1748 This command does not support character folding, and lax space matching
1749 has no effect on it."
1750 (interactive "sWord search: ")
1751 (re-search-forward (word-search-regexp string t) bound noerror count))
1753 ;; Symbol search
1755 (defun isearch-symbol-regexp (string &optional lax)
1756 "Return a regexp which matches STRING as a symbol.
1757 Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>.
1758 If there are more than one symbol, then compute a regexp that matches
1759 those exact symbols separated by non-symbol characters. If the string
1760 begins or ends in whitespace, the beginning or the end of the string
1761 matches arbitrary non-symbol whitespace. Otherwise if LAX is non-nil,
1762 the beginning or the end of the string need not match a symbol boundary."
1763 (let ((not-word-symbol-re
1764 ;; This regexp matches all syntaxes except word and symbol syntax.
1765 ;; FIXME: Replace it with something shorter if possible (bug#14602).
1766 "\\(?:\\s-\\|\\s.\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s/\\|\\s$\\|\\s'\\|\\s<\\|\\s>\\|\\s@\\|\\s!\\|\\s|\\)+"))
1767 (cond
1768 ((equal string "") "")
1769 ((string-match-p (format "\\`%s\\'" not-word-symbol-re) string) not-word-symbol-re)
1770 (t (concat
1771 (if (string-match-p (format "\\`%s" not-word-symbol-re) string) not-word-symbol-re
1772 "\\_<")
1773 (mapconcat 'regexp-quote (split-string string not-word-symbol-re t) not-word-symbol-re)
1774 (if (string-match-p (format "%s\\'" not-word-symbol-re) string) not-word-symbol-re
1775 (unless lax "\\_>")))))))
1777 (put 'isearch-symbol-regexp 'isearch-message-prefix "symbol ")
1779 ;; Search with lax whitespace
1781 (defun search-forward-lax-whitespace (string &optional bound noerror count)
1782 "Search forward for STRING, matching a sequence of whitespace chars."
1783 (let ((search-spaces-regexp search-whitespace-regexp))
1784 (re-search-forward (regexp-quote string) bound noerror count)))
1786 (defun search-backward-lax-whitespace (string &optional bound noerror count)
1787 "Search backward for STRING, matching a sequence of whitespace chars."
1788 (let ((search-spaces-regexp search-whitespace-regexp))
1789 (re-search-backward (regexp-quote string) bound noerror count)))
1791 (defun re-search-forward-lax-whitespace (regexp &optional bound noerror count)
1792 "Search forward for REGEXP, matching a sequence of whitespace chars."
1793 (let ((search-spaces-regexp search-whitespace-regexp))
1794 (re-search-forward regexp bound noerror count)))
1796 (defun re-search-backward-lax-whitespace (regexp &optional bound noerror count)
1797 "Search backward for REGEXP, matching a sequence of whitespace chars."
1798 (let ((search-spaces-regexp search-whitespace-regexp))
1799 (re-search-backward regexp bound noerror count)))
1801 (dolist (old '(re-search-forward-lax-whitespace search-backward-lax-whitespace
1802 search-forward-lax-whitespace re-search-backward-lax-whitespace))
1803 (make-obsolete old
1804 "instead, use (let ((search-spaces-regexp search-whitespace-regexp))
1805 (re-search-... ...))"
1806 "25.1"))
1809 (defun isearch-query-replace (&optional arg regexp-flag)
1810 "Start `query-replace' with string to replace from last search string.
1811 The ARG (prefix arg if interactive), if non-nil, means replace
1812 only matches surrounded by word boundaries. A negative prefix
1813 arg means replace backward. Note that using the prefix arg
1814 is possible only when `isearch-allow-scroll' is non-nil or
1815 `isearch-allow-prefix' is non-nil, and it doesn't always provide the
1816 correct matches for `query-replace', so the preferred way to run word
1817 replacements from Isearch is `M-s w ... M-%'."
1818 (interactive
1819 (list current-prefix-arg))
1820 (barf-if-buffer-read-only)
1821 (if regexp-flag (setq isearch-regexp t))
1822 (let ((case-fold-search isearch-case-fold-search)
1823 ;; set `search-upper-case' to nil to not call
1824 ;; `isearch-no-upper-case-p' in `perform-replace'
1825 (search-upper-case nil)
1826 (search-invisible isearch-invisible)
1827 (replace-lax-whitespace
1828 isearch-lax-whitespace)
1829 (replace-regexp-lax-whitespace
1830 isearch-regexp-lax-whitespace)
1831 (delimited (and arg (not (eq arg '-))))
1832 (backward (and arg (eq arg '-)))
1833 ;; Set `isearch-recursive-edit' to nil to prevent calling
1834 ;; `exit-recursive-edit' in `isearch-done' that terminates
1835 ;; the execution of this command when it is non-nil.
1836 ;; We call `exit-recursive-edit' explicitly at the end below.
1837 (isearch-recursive-edit nil))
1838 (isearch-done nil t)
1839 (isearch-clean-overlays)
1840 (if (and isearch-other-end
1841 (if backward
1842 (> isearch-other-end (point))
1843 (< isearch-other-end (point)))
1844 (not (and transient-mark-mode mark-active
1845 (if backward
1846 (> (mark) (point))
1847 (< (mark) (point))))))
1848 (goto-char isearch-other-end))
1849 (set query-replace-from-history-variable
1850 (cons isearch-string
1851 (symbol-value query-replace-from-history-variable)))
1852 (perform-replace
1853 isearch-string
1854 (query-replace-read-to
1855 isearch-string
1856 (concat "Query replace"
1857 (isearch--describe-regexp-mode (or delimited isearch-regexp-function) t)
1858 (if backward " backward" "")
1859 (if (use-region-p) " in region" ""))
1860 isearch-regexp)
1861 t isearch-regexp (or delimited isearch-regexp-function) nil nil
1862 (if (use-region-p) (region-beginning))
1863 (if (use-region-p) (region-end))
1864 backward))
1865 (and isearch-recursive-edit (exit-recursive-edit)))
1867 (defun isearch-query-replace-regexp (&optional arg)
1868 "Start `query-replace-regexp' with string to replace from last search string.
1869 See `isearch-query-replace' for more information."
1870 (interactive
1871 (list current-prefix-arg))
1872 (isearch-query-replace arg t))
1874 (defun isearch-occur (regexp &optional nlines)
1875 "Run `occur' using the last search string as the regexp.
1876 Interactively, REGEXP is constructed using the search string from the
1877 last search command. NLINES has the same meaning as in `occur'.
1879 If the last search command was a word search, REGEXP is computed from
1880 the search words, ignoring punctuation. If the last search
1881 command was a regular expression search, REGEXP is the regular
1882 expression used in that search. If the last search command searched
1883 for a literal string, REGEXP is constructed by quoting all the special
1884 characters in that string."
1885 (interactive
1886 (let* ((perform-collect (consp current-prefix-arg))
1887 (regexp (cond
1888 ((functionp isearch-regexp-function)
1889 (funcall isearch-regexp-function isearch-string))
1890 (isearch-regexp-function (word-search-regexp isearch-string))
1891 (isearch-regexp isearch-string)
1892 (t (regexp-quote isearch-string)))))
1893 (list regexp
1894 (if perform-collect
1895 ;; Perform collect operation
1896 (if (zerop (regexp-opt-depth regexp))
1897 ;; No subexpression so collect the entire match.
1898 "\\&"
1899 ;; Get the regexp for collection pattern.
1900 (let ((default (car occur-collect-regexp-history))
1901 regexp-collect)
1902 (with-isearch-suspended
1903 (setq regexp-collect
1904 (read-regexp
1905 (format "Regexp to collect (default %s): " default)
1906 default 'occur-collect-regexp-history)))
1907 regexp-collect))
1908 ;; Otherwise normal occur takes numerical prefix argument.
1909 (when current-prefix-arg
1910 (prefix-numeric-value current-prefix-arg))))))
1911 (let ((case-fold-search isearch-case-fold-search)
1912 ;; Set `search-upper-case' to nil to not call
1913 ;; `isearch-no-upper-case-p' in `occur-1'.
1914 (search-upper-case nil)
1915 (search-spaces-regexp
1916 (if (if isearch-regexp
1917 isearch-regexp-lax-whitespace
1918 isearch-lax-whitespace)
1919 search-whitespace-regexp)))
1920 (occur (if isearch-regexp-function
1921 (propertize regexp
1922 'isearch-string isearch-string
1923 'isearch-regexp-function-descr
1924 (isearch--describe-regexp-mode isearch-regexp-function))
1925 regexp)
1926 nlines
1927 (if (use-region-p) (region-bounds)))))
1929 (declare-function hi-lock-read-face-name "hi-lock" ())
1931 (defun isearch-highlight-regexp ()
1932 "Run `highlight-regexp' with regexp from the current search string.
1933 It exits Isearch mode and calls `hi-lock-face-buffer' with its regexp
1934 argument from the last search regexp or a quoted search string,
1935 and reads its face argument using `hi-lock-read-face-name'."
1936 (interactive)
1937 (let (
1938 ;; Set `isearch-recursive-edit' to nil to prevent calling
1939 ;; `exit-recursive-edit' in `isearch-done' that terminates
1940 ;; the execution of this command when it is non-nil.
1941 ;; We call `exit-recursive-edit' explicitly at the end below.
1942 (isearch-recursive-edit nil))
1943 (isearch-done nil t)
1944 (isearch-clean-overlays))
1945 (require 'hi-lock nil t)
1946 (let ((regexp (cond ((functionp isearch-regexp-function)
1947 (funcall isearch-regexp-function isearch-string))
1948 (isearch-regexp-function (word-search-regexp isearch-string))
1949 (isearch-regexp isearch-string)
1950 ((if (and (eq isearch-case-fold-search t)
1951 search-upper-case)
1952 (isearch-no-upper-case-p
1953 isearch-string isearch-regexp)
1954 isearch-case-fold-search)
1955 ;; Turn isearch-string into a case-insensitive
1956 ;; regexp.
1957 (mapconcat
1958 (lambda (c)
1959 (let ((s (string c)))
1960 (if (string-match "[[:alpha:]]" s)
1961 (format "[%s%s]" (upcase s) (downcase s))
1962 (regexp-quote s))))
1963 isearch-string ""))
1964 (t (regexp-quote isearch-string)))))
1965 (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
1966 (and isearch-recursive-edit (exit-recursive-edit)))
1969 (defun isearch-delete-char ()
1970 "Discard last input item and move point back.
1971 Last input means the last character or the last isearch command
1972 that added or deleted characters from the search string,
1973 moved point, toggled regexp mode or case-sensitivity, etc.
1974 If no previous match was done, just beep."
1975 (interactive)
1976 (if (null (cdr isearch-cmds))
1977 (ding)
1978 (isearch-pop-state))
1979 (isearch-update))
1981 (defun isearch-del-char (&optional arg)
1982 "Delete character from end of search string and search again.
1983 Unlike `isearch-delete-char', it only deletes the last character,
1984 but doesn't cancel the effect of other isearch command.
1985 If search string is empty, just beep."
1986 (interactive "p")
1987 (if (= 0 (length isearch-string))
1988 (ding)
1989 (setq isearch-string (substring isearch-string 0
1990 (- (min (or arg 1)
1991 (length isearch-string))))
1992 isearch-message (mapconcat 'isearch-text-char-description
1993 isearch-string "")))
1994 ;; Do the following before moving point.
1995 (funcall (or isearch-message-function #'isearch-message) nil t)
1996 ;; Use the isearch-other-end as new starting point to be able
1997 ;; to find the remaining part of the search string again.
1998 ;; This is like what `isearch-search-and-update' does,
1999 ;; but currently it doesn't support deletion of characters
2000 ;; for the case where unsuccessful search may become successful
2001 ;; by deletion of characters.
2002 (if isearch-other-end (goto-char isearch-other-end))
2003 (isearch-search)
2004 (isearch-push-state)
2005 (isearch-update))
2007 (defun isearch-yank-string (string)
2008 "Pull STRING into search string."
2009 ;; Downcase the string if not supposed to case-fold yanked strings.
2010 (if (and isearch-case-fold-search
2011 (eq 'not-yanks search-upper-case))
2012 (setq string (downcase string)))
2013 (if isearch-regexp (setq string (regexp-quote string)))
2014 ;; Don't move cursor in reverse search.
2015 (setq isearch-yank-flag t)
2016 (isearch-process-search-string
2017 string (mapconcat 'isearch-text-char-description string "")))
2019 (defun isearch-yank-kill ()
2020 "Pull string from kill ring into search string."
2021 (interactive)
2022 (isearch-yank-string (current-kill 0)))
2024 (defun isearch-yank-pop ()
2025 "Replace just-yanked search string with previously killed string."
2026 (interactive)
2027 (if (not (memq last-command '(isearch-yank-kill isearch-yank-pop)))
2028 ;; Fall back on `isearch-yank-kill' for the benefits of people
2029 ;; who are used to the old behavior of `M-y' in isearch mode. In
2030 ;; future, this fallback may be changed if we ever change
2031 ;; `yank-pop' to do something like the kill-ring-browser.
2032 (isearch-yank-kill)
2033 (isearch-pop-state)
2034 (isearch-yank-string (current-kill 1))))
2036 (defun isearch-yank-x-selection ()
2037 "Pull current X selection into search string."
2038 (interactive)
2039 (isearch-yank-string (gui-get-selection))
2040 ;; If `gui-get-selection' returned the text from the active region,
2041 ;; then it "used" the mark which we should hence deactivate.
2042 (when select-active-regions (deactivate-mark)))
2045 (defun isearch-mouse-2 (click)
2046 "Handle mouse-2 in Isearch mode.
2047 For a click in the echo area, invoke `isearch-yank-x-selection'.
2048 Otherwise invoke whatever the calling mouse-2 command sequence
2049 is bound to outside of Isearch."
2050 (interactive "e")
2051 (let ((w (posn-window (event-start click)))
2052 (binding (let ((overriding-terminal-local-map nil))
2053 (key-binding (this-command-keys-vector) t))))
2054 (if (and (window-minibuffer-p w)
2055 (not (minibuffer-window-active-p w))) ; in echo area
2056 (isearch-yank-x-selection)
2057 (when (functionp binding)
2058 (call-interactively binding)))))
2060 (declare-function xterm--pasted-text "term/xterm" ())
2062 (defun isearch-xterm-paste ()
2063 "Pull terminal paste into search string."
2064 (interactive)
2065 (isearch-yank-string (xterm--pasted-text)))
2067 (defun isearch-yank-internal (jumpform)
2068 "Pull the text from point to the point reached by JUMPFORM.
2069 JUMPFORM is a lambda expression that takes no arguments and returns
2070 a buffer position, possibly having moved point to that position.
2071 For example, it might move point forward by a word and return point,
2072 or it might return the position of the end of the line."
2073 (isearch-yank-string
2074 (save-excursion
2075 (and (not isearch-forward) isearch-other-end
2076 (goto-char isearch-other-end))
2077 (buffer-substring-no-properties (point) (funcall jumpform)))))
2079 (defun isearch-yank-char-in-minibuffer (&optional arg)
2080 "Pull next character from buffer into end of search string in minibuffer."
2081 (interactive "p")
2082 (if (eobp)
2083 (insert
2084 (with-current-buffer (cadr (buffer-list))
2085 (buffer-substring-no-properties
2086 (point) (progn (forward-char arg) (point)))))
2087 (forward-char arg)))
2089 (defun isearch-yank-char (&optional arg)
2090 "Pull next character from buffer into search string.
2091 If optional ARG is non-nil, pull in the next ARG characters."
2092 (interactive "p")
2093 (isearch-yank-internal (lambda () (forward-char arg) (point))))
2095 (defun isearch--yank-char-or-syntax (syntax-list fn)
2096 (isearch-yank-internal
2097 (lambda ()
2098 (if (or (memq (char-syntax (or (char-after) 0)) syntax-list)
2099 (memq (char-syntax (or (char-after (1+ (point))) 0))
2100 syntax-list))
2101 (funcall fn 1)
2102 (forward-char 1))
2103 (point))))
2105 (defun isearch-yank-word-or-char ()
2106 "Pull next character or word from buffer into search string."
2107 (interactive)
2108 (isearch--yank-char-or-syntax '(?w) 'forward-word))
2110 (defun isearch-yank-symbol-or-char ()
2111 "Pull next character or symbol from buffer into search string."
2112 (interactive)
2113 (isearch--yank-char-or-syntax '(?w ?_) 'forward-symbol))
2115 (defun isearch-yank-word (&optional arg)
2116 "Pull next word from buffer into search string.
2117 If optional ARG is non-nil, pull in the next ARG words."
2118 (interactive "p")
2119 (isearch-yank-internal (lambda () (forward-word arg) (point))))
2121 (defun isearch-yank-line (&optional arg)
2122 "Pull rest of line from buffer into search string.
2123 If optional ARG is non-nil, yank the next ARG lines."
2124 (interactive "p")
2125 (isearch-yank-internal
2126 (lambda () (let ((inhibit-field-text-motion t))
2127 (line-end-position (if (eolp) (1+ arg) arg))))))
2129 (defun isearch-char-by-name (&optional count)
2130 "Read a character by its Unicode name and add it to the search string.
2131 Completion is available like in `read-char-by-name' used by `insert-char'.
2132 With argument, add COUNT copies of the character."
2133 (interactive "p")
2134 (with-isearch-suspended
2135 (let ((char (read-char-by-name "Add character to search (Unicode name or hex): ")))
2136 (when char
2137 (let ((string (if (and (integerp count) (> count 1))
2138 (make-string count char)
2139 (char-to-string char))))
2140 (setq isearch-new-string (concat isearch-string string)
2141 isearch-new-message (concat isearch-message
2142 (mapconcat 'isearch-text-char-description
2143 string ""))))))))
2145 (defun isearch-search-and-update ()
2146 ;; Do the search and update the display.
2147 (when (or isearch-success
2148 ;; Unsuccessful regexp search may become successful by
2149 ;; addition of characters which make isearch-string valid
2150 isearch-regexp
2151 ;; If the string was found but was completely invisible,
2152 ;; it might now be partly visible, so try again.
2153 (prog1 isearch-hidden (setq isearch-hidden nil)))
2154 ;; In reverse search, adding stuff at
2155 ;; the end may cause zero or many more chars to be
2156 ;; matched, in the string following point.
2157 ;; Allow all those possibilities without moving point as
2158 ;; long as the match does not extend past search origin.
2159 (if (and (not isearch-forward) (not isearch-adjusted)
2160 (condition-case ()
2161 (let ((case-fold-search isearch-case-fold-search))
2162 (if (and (eq case-fold-search t) search-upper-case)
2163 (setq case-fold-search
2164 (isearch-no-upper-case-p isearch-string isearch-regexp)))
2165 (looking-at (cond
2166 ((functionp isearch-regexp-function)
2167 (funcall isearch-regexp-function isearch-string t))
2168 (isearch-regexp-function (word-search-regexp isearch-string t))
2169 (isearch-regexp isearch-string)
2170 (t (regexp-quote isearch-string)))))
2171 (error nil))
2172 (or isearch-yank-flag
2173 (<= (match-end 0)
2174 (min isearch-opoint isearch-barrier))))
2175 (progn
2176 (setq isearch-success t
2177 isearch-error nil
2178 isearch-other-end (match-end 0))
2179 (if (and (eq isearch-case-fold-search t) search-upper-case)
2180 (setq isearch-case-fold-search
2181 (isearch-no-upper-case-p isearch-string isearch-regexp))))
2182 ;; Not regexp, not reverse, or no match at point.
2183 ;; Do the following before moving point.
2184 (funcall (or isearch-message-function #'isearch-message) nil t)
2185 (if (and isearch-other-end (not isearch-adjusted))
2186 (goto-char (if isearch-forward isearch-other-end
2187 (min isearch-opoint
2188 isearch-barrier
2189 (1+ isearch-other-end)))))
2190 (isearch-search)
2192 (isearch-push-state)
2193 (if isearch-op-fun (funcall isearch-op-fun))
2194 (isearch-update))
2197 ;; *, ?, }, and | chars can make a regexp more liberal.
2198 ;; They can make a regexp match sooner or make it succeed instead of failing.
2199 ;; So go back to place last successful search started
2200 ;; or to the last ^S/^R (barrier), whichever is nearer.
2201 ;; + needs no special handling because the string must match at least once.
2203 (defun isearch-backslash (str)
2204 "Return t if STR ends in an odd number of backslashes."
2205 (= (mod (- (length str) (string-match "\\\\*\\'" str)) 2) 1))
2207 (defun isearch-fallback (want-backslash &optional allow-invalid to-barrier)
2208 "Return point to previous successful match to allow regexp liberalization.
2209 \\<isearch-mode-map>
2210 Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by \
2211 stopping at `isearch-barrier' as needed.
2213 Do nothing if a backslash is escaping the liberalizing character.
2214 If WANT-BACKSLASH is non-nil, invert this behavior (for \\} and \\|).
2216 Do nothing if regexp has recently been invalid unless optional
2217 ALLOW-INVALID non-nil.
2219 If optional TO-BARRIER non-nil, ignore previous matches and go exactly
2220 to the barrier."
2221 ;; (eq (not a) (not b)) makes all non-nil values equivalent
2222 (when (and isearch-regexp (eq (not (isearch-backslash isearch-string))
2223 (not want-backslash))
2224 ;; We have to check 2 stack frames because the last might be
2225 ;; invalid just because of a backslash.
2226 (or (not isearch-error)
2227 (not (isearch--state-error (cadr isearch-cmds)))
2228 allow-invalid))
2229 (if to-barrier
2230 (progn (goto-char isearch-barrier)
2231 (setq isearch-adjusted t))
2232 (let* ((stack isearch-cmds)
2233 (previous (cdr stack)) ; lookbelow in the stack
2234 (frame (car stack)))
2235 ;; Walk down the stack looking for a valid regexp (as of course only
2236 ;; they can be the previous successful match); this conveniently
2237 ;; removes all bracket-sets and groups that might be in the way, as
2238 ;; well as partial \{\} constructs that the code below leaves behind.
2239 ;; Also skip over postfix operators -- though horrid,
2240 ;; 'ab?\{5,6\}+\{1,2\}*' is perfectly valid.
2241 (while (and previous
2242 (or (isearch--state-error frame)
2243 (let* ((string (isearch--state-string frame))
2244 (lchar (aref string (1- (length string)))))
2245 ;; The operators aren't always operators; check
2246 ;; backslashes. This doesn't handle the case of
2247 ;; operators at the beginning of the regexp not
2248 ;; being special, but then we should fall back to
2249 ;; the barrier anyway because it's all optional.
2250 (if (isearch-backslash
2251 (isearch--state-string (car previous)))
2252 (eq lchar ?\})
2253 (memq lchar '(?* ?? ?+))))))
2254 (setq stack previous previous (cdr previous) frame (car stack)))
2255 (when stack
2256 ;; `stack' now refers the most recent valid regexp that is not at
2257 ;; all optional in its last term. Now dig one level deeper and find
2258 ;; what matched before that.
2259 (let ((last-other-end
2260 (or (and (car previous)
2261 (isearch--state-other-end (car previous)))
2262 isearch-barrier)))
2263 (goto-char (if isearch-forward
2264 (max last-other-end isearch-barrier)
2265 (min last-other-end isearch-barrier)))
2266 (setq isearch-adjusted t)))))))
2268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2269 ;; scrolling within Isearch mode. Alan Mackenzie (acm@muc.de), 2003/2/24
2271 ;; The idea here is that certain vertical scrolling commands (like C-l
2272 ;; `recenter') should be usable WITHIN Isearch mode. For a command to be
2273 ;; suitable, it must NOT alter the buffer, swap to another buffer or frame,
2274 ;; tamper with isearch's state, or move point. It is unacceptable for the
2275 ;; search string to be scrolled out of the current window. If a command
2276 ;; attempts this, we scroll the text back again.
2278 ;; We implement this feature with a property called `isearch-scroll'.
2279 ;; If a command's symbol has the value t for this property or for the
2280 ;; `scroll-command' property, it is a scrolling command. The feature
2281 ;; needs to be enabled by setting the customizable variable
2282 ;; `isearch-allow-scroll' to a non-nil value.
2284 ;; The universal argument commands (e.g. C-u) in simple.el are marked
2285 ;; as scrolling commands, and isearch.el has been amended to allow
2286 ;; prefix arguments to be passed through to scrolling commands. Thus
2287 ;; M-0 C-l will scroll point to the top of the window.
2289 ;; Horizontal scrolling commands are currently not catered for.
2290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2292 ;; Set the isearch-scroll property on some standard functions:
2293 ;; Scroll-bar functions:
2294 (if (fboundp 'scroll-bar-toolkit-scroll)
2295 (put 'scroll-bar-toolkit-scroll 'isearch-scroll t))
2296 (if (fboundp 'w32-handle-scroll-bar-event)
2297 (put 'w32-handle-scroll-bar-event 'isearch-scroll t))
2299 ;; Commands which scroll the window (some scroll commands
2300 ;; already have the `scroll-command' property on them):
2301 (put 'recenter 'isearch-scroll t)
2302 (put 'recenter-top-bottom 'isearch-scroll t)
2303 (put 'reposition-window 'isearch-scroll t)
2305 ;; Commands which act on the other window
2306 (put 'list-buffers 'isearch-scroll t)
2307 (put 'scroll-other-window 'isearch-scroll t)
2308 (put 'scroll-other-window-down 'isearch-scroll t)
2309 (put 'beginning-of-buffer-other-window 'isearch-scroll t)
2310 (put 'end-of-buffer-other-window 'isearch-scroll t)
2312 ;; Commands which change the window layout
2313 (put 'delete-other-windows 'isearch-scroll t)
2314 (put 'balance-windows 'isearch-scroll t)
2315 (put 'split-window-right 'isearch-scroll t)
2316 (put 'split-window-below 'isearch-scroll t)
2317 (put 'enlarge-window 'isearch-scroll t)
2319 ;; Aliases for split-window-*
2320 (put 'split-window-vertically 'isearch-scroll t)
2321 (put 'split-window-horizontally 'isearch-scroll t)
2323 ;; Universal argument commands
2324 (put 'universal-argument 'isearch-scroll t)
2325 (put 'universal-argument-more 'isearch-scroll t)
2326 (put 'negative-argument 'isearch-scroll t)
2327 (put 'digit-argument 'isearch-scroll t)
2329 (defcustom isearch-allow-scroll nil
2330 "Whether scrolling is allowed during incremental search.
2331 If non-nil, scrolling commands can be used in Isearch mode.
2332 However, the current match will never scroll offscreen.
2333 If nil, scrolling commands will first cancel Isearch mode."
2334 :type 'boolean
2335 :group 'isearch)
2337 (defcustom isearch-allow-prefix t
2338 "Whether prefix arguments are allowed during incremental search.
2339 If non-nil, entering a prefix argument will not terminate the
2340 search. This option is ignored \(presumed t) when
2341 `isearch-allow-scroll' is set."
2342 :version "24.4"
2343 :type 'boolean
2344 :group 'isearch)
2346 (defun isearch-string-out-of-window (isearch-point)
2347 "Test whether the search string is currently outside of the window.
2348 Return nil if it's completely visible, or if point is visible,
2349 together with as much of the search string as will fit; the symbol
2350 `above' if we need to scroll the text downwards; the symbol `below',
2351 if upwards."
2352 (let ((w-start (window-group-start))
2353 (w-end (window-group-end nil t))
2354 (w-L1 (save-excursion
2355 (save-selected-window (move-to-window-group-line 1) (point))))
2356 (w-L-1 (save-excursion
2357 (save-selected-window (move-to-window-group-line -1) (point))))
2358 start end) ; start and end of search string in buffer
2359 (if isearch-forward
2360 (setq end isearch-point start (or isearch-other-end isearch-point))
2361 (setq start isearch-point end (or isearch-other-end isearch-point)))
2362 (cond ((or (and (>= start w-start) (<= end w-end))
2363 (if isearch-forward
2364 (and (>= isearch-point w-L-1) (< isearch-point w-end)) ; point on Line -1
2365 (and (>= isearch-point w-start) (< isearch-point w-L1)))) ; point on Line 0
2366 nil)
2367 ((and (< start w-start)
2368 (< isearch-point w-L-1))
2369 'above)
2370 (t 'below))))
2372 (defun isearch-back-into-window (above isearch-point)
2373 "Scroll the window to bring the search string back into view.
2374 Restore point to ISEARCH-POINT in the process. ABOVE is t when the
2375 search string is above the top of the window, nil when it is beneath
2376 the bottom."
2377 (let (start end)
2378 (if isearch-forward
2379 (setq end isearch-point start (or isearch-other-end isearch-point))
2380 (setq start isearch-point end (or isearch-other-end isearch-point)))
2381 (if above
2382 (progn
2383 (goto-char start)
2384 (recenter-window-group 0)
2385 (when (>= isearch-point (window-group-end nil t))
2386 (goto-char isearch-point)
2387 (recenter-window-group -1)))
2388 (goto-char end)
2389 (recenter-window-group -1)
2390 (when (< isearch-point (window-group-start))
2391 (goto-char isearch-point)
2392 (recenter-window-group 0))))
2393 (goto-char isearch-point))
2395 (defvar isearch-pre-scroll-point nil)
2396 (defvar isearch-pre-move-point nil)
2398 (defun isearch-pre-command-hook ()
2399 "Decide whether to exit Isearch mode before executing the command.
2400 Don't exit Isearch if the key sequence that invoked this command
2401 is bound in `isearch-mode-map', or if the invoked command is
2402 a prefix argument command (when `isearch-allow-prefix' is non-nil),
2403 or it is a scrolling command (when `isearch-allow-scroll' is non-nil).
2404 Otherwise, exit Isearch (when `search-exit-option' is t)
2405 before the command is executed globally with terminated Isearch.
2406 See more for options in `search-exit-option'."
2407 (let* ((key (this-single-command-keys))
2408 (main-event (aref key 0)))
2409 (cond
2410 ;; Don't exit Isearch if we're in the middle of some
2411 ;; `set-transient-map' thingy like `universal-argument--mode'.
2412 ((not (eq overriding-terminal-local-map isearch--saved-overriding-local-map)))
2413 ;; Don't exit Isearch for isearch key bindings.
2414 ((commandp (lookup-key isearch-mode-map key nil)))
2415 ;; Optionally edit the search string instead of exiting.
2416 ((eq search-exit-option 'edit)
2417 (setq this-command 'isearch-edit-string))
2418 ;; Handle a scrolling function or prefix argument.
2419 ((or (and isearch-allow-prefix
2420 (memq this-command '(universal-argument universal-argument-more
2421 digit-argument negative-argument)))
2422 (and isearch-allow-scroll
2423 (symbolp this-command)
2424 (or (eq (get this-command 'isearch-scroll) t)
2425 (eq (get this-command 'scroll-command) t))))
2426 (when isearch-allow-scroll
2427 (setq isearch-pre-scroll-point (point))))
2428 ;; A mouse click on the isearch message starts editing the search string.
2429 ((and (eq (car-safe main-event) 'down-mouse-1)
2430 (window-minibuffer-p (posn-window (event-start main-event))))
2431 ;; Swallow the up-event.
2432 (read-event)
2433 (setq this-command 'isearch-edit-string))
2434 ;; Don't terminate the search for motion commands.
2435 ((or (and (eq search-exit-option 'move)
2436 (symbolp this-command)
2437 (eq (get this-command 'isearch-move) t))
2438 (and (eq search-exit-option 'shift-move)
2439 this-command-keys-shift-translated))
2440 (setq this-command-keys-shift-translated nil)
2441 (setq isearch-pre-move-point (point)))
2442 ;; Append control characters to the search string
2443 ((eq search-exit-option 'append)
2444 (when (cl-every #'characterp key)
2445 (isearch-process-search-string key key))
2446 (setq this-command 'ignore))
2447 ;; Other characters terminate the search and are then executed normally.
2448 (search-exit-option
2449 (isearch-done)
2450 (isearch-clean-overlays)))))
2452 (defun isearch-post-command-hook ()
2453 (cond
2454 (isearch-pre-scroll-point
2455 (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point)))
2456 (if ab-bel
2457 (isearch-back-into-window (eq ab-bel 'above) isearch-pre-scroll-point)
2458 (goto-char isearch-pre-scroll-point)))
2459 (setq isearch-pre-scroll-point nil)
2460 (isearch-update))
2461 ((memq search-exit-option '(move shift-move))
2462 (when (and isearch-pre-move-point
2463 (not (eq isearch-pre-move-point (point))))
2464 (let ((string (buffer-substring-no-properties
2465 (or isearch-other-end isearch-opoint) (point))))
2466 (if isearch-regexp (setq string (regexp-quote string)))
2467 (setq isearch-string string)
2468 (setq isearch-message (mapconcat 'isearch-text-char-description
2469 string ""))
2470 (setq isearch-yank-flag t)
2471 (setq isearch-forward (<= (or isearch-other-end isearch-opoint) (point)))
2472 (goto-char isearch-pre-move-point)
2473 (isearch-search-and-update)))
2474 (setq isearch-pre-move-point nil))))
2476 (defun isearch-quote-char (&optional count)
2477 "Quote special characters for incremental search.
2478 With argument, add COUNT copies of the character."
2479 (interactive "p")
2480 (let ((char (read-quoted-char (isearch-message t))))
2481 (unless (characterp char)
2482 (user-error "%s is not a valid character"
2483 (key-description (vector char))))
2484 ;; Assume character codes 0200 - 0377 stand for characters in some
2485 ;; single-byte character set, and convert them to Emacs
2486 ;; characters.
2487 (if (and isearch-regexp isearch-regexp-lax-whitespace (= char ?\s))
2488 (if (subregexp-context-p isearch-string (length isearch-string))
2489 (isearch-process-search-string "[ ]" " ")
2490 (isearch-process-search-char char count))
2491 ;; This used to assume character codes 0240 - 0377 stand for
2492 ;; characters in some single-byte character set, and converted them
2493 ;; to Emacs characters. But in 23.1 this feature is deprecated
2494 ;; in favor of inserting the corresponding Unicode characters.
2495 ;; (and enable-multibyte-characters
2496 ;; (>= char ?\200)
2497 ;; (<= char ?\377)
2498 ;; (setq char (unibyte-char-to-multibyte char)))
2499 (isearch-process-search-char char count))))
2501 (defun isearch-printing-char (&optional char count)
2502 "Add this ordinary printing CHAR to the search string and search.
2503 With argument, add COUNT copies of the character."
2504 (interactive (list last-command-event
2505 (prefix-numeric-value current-prefix-arg)))
2506 (let ((char (or char last-command-event)))
2507 (if (= char ?\S-\ )
2508 (setq char ?\s))
2509 (if current-input-method
2510 (isearch-process-search-multibyte-characters char count)
2511 (isearch-process-search-char char count))))
2513 (defun isearch-process-search-char (char &optional count)
2514 "Add CHAR to the search string, COUNT times.
2515 Search is updated accordingly."
2516 ;; * and ? are special in regexps when not preceded by \.
2517 ;; } and | are special in regexps when preceded by \.
2518 ;; Nothing special for + because it matches at least once.
2519 (cond
2520 ((memq char '(?* ??)) (isearch-fallback nil))
2521 ((eq char ?\}) (isearch-fallback t t))
2522 ((eq char ?|) (isearch-fallback t nil t)))
2524 ;; Append the char(s) to the search string,
2525 ;; update the message and re-search.
2526 (let* ((string (if (and (integerp count) (> count 1))
2527 (make-string count char)
2528 (char-to-string char)))
2529 (message (if (>= char ?\200)
2530 string
2531 (mapconcat 'isearch-text-char-description string ""))))
2532 (isearch-process-search-string string message)))
2534 (defun isearch-process-search-string (string message)
2535 (setq isearch-string (concat isearch-string string)
2536 isearch-message (concat isearch-message message))
2537 (isearch-search-and-update))
2540 ;; Search Ring
2542 (defun isearch-ring-adjust1 (advance)
2543 ;; Helper for isearch-ring-adjust
2544 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
2545 (length (length ring))
2546 (yank-pointer-name (if isearch-regexp
2547 'regexp-search-ring-yank-pointer
2548 'search-ring-yank-pointer))
2549 (yank-pointer (eval yank-pointer-name)))
2550 (if (zerop length)
2552 (set yank-pointer-name
2553 (setq yank-pointer
2554 (mod (+ (or yank-pointer (if advance 0 -1))
2555 (if advance -1 1))
2556 length)))
2557 (setq isearch-string (nth yank-pointer ring)
2558 isearch-message (mapconcat 'isearch-text-char-description
2559 isearch-string "")))))
2561 (defun isearch-ring-adjust (advance)
2562 ;; Helper for isearch-ring-advance and isearch-ring-retreat
2563 (isearch-ring-adjust1 advance)
2564 (if search-ring-update
2565 (progn
2566 (funcall (or isearch-message-function #'isearch-message) nil t)
2567 (isearch-search)
2568 (isearch-push-state)
2569 (isearch-update))
2570 ;; Otherwise, edit the search string instead. Note that there is
2571 ;; no need to push the search state after isearch-edit-string here
2572 ;; since isearch-edit-string already pushes its state
2573 (isearch-edit-string)))
2575 (defun isearch-ring-advance ()
2576 "Advance to the next search string in the ring."
2577 ;; This could be more general to handle a prefix arg, but who would use it.
2578 (interactive)
2579 (isearch-ring-adjust 'advance))
2581 (defun isearch-ring-retreat ()
2582 "Retreat to the previous search string in the ring."
2583 (interactive)
2584 (isearch-ring-adjust nil))
2586 (defun isearch-complete1 ()
2587 ;; Helper for isearch-complete and isearch-complete-edit
2588 ;; Return t if completion OK, nil if no completion exists.
2589 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
2590 (completion-ignore-case case-fold-search)
2591 (completion (try-completion isearch-string ring)))
2592 (cond
2593 ((eq completion t)
2594 ;; isearch-string stays the same
2596 ((or completion ; not nil, must be a string
2597 (= 0 (length isearch-string))) ; shouldn't have to say this
2598 (if (equal completion isearch-string) ;; no extension?
2599 (progn
2600 (if completion-auto-help
2601 (with-output-to-temp-buffer "*Isearch completions*"
2602 (display-completion-list
2603 (all-completions isearch-string ring))))
2605 (and completion
2606 (setq isearch-string completion))))
2608 (message "No completion") ; waits a second if in minibuffer
2609 nil))))
2611 (defun isearch-complete ()
2612 "Complete the search string from the strings on the search ring.
2613 The completed string is then editable in the minibuffer.
2614 If there is no completion possible, say so and continue searching."
2615 (interactive)
2616 (if (isearch-complete1)
2617 (progn (setq isearch-message
2618 (mapconcat 'isearch-text-char-description
2619 isearch-string ""))
2620 (isearch-edit-string))
2621 ;; else
2622 (sit-for 1)
2623 (isearch-update)))
2625 (defun isearch-complete-edit ()
2626 "Same as `isearch-complete' except in the minibuffer."
2627 (interactive)
2628 (setq isearch-string (field-string))
2629 (if (isearch-complete1)
2630 (progn
2631 (delete-field)
2632 (insert isearch-string))))
2635 ;; Message string
2637 (defun isearch-message (&optional c-q-hack ellipsis)
2638 ;; Generate and print the message string.
2640 ;; N.B.: This function should always be called with point at the
2641 ;; search point, because in certain (rare) circumstances, undesired
2642 ;; scrolling can happen when point is elsewhere. These
2643 ;; circumstances are when follow-mode is active, the search string
2644 ;; spans two (or several) windows, and the message about to be
2645 ;; displayed will cause the echo area to expand.
2646 (let ((cursor-in-echo-area ellipsis)
2647 (m isearch-message)
2648 (fail-pos (isearch-fail-pos t)))
2649 ;; Highlight failed part
2650 (when fail-pos
2651 (setq m (copy-sequence m))
2652 (add-text-properties fail-pos (length m) '(face isearch-fail) m)
2653 ;; Highlight failed trailing whitespace
2654 (when (string-match " +$" m)
2655 (add-text-properties (match-beginning 0) (match-end 0)
2656 '(face trailing-whitespace) m)))
2657 (setq m (concat
2658 (isearch-message-prefix ellipsis isearch-nonincremental)
2660 (isearch-message-suffix c-q-hack)))
2661 (if c-q-hack m (let ((message-log-max nil)) (message "%s" m)))))
2663 (defun isearch--describe-regexp-mode (regexp-function &optional space-before)
2664 "Make a string for describing REGEXP-FUNCTION.
2665 If SPACE-BEFORE is non-nil, put a space before, instead of after,
2666 the word mode."
2667 (when (eq regexp-function t)
2668 (setq regexp-function #'word-search-regexp))
2669 (let ((description
2670 (cond
2671 ;; 1. Do not use a description on the default search mode,
2672 ;; but only if the default search mode is non-nil.
2673 ((or (and search-default-mode
2674 (equal search-default-mode regexp-function))
2675 ;; Special case where `search-default-mode' is t
2676 ;; (defaults to regexp searches).
2677 (and (eq search-default-mode t)
2678 (eq search-default-mode isearch-regexp))) "")
2679 ;; 2. Use the `isearch-message-prefix' set for
2680 ;; `regexp-function' if available.
2681 (regexp-function
2682 (and (symbolp regexp-function)
2683 (or (get regexp-function 'isearch-message-prefix)
2684 "")))
2685 ;; 3. Else if `isearch-regexp' is non-nil, set description
2686 ;; to "regexp ".
2687 (isearch-regexp "regexp ")
2688 ;; 4. Else if we're in literal mode (and if the default
2689 ;; mode is also not literal), describe it.
2690 ((functionp search-default-mode) "literal ")
2691 ;; 5. And finally, if none of the above is true, set the
2692 ;; description to an empty string.
2693 (t ""))))
2694 (if space-before
2695 ;; Move space from the end to the beginning.
2696 (replace-regexp-in-string "\\(.*\\) \\'" " \\1" description)
2697 description)))
2698 (define-obsolete-function-alias 'isearch--describe-word-mode
2699 'isearch--describe-regexp-mode "25.1")
2701 (defun isearch-message-prefix (&optional ellipsis nonincremental)
2702 ;; If about to search, and previous search regexp was invalid,
2703 ;; check that it still is. If it is valid now,
2704 ;; let the message we display while searching say that it is valid.
2705 (and isearch-error ellipsis
2706 (condition-case ()
2707 (progn (re-search-forward isearch-string (point) t)
2708 (setq isearch-error nil))
2709 (error nil)))
2710 ;; If currently failing, display no ellipsis.
2711 (or isearch-success (setq ellipsis nil))
2712 (let ((m (concat (if isearch-success "" "failing ")
2713 (if isearch-adjusted "pending " "")
2714 (if (and isearch-wrapped
2715 (not isearch-wrap-function)
2716 (if isearch-forward
2717 (> (point) isearch-opoint)
2718 (< (point) isearch-opoint)))
2719 "over")
2720 (if isearch-wrapped "wrapped ")
2721 (let ((prefix ""))
2722 (advice-function-mapc
2723 (lambda (_ props)
2724 (let ((np (cdr (assq 'isearch-message-prefix props))))
2725 (if np (setq prefix (concat np prefix)))))
2726 isearch-filter-predicate)
2727 prefix)
2728 (isearch--describe-regexp-mode isearch-regexp-function)
2729 (cond
2730 (multi-isearch-file-list "multi-file ")
2731 (multi-isearch-buffer-list "multi-buffer ")
2732 (t ""))
2733 (or isearch-message-prefix-add "")
2734 (if nonincremental "search" "I-search")
2735 (if isearch-forward "" " backward")
2736 (if current-input-method
2737 ;; Input methods for RTL languages use RTL
2738 ;; characters for their title, and that messes
2739 ;; up the display of search text after the prompt.
2740 (bidi-string-mark-left-to-right
2741 (concat " [" current-input-method-title "]: "))
2742 ": ")
2744 (propertize (concat (upcase (substring m 0 1)) (substring m 1))
2745 'face 'minibuffer-prompt)))
2747 (defun isearch-message-suffix (&optional c-q-hack)
2748 (concat (if c-q-hack "^Q" "")
2749 (if isearch-error
2750 (concat " [" isearch-error "]")
2752 (or isearch-message-suffix-add "")))
2755 ;; Searching
2757 (defvar isearch-search-fun-function 'isearch-search-fun-default
2758 "Non-default value overrides the behavior of `isearch-search-fun-default'.
2759 This variable's value should be a function, which will be called
2760 with no arguments, and should return a function that takes three
2761 arguments: STRING, BOUND, and NOERROR. STRING is the string to
2762 be searched for. See `re-search-forward' for the meaning of
2763 BOUND and NOERROR arguments.
2765 This returned function will be used by `isearch-search-string' to
2766 search for the first occurrence of STRING.")
2768 (defun isearch-search-fun ()
2769 "Return the function to use for the search.
2770 Can be changed via `isearch-search-fun-function' for special needs."
2771 (funcall (or isearch-search-fun-function 'isearch-search-fun-default)))
2773 (defun isearch--lax-regexp-function-p ()
2774 "Non-nil if next regexp-function call should be lax."
2775 (not (or isearch-nonincremental
2776 (null (car isearch-cmds))
2777 (eq (length isearch-string)
2778 (length (isearch--state-string
2779 (car isearch-cmds)))))))
2781 (defun isearch-search-fun-default ()
2782 "Return default functions to use for the search."
2783 (lambda (string &optional bound noerror count)
2784 ;; Use lax versions to not fail at the end of the word while
2785 ;; the user adds and removes characters in the search string
2786 ;; (or when using nonincremental word isearch)
2787 (let ((search-spaces-regexp (when (cond
2788 (isearch-regexp isearch-regexp-lax-whitespace)
2789 (t isearch-lax-whitespace))
2790 search-whitespace-regexp)))
2791 (condition-case er
2792 (funcall
2793 (if isearch-forward #'re-search-forward #'re-search-backward)
2794 (cond (isearch-regexp-function
2795 (let ((lax (and (not bound) (isearch--lax-regexp-function-p))))
2796 (when lax
2797 (setq isearch-adjusted t))
2798 (if (functionp isearch-regexp-function)
2799 (funcall isearch-regexp-function string lax)
2800 (word-search-regexp string lax))))
2801 (isearch-regexp string)
2802 (t (regexp-quote string)))
2803 bound noerror count)
2804 (search-failed
2805 (signal (car er)
2806 (let ((prefix (get isearch-regexp-function 'isearch-message-prefix)))
2807 (if (and isearch-regexp-function (stringp prefix))
2808 (list (format "%s [using %ssearch]" string prefix))
2809 (cdr er)))))))))
2811 (defun isearch-search-string (string bound noerror)
2812 "Search for the first occurrence of STRING or its translation.
2813 STRING's characters are translated using `translation-table-for-input'
2814 if that is non-nil.
2815 If found, move point to the end of the occurrence,
2816 update the match data, and return point.
2817 An optional second argument bounds the search; it is a buffer position.
2818 The match found must not extend after that position.
2819 Optional third argument, if t, means if fail just return nil (no error).
2820 If not nil and not t, move to limit of search and return nil."
2821 (let* ((func (isearch-search-fun))
2822 (pos1 (save-excursion (funcall func string bound noerror)))
2823 pos2)
2824 (when (and
2825 ;; Avoid "obsolete" warnings for translation-table-for-input.
2826 (with-no-warnings
2827 (char-table-p translation-table-for-input))
2828 (multibyte-string-p string)
2829 ;; Minor optimization.
2830 (string-match-p "[^[:ascii:]]" string))
2831 (let ((translated
2832 (apply 'string
2833 (mapcar (lambda (c)
2835 ;; Avoid "obsolete" warnings for
2836 ;; translation-table-for-input.
2837 (with-no-warnings
2838 (aref translation-table-for-input c))
2840 string)))
2841 match-data)
2842 (when translated
2843 (save-match-data
2844 (save-excursion
2845 (if (setq pos2 (funcall func translated bound noerror))
2846 (setq match-data (match-data t)))))
2847 (when (and pos2
2848 (or (not pos1)
2849 (if isearch-forward (< pos2 pos1) (> pos2 pos1))))
2850 (setq pos1 pos2)
2851 (set-match-data match-data)))))
2852 (when pos1
2853 ;; When using multiple buffers isearch, switch to the new buffer here,
2854 ;; because `save-excursion' above doesn't allow doing it inside funcall.
2855 (if (and multi-isearch-next-buffer-current-function
2856 (buffer-live-p multi-isearch-current-buffer))
2857 (switch-to-buffer multi-isearch-current-buffer))
2858 (goto-char pos1)
2859 pos1)))
2861 (defun isearch-search ()
2862 ;; Do the search with the current search string.
2863 (if (and (eq isearch-case-fold-search t) search-upper-case)
2864 (setq isearch-case-fold-search
2865 (isearch-no-upper-case-p isearch-string isearch-regexp)))
2866 (condition-case lossage
2867 (let ((inhibit-point-motion-hooks isearch-invisible)
2868 (inhibit-quit nil)
2869 (case-fold-search isearch-case-fold-search)
2870 (search-invisible isearch-invisible)
2871 (retry t))
2872 (setq isearch-error nil)
2873 (while retry
2874 (setq isearch-success
2875 (isearch-search-string isearch-string nil t))
2876 ;; Clear RETRY unless the search predicate says
2877 ;; to skip this search hit.
2878 (if (or (not isearch-success)
2879 (bobp) (eobp)
2880 (= (match-beginning 0) (match-end 0))
2881 (funcall isearch-filter-predicate
2882 (match-beginning 0) (match-end 0)))
2883 (setq retry nil)))
2884 (setq isearch-just-started nil)
2885 (if isearch-success
2886 (setq isearch-other-end
2887 (if isearch-forward (match-beginning 0) (match-end 0)))))
2889 (quit (isearch-unread ?\C-g)
2890 (setq isearch-success nil))
2892 (invalid-regexp
2893 (setq isearch-error (car (cdr lossage)))
2894 (cond
2895 ((string-match
2896 "\\`Premature \\|\\`Unmatched "
2897 isearch-error)
2898 (setq isearch-error "incomplete input"))
2899 ((and (not isearch-regexp)
2900 (string-match "\\`Regular expression too big" isearch-error))
2901 (cond
2902 (isearch-regexp-function
2903 (setq isearch-error "Too many words"))
2904 ((and isearch-lax-whitespace search-whitespace-regexp)
2905 (setq isearch-error "Too many spaces for whitespace matching"))))))
2907 (search-failed
2908 (setq isearch-success nil)
2909 (setq isearch-error (nth 2 lossage)))
2911 (error
2912 ;; stack overflow in regexp search.
2913 (setq isearch-error (format "%s" lossage))))
2915 (if isearch-success
2917 ;; Ding if failed this time after succeeding last time.
2918 (and (isearch--state-success (car isearch-cmds))
2919 (ding))
2920 (if (functionp (isearch--state-pop-fun (car isearch-cmds)))
2921 (funcall (isearch--state-pop-fun (car isearch-cmds))
2922 (car isearch-cmds)))
2923 (goto-char (isearch--state-point (car isearch-cmds)))))
2926 ;; Called when opening an overlay, and we are still in isearch.
2927 (defun isearch-open-overlay-temporary (ov)
2928 (if (not (null (overlay-get ov 'isearch-open-invisible-temporary)))
2929 ;; Some modes would want to open the overlays temporary during
2930 ;; isearch in their own way, they should set the
2931 ;; `isearch-open-invisible-temporary' to a function doing this.
2932 (funcall (overlay-get ov 'isearch-open-invisible-temporary) ov nil)
2933 ;; Store the values for the `invisible' property, and then set it to nil.
2934 ;; This way the text hidden by this overlay becomes visible.
2936 ;; In 19.34 this does not exist so I cannot test it.
2937 (overlay-put ov 'isearch-invisible (overlay-get ov 'invisible))
2938 (overlay-put ov 'invisible nil)))
2941 ;; This is called at the end of isearch. It will open the overlays
2942 ;; that contain the latest match. Obviously in case of a C-g the
2943 ;; point returns to the original location which surely is not contain
2944 ;; in any of these overlays, se we are safe in this case too.
2945 (defun isearch-open-necessary-overlays (ov)
2946 (let ((inside-overlay (and (> (point) (overlay-start ov))
2947 (<= (point) (overlay-end ov))))
2948 ;; If this exists it means that the overlay was opened using
2949 ;; this function, not by us tweaking the overlay properties.
2950 (fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
2951 (when (or inside-overlay (not fct-temp))
2952 ;; restore the values for the `invisible' properties.
2953 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
2954 (overlay-put ov 'isearch-invisible nil))
2955 (if inside-overlay
2956 (funcall (overlay-get ov 'isearch-open-invisible) ov)
2957 (if fct-temp
2958 (funcall fct-temp ov t)))))
2960 ;; This is called when exiting isearch. It closes the temporary
2961 ;; opened overlays, except the ones that contain the latest match.
2962 (defun isearch-clean-overlays ()
2963 (when isearch-opened-overlays
2964 (mapc 'isearch-open-necessary-overlays isearch-opened-overlays)
2965 (setq isearch-opened-overlays nil)))
2968 (defun isearch-intersects-p (start0 end0 start1 end1)
2969 "Return t if regions START0..END0 and START1..END1 intersect."
2970 (or (and (>= start0 start1) (< start0 end1))
2971 (and (> end0 start1) (<= end0 end1))
2972 (and (>= start1 start0) (< start1 end0))
2973 (and (> end1 start0) (<= end1 end0))))
2976 ;; Verify if the current match is outside of each element of
2977 ;; `isearch-opened-overlays', if so close that overlay.
2979 (defun isearch-close-unnecessary-overlays (begin end)
2980 (let ((overlays isearch-opened-overlays))
2981 (setq isearch-opened-overlays nil)
2982 (dolist (ov overlays)
2983 (if (isearch-intersects-p begin end (overlay-start ov) (overlay-end ov))
2984 (push ov isearch-opened-overlays)
2985 (let ((fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
2986 (if fct-temp
2987 ;; If this exists it means that the overlay was opened
2988 ;; using this function, not by us tweaking the overlay
2989 ;; properties.
2990 (funcall fct-temp ov t)
2991 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
2992 (overlay-put ov 'isearch-invisible nil)))))))
2995 (defun isearch-range-invisible (beg end)
2996 "Return t if all the text from BEG to END is invisible."
2997 (when (/= beg end)
2998 ;; Check that invisibility runs up to END.
2999 (save-excursion
3000 (goto-char beg)
3001 (let (;; can-be-opened keeps track if we can open some overlays.
3002 (can-be-opened (eq search-invisible 'open))
3003 ;; the list of overlays that could be opened
3004 (crt-overlays nil))
3005 (when (and can-be-opened isearch-hide-immediately)
3006 (isearch-close-unnecessary-overlays beg end))
3007 ;; If the following character is currently invisible,
3008 ;; skip all characters with that same `invisible' property value.
3009 ;; Do that over and over.
3010 (while (and (< (point) end) (invisible-p (point)))
3011 (if (invisible-p (get-text-property (point) 'invisible))
3012 (progn
3013 (goto-char (next-single-property-change (point) 'invisible
3014 nil end))
3015 ;; if text is hidden by an `invisible' text property
3016 ;; we cannot open it at all.
3017 (setq can-be-opened nil))
3018 (when can-be-opened
3019 (let ((overlays (overlays-at (point)))
3020 ov-list
3022 invis-prop)
3023 (while overlays
3024 (setq o (car overlays)
3025 invis-prop (overlay-get o 'invisible))
3026 (if (invisible-p invis-prop)
3027 (if (overlay-get o 'isearch-open-invisible)
3028 (setq ov-list (cons o ov-list))
3029 ;; We found one overlay that cannot be
3030 ;; opened, that means the whole chunk
3031 ;; cannot be opened.
3032 (setq can-be-opened nil)))
3033 (setq overlays (cdr overlays)))
3034 (if can-be-opened
3035 ;; It makes sense to append to the open
3036 ;; overlays list only if we know that this is
3037 ;; t.
3038 (setq crt-overlays (append ov-list crt-overlays)))))
3039 (goto-char (next-overlay-change (point)))))
3040 ;; See if invisibility reaches up thru END.
3041 (if (>= (point) end)
3042 (if (and can-be-opened (consp crt-overlays))
3043 (progn
3044 (setq isearch-opened-overlays
3045 (append isearch-opened-overlays crt-overlays))
3046 (mapc 'isearch-open-overlay-temporary crt-overlays)
3047 nil)
3048 (setq isearch-hidden t)))))))
3050 (defun isearch-filter-visible (beg end)
3051 "Test whether the current search hit is visible at least partially.
3052 Return non-nil if the text from BEG to END is visible to Isearch as
3053 determined by `isearch-range-invisible' unless invisible text can be
3054 searched too when `search-invisible' is t."
3055 (or (eq search-invisible t)
3056 (not (isearch-range-invisible beg end))))
3059 ;; General utilities
3061 (defun isearch-no-upper-case-p (string regexp-flag)
3062 "Return t if there are no upper case chars in STRING.
3063 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
3064 since they have special meaning in a regexp."
3065 (let (quote-flag (i 0) (len (length string)) found)
3066 (while (and (not found) (< i len))
3067 (let ((char (aref string i)))
3068 (if (and regexp-flag (eq char ?\\))
3069 (setq quote-flag (not quote-flag))
3070 (if (and (not quote-flag) (not (eq char (downcase char))))
3071 (setq found t))
3072 (setq quote-flag nil)))
3073 (setq i (1+ i)))
3074 (not (or found
3075 ;; Even if there's no uppercase char, we want to detect the use
3076 ;; of [:upper:] or [:lower:] char-class, which indicates
3077 ;; clearly that the user cares about case distinction.
3078 (and regexp-flag (string-match "\\[:\\(upp\\|low\\)er:]" string)
3079 (condition-case err
3080 (progn
3081 (string-match (substring string 0 (match-beginning 0))
3083 nil)
3084 (invalid-regexp
3085 (equal "Unmatched [ or [^" (cadr err)))))))))
3087 ;; Portability functions to support various Emacs versions.
3089 (defun isearch-text-char-description (c)
3090 (cond
3091 ((< c ?\s) (propertize
3092 (char-to-string c)
3093 'display (propertize (format "^%c" (+ c 64)) 'face 'escape-glyph)))
3094 ((= c ?\^?) (propertize
3095 (char-to-string c)
3096 'display (propertize "^?" 'face 'escape-glyph)))
3097 (t (char-to-string c))))
3099 ;; General function to unread characters or events.
3100 ;; Also insert them in a keyboard macro being defined.
3101 (defun isearch-unread (&rest char-or-events)
3102 (mapc 'store-kbd-macro-event char-or-events)
3103 (setq unread-command-events
3104 (append char-or-events unread-command-events)))
3107 ;; Highlighting
3109 (defvar isearch-overlay nil)
3111 (defun isearch-highlight (beg end)
3112 (if search-highlight
3113 (if isearch-overlay
3114 ;; Overlay already exists, just move it.
3115 (move-overlay isearch-overlay beg end (current-buffer))
3116 ;; Overlay doesn't exist, create it.
3117 (setq isearch-overlay (make-overlay beg end))
3118 ;; 1001 is higher than lazy's 1000 and ediff's 100+
3119 (overlay-put isearch-overlay 'priority 1001)
3120 (overlay-put isearch-overlay 'face isearch-face))))
3122 (defun isearch-dehighlight ()
3123 (when isearch-overlay
3124 (delete-overlay isearch-overlay)))
3126 ;; isearch-lazy-highlight feature
3127 ;; by Bob Glickstein <http://www.zanshin.com/~bobg/>
3129 ;; When active, *every* match for the current search string is
3130 ;; highlighted: the current one using the normal isearch match color
3131 ;; and all the others using `isearch-lazy-highlight'. The extra
3132 ;; highlighting makes it easier to anticipate where the cursor will
3133 ;; land each time you press C-s or C-r to repeat a pending search.
3134 ;; Highlighting of these additional matches happens in a deferred
3135 ;; fashion using "idle timers," so the cycles needed do not rob
3136 ;; isearch of its usual snappy response.
3138 ;; IMPLEMENTATION NOTE: This depends on some isearch internals.
3139 ;; Specifically:
3140 ;; - `isearch-update' is expected to be called (at least) every time
3141 ;; the search string or window-start changes;
3142 ;; - `isearch-string' is expected to contain the current search
3143 ;; string as entered by the user;
3144 ;; - the type of the current search is expected to be given by
3145 ;; `isearch-regexp-function' and `isearch-regexp';
3146 ;; - the direction of the current search is expected to be given by
3147 ;; `isearch-forward';
3148 ;; - the variable `isearch-error' is expected to be true
3149 ;; only if `isearch-string' is an invalid regexp.
3151 (defvar isearch-lazy-highlight-overlays nil)
3152 (defvar isearch-lazy-highlight-wrapped nil)
3153 (defvar isearch-lazy-highlight-start-limit nil)
3154 (defvar isearch-lazy-highlight-end-limit nil)
3155 (defvar isearch-lazy-highlight-start nil)
3156 (defvar isearch-lazy-highlight-end nil)
3157 (defvar isearch-lazy-highlight-timer nil)
3158 (defvar isearch-lazy-highlight-last-string nil)
3159 (defvar isearch-lazy-highlight-window nil)
3160 (defvar isearch-lazy-highlight-window-group nil)
3161 (defvar isearch-lazy-highlight-window-start nil)
3162 (defvar isearch-lazy-highlight-window-end nil)
3163 (defvar isearch-lazy-highlight-case-fold-search nil)
3164 (defvar isearch-lazy-highlight-regexp nil)
3165 (defvar isearch-lazy-highlight-lax-whitespace nil)
3166 (defvar isearch-lazy-highlight-regexp-lax-whitespace nil)
3167 (defvar isearch-lazy-highlight-regexp-function nil)
3168 (define-obsolete-variable-alias 'isearch-lazy-highlight-word
3169 'isearch-lazy-highlight-regexp-function "25.1")
3170 (defvar isearch-lazy-highlight-forward nil)
3171 (defvar isearch-lazy-highlight-error nil)
3173 (defun lazy-highlight-cleanup (&optional force procrastinate)
3174 "Stop lazy highlighting and remove extra highlighting from current buffer.
3175 FORCE non-nil means do it whether or not `lazy-highlight-cleanup' is nil.
3176 PROCRASTINATE non-nil means postpone cleanup to a later time.
3177 This function is called when exiting an incremental search if
3178 `lazy-highlight-cleanup' is non-nil."
3179 (interactive '(t))
3180 (when (and (or force lazy-highlight-cleanup) (not procrastinate))
3181 (while isearch-lazy-highlight-overlays
3182 (delete-overlay (car isearch-lazy-highlight-overlays))
3183 (setq isearch-lazy-highlight-overlays
3184 (cdr isearch-lazy-highlight-overlays))))
3185 (when isearch-lazy-highlight-timer
3186 (cancel-timer isearch-lazy-highlight-timer)
3187 (setq isearch-lazy-highlight-timer nil)))
3189 (defun isearch-lazy-highlight-new-loop (&optional beg end)
3190 "Cleanup any previous `lazy-highlight' loop and begin a new one.
3191 BEG and END specify the bounds within which highlighting should occur.
3192 This is called when `isearch-update' is invoked (which can cause the
3193 search string to change or the window to scroll). It is also used
3194 by other Emacs features."
3195 (when (and (null executing-kbd-macro)
3196 (sit-for 0) ;make sure (window-start) is credible
3197 (or (not (equal isearch-string
3198 isearch-lazy-highlight-last-string))
3199 (not (memq (selected-window)
3200 isearch-lazy-highlight-window-group))
3201 (not (eq isearch-lazy-highlight-case-fold-search
3202 isearch-case-fold-search))
3203 (not (eq isearch-lazy-highlight-regexp
3204 isearch-regexp))
3205 (not (eq isearch-lazy-highlight-regexp-function
3206 isearch-regexp-function))
3207 (not (eq isearch-lazy-highlight-lax-whitespace
3208 isearch-lax-whitespace))
3209 (not (eq isearch-lazy-highlight-regexp-lax-whitespace
3210 isearch-regexp-lax-whitespace))
3211 (not (= (window-group-start)
3212 isearch-lazy-highlight-window-start))
3213 (not (= (window-group-end) ; Window may have been split/joined.
3214 isearch-lazy-highlight-window-end))
3215 (not (eq isearch-forward
3216 isearch-lazy-highlight-forward))
3217 ;; In case we are recovering from an error.
3218 (not (equal isearch-error
3219 isearch-lazy-highlight-error))))
3220 ;; something important did indeed change
3221 (lazy-highlight-cleanup t (not (equal isearch-string ""))) ;stop old timer
3222 (setq isearch-lazy-highlight-error isearch-error)
3223 ;; It used to check for `(not isearch-error)' here, but actually
3224 ;; lazy-highlighting might find matches to highlight even when
3225 ;; `isearch-error' is non-nil. (Bug#9918)
3226 (setq isearch-lazy-highlight-start-limit beg
3227 isearch-lazy-highlight-end-limit end)
3228 (setq isearch-lazy-highlight-window (selected-window)
3229 isearch-lazy-highlight-window-group (selected-window-group)
3230 isearch-lazy-highlight-window-start (window-group-start)
3231 isearch-lazy-highlight-window-end (window-group-end)
3232 ;; Start lazy-highlighting at the beginning of the found
3233 ;; match (`isearch-other-end'). If no match, use point.
3234 ;; One of the next two variables (depending on search direction)
3235 ;; is used to define the starting position of lazy-highlighting
3236 ;; and also to remember the current position of point between
3237 ;; calls of `isearch-lazy-highlight-update', and another variable
3238 ;; is used to define where the wrapped search must stop.
3239 isearch-lazy-highlight-start (or isearch-other-end (point))
3240 isearch-lazy-highlight-end (or isearch-other-end (point))
3241 isearch-lazy-highlight-wrapped nil
3242 isearch-lazy-highlight-last-string isearch-string
3243 isearch-lazy-highlight-case-fold-search isearch-case-fold-search
3244 isearch-lazy-highlight-regexp isearch-regexp
3245 isearch-lazy-highlight-lax-whitespace isearch-lax-whitespace
3246 isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace
3247 isearch-lazy-highlight-regexp-function isearch-regexp-function
3248 isearch-lazy-highlight-forward isearch-forward)
3249 (unless (equal isearch-string "")
3250 (setq isearch-lazy-highlight-timer
3251 (run-with-idle-timer lazy-highlight-initial-delay nil
3252 'isearch-lazy-highlight-start)))))
3254 (defun isearch-lazy-highlight-search ()
3255 "Search ahead for the next or previous match, for lazy highlighting.
3256 Attempt to do the search exactly the way the pending Isearch would."
3257 (condition-case nil
3258 (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
3259 (isearch-regexp isearch-lazy-highlight-regexp)
3260 (isearch-regexp-function isearch-lazy-highlight-regexp-function)
3261 (isearch-lax-whitespace
3262 isearch-lazy-highlight-lax-whitespace)
3263 (isearch-regexp-lax-whitespace
3264 isearch-lazy-highlight-regexp-lax-whitespace)
3265 (isearch-forward isearch-lazy-highlight-forward)
3266 (search-invisible nil) ; don't match invisible text
3267 (retry t)
3268 (success nil)
3269 (bound (if isearch-lazy-highlight-forward
3270 (min (or isearch-lazy-highlight-end-limit (point-max))
3271 (if isearch-lazy-highlight-wrapped
3272 (+ isearch-lazy-highlight-start
3273 ;; Extend bound to match whole string at point
3274 (1- (length isearch-lazy-highlight-last-string)))
3275 (window-group-end)))
3276 (max (or isearch-lazy-highlight-start-limit (point-min))
3277 (if isearch-lazy-highlight-wrapped
3278 (- isearch-lazy-highlight-end
3279 ;; Extend bound to match whole string at point
3280 (1- (length isearch-lazy-highlight-last-string)))
3281 (window-group-start))))))
3282 ;; Use a loop like in `isearch-search'.
3283 (while retry
3284 (setq success (isearch-search-string
3285 isearch-lazy-highlight-last-string bound t))
3286 ;; Clear RETRY unless the search predicate says
3287 ;; to skip this search hit.
3288 (if (or (not success)
3289 (= (point) bound) ; like (bobp) (eobp) in `isearch-search'.
3290 (= (match-beginning 0) (match-end 0))
3291 (funcall isearch-filter-predicate
3292 (match-beginning 0) (match-end 0)))
3293 (setq retry nil)))
3294 success)
3295 (error nil)))
3297 (defun isearch-lazy-highlight-start ()
3298 "Start a new lazy-highlight updating loop."
3299 (lazy-highlight-cleanup t) ;remove old overlays
3300 (isearch-lazy-highlight-update))
3302 (defun isearch-lazy-highlight-update ()
3303 "Update highlighting of other matches for current search."
3304 (let ((max lazy-highlight-max-at-a-time)
3305 (looping t)
3306 nomore)
3307 (with-local-quit
3308 (save-selected-window
3309 (if (and (window-live-p isearch-lazy-highlight-window)
3310 (not (memq (selected-window) isearch-lazy-highlight-window-group)))
3311 (select-window isearch-lazy-highlight-window))
3312 (save-excursion
3313 (save-match-data
3314 (goto-char (if isearch-lazy-highlight-forward
3315 isearch-lazy-highlight-end
3316 isearch-lazy-highlight-start))
3317 (while looping
3318 (let ((found (isearch-lazy-highlight-search)))
3319 (when max
3320 (setq max (1- max))
3321 (if (<= max 0)
3322 (setq looping nil)))
3323 (if found
3324 (let ((mb (match-beginning 0))
3325 (me (match-end 0)))
3326 (if (= mb me) ;zero-length match
3327 (if isearch-lazy-highlight-forward
3328 (if (= mb (if isearch-lazy-highlight-wrapped
3329 isearch-lazy-highlight-start
3330 (window-group-end)))
3331 (setq found nil)
3332 (forward-char 1))
3333 (if (= mb (if isearch-lazy-highlight-wrapped
3334 isearch-lazy-highlight-end
3335 (window-group-start)))
3336 (setq found nil)
3337 (forward-char -1)))
3339 ;; non-zero-length match
3340 (let ((ov (make-overlay mb me)))
3341 (push ov isearch-lazy-highlight-overlays)
3342 ;; 1000 is higher than ediff's 100+,
3343 ;; but lower than isearch main overlay's 1001
3344 (overlay-put ov 'priority 1000)
3345 (overlay-put ov 'face 'lazy-highlight)
3346 (unless (eq isearch-lazy-highlight 'all-windows)
3347 (overlay-put ov 'window (selected-window)))))
3348 ;; Remember the current position of point for
3349 ;; the next call of `isearch-lazy-highlight-update'
3350 ;; when `lazy-highlight-max-at-a-time' is too small.
3351 (if isearch-lazy-highlight-forward
3352 (setq isearch-lazy-highlight-end (point))
3353 (setq isearch-lazy-highlight-start (point)))))
3355 ;; not found or zero-length match at the search bound
3356 (if (not found)
3357 (if isearch-lazy-highlight-wrapped
3358 (setq looping nil
3359 nomore t)
3360 (setq isearch-lazy-highlight-wrapped t)
3361 (if isearch-lazy-highlight-forward
3362 (progn
3363 (setq isearch-lazy-highlight-end (window-group-start))
3364 (goto-char (max (or isearch-lazy-highlight-start-limit (point-min))
3365 (window-group-start))))
3366 (setq isearch-lazy-highlight-start (window-group-end))
3367 (goto-char (min (or isearch-lazy-highlight-end-limit (point-max))
3368 (window-group-end))))))))
3369 (unless nomore
3370 (setq isearch-lazy-highlight-timer
3371 (run-at-time lazy-highlight-interval nil
3372 'isearch-lazy-highlight-update)))))))))
3374 (defun isearch-resume (string regexp word forward message case-fold)
3375 "Resume an incremental search.
3376 STRING is the string or regexp searched for.
3377 REGEXP non-nil means the resumed search was a regexp search.
3378 WORD non-nil means resume a word search.
3379 FORWARD non-nil means resume a forward search.
3380 MESSAGE is the echo-area message recorded for the search resumed.
3381 CASE-FOLD non-nil means the search was case-insensitive."
3382 (isearch-mode forward regexp nil nil word)
3383 (setq isearch-string string
3384 isearch-message message
3385 isearch-case-fold-search case-fold)
3386 (isearch-search)
3387 (isearch-update))
3389 (provide 'isearch)
3391 ;;; isearch.el ends here