428
+ − 1 ;;; isearch-mode.el --- Incremental search minor mode.
+ − 2
+ − 3 ;; Copyright (C) 1992,93,94,95,96,97,98,1999 Free Software Foundation, Inc.
+ − 4
+ − 5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
+ − 6 ;; Maintainer: XEmacs Development Team
+ − 7 ;; Keywords: extensions, dumped
+ − 8
+ − 9 ;; This file is part of XEmacs.
+ − 10
+ − 11 ;; XEmacs is free software; you can redistribute it and/or modify it
+ − 12 ;; under the terms of the GNU General Public License as published by
+ − 13 ;; the Free Software Foundation; either version 2, or (at your option)
+ − 14 ;; any later version.
+ − 15
+ − 16 ;; XEmacs is distributed in the hope that it will be useful, but
+ − 17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ − 19 ;; General Public License for more details.
+ − 20
+ − 21 ;; You should have received a copy of the GNU General Public License
+ − 22 ;; along with XEmacs; see the file COPYING. If not, write to the
+ − 23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
+ − 24 ;; Boston, MA 02111-1307, USA.
+ − 25
+ − 26 ;;; Synched up with: FSF 20.4.
+ − 27
+ − 28 ;;; Commentary:
+ − 29
+ − 30 ;; Instructions
+ − 31
+ − 32 ;; Searching with isearch-mode.el should work just like isearch.el
+ − 33 ;; [the one from Emacs 18], except it is done in a temporary minor
+ − 34 ;; mode that terminates when you finish searching.
+ − 35
+ − 36 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
+ − 37 ;; isearch-mode behaves modally and does not return until the search
+ − 38 ;; is completed. It uses a recursive-edit to behave this way. In
+ − 39 ;; that case, you should still be able switch buffers, so be careful
+ − 40 ;; not to get things confused.
+ − 41
+ − 42 ;; The key bindings active within isearch-mode are defined below in
+ − 43 ;; `isearch-mode-map' which is given bindings close to the default
+ − 44 ;; characters of the original isearch.el. With `isearch-mode',
+ − 45 ;; however, you can bind multi-character keys and it should be easier
+ − 46 ;; to add new commands. One bug though: keys with meta-prefix cannot
+ − 47 ;; be longer than two chars. Also see minibuffer-local-isearch-map
+ − 48 ;; for bindings active during `isearch-edit-string'.
+ − 49
+ − 50 ;; The search ring and completion commands automatically put you in
+ − 51 ;; the minibuffer to edit the string. This gives you a chance to
+ − 52 ;; modify the search string before executing the search. There are
+ − 53 ;; three commands to terminate the editing: C-s and C-r exit the
+ − 54 ;; minibuffer and search forward and reverse respectively, while C-m
+ − 55 ;; exits and does a nonincremental search.
+ − 56
+ − 57 ;; Exiting immediately from isearch uses isearch-edit-string instead
+ − 58 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
+ − 59 ;; The name of this option should probably be changed if we decide to
+ − 60 ;; keep the behavior. No point in forcing nonincremental search until
+ − 61 ;; the last possible moment.
+ − 62
+ − 63 ;; TODO
+ − 64 ;; - Integrate generalized command history to isearch-edit-string.
+ − 65 ;; - Think about incorporating query-replace.
+ − 66 ;; - Hooks and options for failed search.
+ − 67
+ − 68 ;;; Change Log:
+ − 69
+ − 70 ;; Changes before those recorded in ChangeLog:
+ − 71
+ − 72 ;; 20-aug-92 Hacked by jwz for Lucid Emacs 19.3.
+ − 73 ;;
+ − 74 ;; Revision 1.3 92/06/29 13:10:08 liberte
+ − 75 ;; Moved modal isearch-mode handling into isearch-mode.
+ − 76 ;; Got rid of buffer-local isearch variables.
+ − 77 ;; isearch-edit-string used by ring adjustments, completion, and
+ − 78 ;; nonincremental searching. C-s and C-r are additional exit commands.
+ − 79 ;; Renamed all regex to regexp.
+ − 80 ;; Got rid of found-start and found-point globals.
+ − 81 ;; Generalized handling of upper-case chars.
+ − 82
+ − 83 ;; Revision 1.2 92/05/27 11:33:57 liberte
+ − 84 ;; Emacs version 19 has a search ring, which is supported here.
+ − 85 ;; Other fixes found in the version 19 isearch are included here.
+ − 86 ;;
+ − 87 ;; Also see variables search-caps-disable-folding,
+ − 88 ;; search-nonincremental-instead, search-whitespace-regexp, and
+ − 89 ;; commands isearch-toggle-regexp, isearch-edit-string.
+ − 90 ;;
+ − 91 ;; semi-modal isearching is supported.
+ − 92
+ − 93 ;; Changes for 1.1
+ − 94 ;; 3/18/92 Fixed invalid-regexp.
+ − 95 ;; 3/18/92 Fixed yanking in regexps.
+ − 96
+ − 97 ;;; Code:
+ − 98
+ − 99
+ − 100 ;;;=========================================================================
+ − 101 ;;; User-accessible variables
+ − 102
+ − 103 (defgroup isearch nil
+ − 104 "Incremental search minor mode."
+ − 105 :prefix "search-"
+ − 106 :group 'matching)
+ − 107
+ − 108
+ − 109 (defcustom search-exit-option t
+ − 110 "*Non-nil means random control characters terminate incremental search."
+ − 111 :type 'boolean
+ − 112 :group 'isearch)
+ − 113
+ − 114 (defcustom search-slow-window-lines 1
+ − 115 "*Number of lines in slow search display windows.
+ − 116 These are the short windows used during incremental search on slow terminals.
+ − 117 Negative means put the slow search window at the top (normally it's at bottom)
+ − 118 and the value is minus the number of lines."
+ − 119 :type 'integer
+ − 120 :group 'isearch)
+ − 121
+ − 122 (defcustom search-slow-speed 1200
+ − 123 "*Highest terminal speed at which to use \"slow\" style incremental search.
+ − 124 This is the style where a one-line window is created to show the line
+ − 125 that the search has reached."
+ − 126 :type 'integer
+ − 127 :group 'isearch)
+ − 128
+ − 129 ;; We have `search-caps-disable-folding'.
+ − 130 ;(defcustom search-upper-case 'not-yanks
+ − 131 ; "*If non-nil, upper case chars disable case fold searching.
+ − 132 ;That is, upper and lower case chars must match exactly.
+ − 133 ;This applies no matter where the chars come from, but does not
+ − 134 ;apply to chars in regexps that are prefixed with `\\'.
+ − 135 ;If this value is `not-yanks', yanked text is always downcased."
+ − 136 ; :type '(choice (const :tag "off" nil)
+ − 137 ; (const not-yanks)
+ − 138 ; (other :tag "on" t))
+ − 139 ; :group 'isearch)
+ − 140
+ − 141 (defcustom search-nonincremental-instead t
+ − 142 "*If non-nil, do a nonincremental search instead if exiting immediately.
+ − 143 Actually, `isearch-edit-string' is called to let you enter the search
+ − 144 string, and RET terminates editing and does a nonincremental search."
+ − 145 :type 'boolean
+ − 146 :group 'isearch)
+ − 147
+ − 148 ;; FSF default is "\\s-+", but I think our default is better so I'm
+ − 149 ;; leaving it.
+ − 150 (defcustom search-whitespace-regexp "\\(\\s-\\|[\n\r]\\)+"
+ − 151 "*If non-nil, regular expression to match a sequence of whitespace chars."
+ − 152 :type 'regexp
+ − 153 :group 'isearch)
+ − 154
+ − 155 (defcustom search-highlight t
+ − 156 "*Whether incremental search and query-replace should highlight
+ − 157 the text that currently matches the search string."
+ − 158 :type 'boolean
+ − 159 :group 'isearch)
+ − 160
+ − 161 ;; I think the name `search-highlight' makes more sense, both because
+ − 162 ;; of consistency with other search-* variables above, and because it
+ − 163 ;; also applies to query-replace.
+ − 164 (define-obsolete-variable-alias 'isearch-highlight 'search-highlight)
+ − 165
+ − 166 (defcustom search-invisible 'open
+ − 167 "If t incremental search can match hidden text.
+ − 168 nil means don't match invisible text.
+ − 169 If the value is `open', if the text matched is made invisible by
+ − 170 an overlay having an `invisible' property and that overlay has a property
+ − 171 `isearch-open-invisible', then incremental search will show the contents.
+ − 172 \(This applies when using `outline.el' and `hideshow.el'.)"
+ − 173 :type '(choice (const :tag "Match hidden text" t)
+ − 174 (const :tag "Open overlays" open)
+ − 175 (const :tag "Don't match hidden text" nil))
+ − 176 :group 'isearch)
+ − 177
+ − 178 (defcustom isearch-hide-immediately t
+ − 179 "If non-nil, re-hide an invisible match right away.
+ − 180 This variable makes a difference when `search-invisible' is set to `open'.
+ − 181 It means that after search makes some invisible text visible
+ − 182 to show the match, it makes the text invisible again when the match moves.
444
+ − 183 Ordinarily the text becomes invisible again at the end of the search."
+ − 184 :type 'boolean
428
+ − 185 :group 'isearch)
+ − 186
+ − 187 (defvar isearch-mode-hook nil
+ − 188 "Function(s) to call after starting up an incremental search.")
+ − 189
+ − 190 (defvar isearch-mode-end-hook nil
+ − 191 "Function(s) to call after terminating an incremental search.")
+ − 192
+ − 193 ;;;==================================================================
+ − 194 ;;; Search ring.
+ − 195
+ − 196 (defvar search-ring nil
+ − 197 "List of search string sequences.")
+ − 198 (defvar regexp-search-ring nil
+ − 199 "List of regular expression search string sequences.")
+ − 200
+ − 201 (defcustom search-ring-max 16
+ − 202 "*Maximum length of search ring before oldest elements are thrown away."
+ − 203 :type 'integer
+ − 204 :group 'isearch)
+ − 205 (defcustom regexp-search-ring-max 16
+ − 206 "*Maximum length of regexp search ring before oldest elements are thrown away."
+ − 207 :type 'integer
+ − 208 :group 'isearch)
+ − 209
+ − 210 ;; The important difference between pre-20.4-merge yank-pointers and
+ − 211 ;; current code is that the yank pointers positions used to be
+ − 212 ;; preserved across the isearch sessions. I changed this because I
+ − 213 ;; think the FSF code is closer to how the feature is supposed to
+ − 214 ;; behave (read: to minibuffer histories.)
+ − 215 (defvar search-ring-yank-pointer nil
+ − 216 "Index in `search-ring' of last string reused.
+ − 217 nil if none yet.")
+ − 218 (defvar regexp-search-ring-yank-pointer nil
+ − 219 "Index in `regexp-search-ring' of last string reused.
+ − 220 nil if none yet.")
+ − 221
+ − 222 (defcustom search-ring-update nil
+ − 223 "*Non-nil if advancing or retreating in the search ring should cause search.
+ − 224 Default nil means edit the string from the search ring first."
+ − 225 :type 'boolean
+ − 226 :group 'isearch)
+ − 227
710
+ − 228 (defcustom isearch-mode-line-string " Isearch"
+ − 229 "*String to display in the modeline when `isearch-mode' is active.
+ − 230 Set this to nil if you don't want a modeline indicator."
+ − 231 :type '(choice string
+ − 232 (const :tag "none" nil))
+ − 233 :group 'isearch)
+ − 234
428
+ − 235 ;;;====================================================
+ − 236 ;;; Define isearch-mode keymap.
+ − 237
+ − 238 (defvar isearch-mode-map
+ − 239 (let ((map (make-keymap)))
+ − 240 (set-keymap-name map 'isearch-mode-map)
+ − 241
+ − 242 ;; Bind all printing characters to `isearch-printing-char'.
+ − 243 ;; This isn't normally necessary, but if a printing character were
+ − 244 ;; bound to something other than self-insert-command in global-map,
+ − 245 ;; then it would terminate the search and be executed without this.
+ − 246 (let ((i 32)
+ − 247 (str (make-string 1 0)))
+ − 248 (while (< i 127)
+ − 249 (aset str 0 i)
+ − 250 (define-key map str 'isearch-printing-char)
+ − 251 (setq i (1+ i))))
+ − 252
+ − 253 ;; Here FSF sets up various kludges to handle local bindings with
+ − 254 ;; meta char prefix keys. We don't need isearch-other-meta-char
+ − 255 ;; because we handle things differently (via pre-command-hook).
+ − 256
+ − 257 ;; Several non-printing chars change the searching behavior.
+ − 258 ;;
+ − 259 (define-key map "\C-s" 'isearch-repeat-forward)
+ − 260 (define-key map "\M-\C-s" 'isearch-repeat-forward)
+ − 261 (define-key map "\C-r" 'isearch-repeat-backward)
+ − 262 (define-key map "\C-g" 'isearch-abort)
+ − 263
771
+ − 264 (define-key map [(meta escape)] 'isearch-cancel)
428
+ − 265
+ − 266 (define-key map "\C-q" 'isearch-quote-char)
+ − 267
+ − 268 (define-key map "\C-m" 'isearch-exit)
+ − 269 (define-key map "\C-j" 'isearch-printing-char)
+ − 270 (define-key map "\t" 'isearch-printing-char)
+ − 271 ;; I prefer our default.
+ − 272 ;(define-key map " " 'isearch-whitespace-chars)
+ − 273 (define-key map "\M- " 'isearch-whitespace-chars)
+ − 274
+ − 275 (define-key map "\C-w" 'isearch-yank-word)
+ − 276 (define-key map "\C-y" 'isearch-yank-line)
+ − 277 (define-key map "\M-y" 'isearch-yank-kill)
+ − 278
+ − 279 ;; Define keys for regexp chars * ? |.
+ − 280 ;; Nothing special for + because it matches at least once.
+ − 281 (define-key map "*" 'isearch-*-char)
+ − 282 (define-key map "?" 'isearch-*-char)
+ − 283 (define-key map "|" 'isearch-|-char)
+ − 284
+ − 285 ;; delete and backspace delete backward, f1 is help, and C-h can be either
+ − 286 (define-key map 'delete 'isearch-delete-char)
+ − 287 (define-key map 'backspace 'isearch-delete-char)
+ − 288 (define-key map '(control h) 'isearch-help-or-delete-char)
+ − 289 (define-key map 'f1 'isearch-mode-help)
+ − 290 (define-key map 'help 'isearch-mode-help)
+ − 291
+ − 292 (define-key map "\M-n" 'isearch-ring-advance)
+ − 293 (define-key map "\M-p" 'isearch-ring-retreat)
+ − 294 (define-key map "\M-\t" 'isearch-complete)
+ − 295
+ − 296 ;; I find this binding somewhat unintuitive, because it doesn't
+ − 297 ;; work if the mouse pointer is over the echo area -- it has to be
+ − 298 ;; over the search window.
+ − 299 (define-key map 'button2 'isearch-yank-selection)
+ − 300
+ − 301 map)
+ − 302 "Keymap for isearch-mode.")
+ − 303
+ − 304 ;; Some bindings you may want to put in your isearch-mode-hook.
+ − 305 ;; Suggest some alternates...
+ − 306 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-case-fold)
+ − 307 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
+ − 308 ;; (define-key isearch-mode-map "\C-^" 'isearch-edit-string)
+ − 309
+ − 310 (defvar minibuffer-local-isearch-map
+ − 311 (let ((map (make-sparse-keymap)))
+ − 312 ;; #### - this should also be minor-mode-ified
+ − 313 (set-keymap-parents map (list minibuffer-local-map))
+ − 314 (set-keymap-name map 'minibuffer-local-isearch-map)
+ − 315
+ − 316 ;;#### This should just arrange to use the usual Emacs minibuffer histories
+ − 317 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
+ − 318 (define-key map "\M-n" 'isearch-ring-advance-edit)
+ − 319 (define-key map "\M-p" 'isearch-ring-retreat-edit)
+ − 320 (define-key map 'down 'isearch-ring-advance-edit)
+ − 321 (define-key map 'up 'isearch-ring-retreat-edit)
+ − 322 (define-key map "\M-\t" 'isearch-complete-edit)
+ − 323 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
+ − 324 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
+ − 325 map)
+ − 326 "Keymap for editing isearch strings in the minibuffer.")
+ − 327
+ − 328 ;;;========================================================
+ − 329 ;; Internal variables declared globally for byte-compiler.
+ − 330 ;; These are all set with setq while isearching
+ − 331 ;; and bound locally while editing the search string.
+ − 332
+ − 333 (defvar isearch-forward nil) ; Searching in the forward direction.
+ − 334 (defvar isearch-regexp nil) ; Searching for a regexp.
+ − 335 (defvar isearch-word nil) ; Searching for words.
+ − 336
+ − 337 (defvar isearch-cmds nil) ; Stack of search status sets.
+ − 338 (defvar isearch-string "") ; The current search string.
+ − 339 (defvar isearch-message "") ; text-char-description version of isearch-string
+ − 340
+ − 341 (defvar isearch-success t) ; Searching is currently successful.
+ − 342 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
+ − 343 (defvar isearch-within-brackets nil) ; Regexp has unclosed [.
+ − 344 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
+ − 345 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
+ − 346 (defvar isearch-barrier 0)
+ − 347 (defvar isearch-just-started nil)
+ − 348 (defvar isearch-buffer nil) ; the buffer we've frobbed the keymap of
+ − 349
+ − 350 (defvar isearch-case-fold-search nil)
+ − 351
+ − 352 ;; Need this for toggling case in isearch-toggle-case-fold. When this
+ − 353 ;; is non-nil, the case-sensitiveness of the search is set by the
+ − 354 ;; user, and is may no longer be dynamically changed as per
+ − 355 ;; search-caps-disable-folding.
+ − 356 (defvar isearch-fixed-case nil)
+ − 357
+ − 358 (defvar isearch-adjusted nil)
+ − 359 (defvar isearch-slow-terminal-mode nil)
+ − 360 ;;; If t, using a small window.
+ − 361 (defvar isearch-small-window nil)
+ − 362 (defvar isearch-opoint 0)
+ − 363 ;;; The window configuration active at the beginning of the search.
+ − 364 (defvar isearch-window-configuration nil)
+ − 365 (defvar isearch-selected-frame nil)
+ − 366
+ − 367 ;; Flag to indicate a yank occurred, so don't move the cursor.
+ − 368 (defvar isearch-yank-flag nil)
+ − 369
+ − 370 ;;; A function to be called after each input character is processed.
+ − 371 ;;; (It is not called after characters that exit the search.)
+ − 372 ;;; It is only set from an optional argument to `isearch-mode'.
+ − 373 (defvar isearch-op-fun nil)
+ − 374
+ − 375 ;;; Is isearch-mode in a recursive edit for modal searching.
+ − 376 (defvar isearch-recursive-edit nil)
+ − 377
+ − 378 ;;; Should isearch be terminated after doing one search?
+ − 379 (defvar isearch-nonincremental nil)
+ − 380
+ − 381 ;; New value of isearch-forward after isearch-edit-string.
+ − 382 (defvar isearch-new-forward nil)
+ − 383
+ − 384 ;; Accumulate here the extents unhidden during searching.
+ − 385 (defvar isearch-unhidden-extents nil) ; in FSF: isearch-opened-overlays
+ − 386
+ − 387
+ − 388 ;;;==============================================================
+ − 389 ;; Minor-mode-alist changes - kind of redundant with the
+ − 390 ;; echo area, but if isearching in multiple windows, it can be useful.
+ − 391
710
+ − 392 (add-minor-mode 'isearch-mode 'isearch-mode-line-string)
428
+ − 393
+ − 394 (defvar isearch-mode nil) ;; Name of the minor mode, if non-nil.
+ − 395 (make-variable-buffer-local 'isearch-mode)
+ − 396
+ − 397 ;; We bind these in keydefs.el.
+ − 398 ;(define-key global-map "\C-s" 'isearch-forward)
+ − 399 ;(define-key global-map "\C-r" 'isearch-backward)
+ − 400 ;(define-key global-map "\M-\C-s" 'isearch-forward-regexp)
+ − 401 ;(define-key global-map "\M-\C-r" 'isearch-backward-regexp)
+ − 402
+ − 403 ;;;===============================================================
+ − 404 ;;; Entry points to isearch-mode.
+ − 405 ;;; These four functions should replace those in loaddefs.el
+ − 406 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
+ − 407 ;;; and look at this-command to set the options accordingly.
+ − 408
+ − 409 (defun isearch-forward (&optional regexp-p no-recursive-edit)
+ − 410 "\
+ − 411 Do incremental search forward.
+ − 412 With a prefix argument, do an incremental regular expression search instead.
+ − 413 \\<isearch-mode-map>
+ − 414 As you type characters, they add to the search string and are found.
+ − 415 The following non-printing keys are bound in `isearch-mode-map'.
+ − 416
+ − 417 Type \\[isearch-delete-char] to cancel characters from end of search string.
+ − 418 Type \\[isearch-exit] to exit, leaving point at location found.
+ − 419 Type LFD (C-j) to match end of line.
+ − 420 Type \\[isearch-repeat-forward] to search again forward,\
+ − 421 \\[isearch-repeat-backward] to search again backward.
+ − 422 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
+ − 423 string and search for it.
+ − 424 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
+ − 425 and search for it.
+ − 426 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\
+ − 427 and search for it.
+ − 428 Type \\[isearch-quote-char] to quote control character to search for it.
+ − 429 Type \\[isearch-whitespace-chars] to match all whitespace chars in regexp.
+ − 430 \\[isearch-abort] while searching or when search has failed cancels input\
+ − 431 back to what has
+ − 432 been found successfully.
+ − 433 \\[isearch-abort] when search is successful aborts and moves point to\
+ − 434 starting point.
+ − 435
+ − 436 Also supported is a search ring of the previous 16 search strings.
+ − 437 Type \\[isearch-ring-advance] to search for the next item in the search ring.
+ − 438 Type \\[isearch-ring-retreat] to search for the previous item in the search\
+ − 439 ring.
+ − 440 Type \\[isearch-complete] to complete the search string using the search ring.
+ − 441
+ − 442 The above keys are bound in the isearch-mode-map. To change the keys which
+ − 443 are special to isearch-mode, simply change the bindings in that map.
+ − 444
+ − 445 Other control and meta characters terminate the search
+ − 446 and are then executed normally (depending on `search-exit-option').
+ − 447
+ − 448 If this function is called non-interactively, it does not return to
+ − 449 the calling function until the search is done.
+ − 450
+ − 451 The bindings, more precisely:
+ − 452 \\{isearch-mode-map}"
+ − 453
+ − 454 ;; Non-standard bindings
+ − 455 ;; Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
+ − 456 ;; Type \\[isearch-edit-string] to edit the search string in the minibuffer.
+ − 457 ;; Terminate editing and return to incremental searching with CR.
+ − 458
+ − 459 (interactive "_P\np")
+ − 460 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
+ − 461
+ − 462 (defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
+ − 463 "\
+ − 464 Do incremental search forward for regular expression.
+ − 465 With a prefix argument, do a regular string search instead.
+ − 466 Like ordinary incremental search except that your input
+ − 467 is treated as a regexp. See \\[isearch-forward] for more info."
+ − 468 (interactive "_P\np")
+ − 469 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
+ − 470
+ − 471 (defun isearch-backward (&optional regexp-p no-recursive-edit)
+ − 472 "\
+ − 473 Do incremental search backward.
+ − 474 With a prefix argument, do a regular expression search instead.
+ − 475 See \\[isearch-forward] for more information."
+ − 476 (interactive "_P\np")
+ − 477 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
+ − 478
+ − 479 (defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
+ − 480 "\
+ − 481 Do incremental search backward for regular expression.
+ − 482 With a prefix argument, do a regular string search instead.
+ − 483 Like ordinary incremental search except that your input
+ − 484 is treated as a regexp. See \\[isearch-forward] for more info."
+ − 485 (interactive "_P\np")
+ − 486 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
+ − 487
+ − 488 ;; The problem here is that you can't scroll the help screen; as soon
+ − 489 ;; as you press a key, it's gone. I don't know of a good way to fix
+ − 490 ;; it, though. -hniksic
+ − 491 (defun isearch-mode-help ()
+ − 492 (interactive "_")
+ − 493 (let ((w (selected-window)))
+ − 494 (describe-function 'isearch-forward)
+ − 495 (select-window w))
+ − 496 (isearch-update))
+ − 497
+ − 498
+ − 499 ;;;==================================================================
+ − 500 ;; isearch-mode only sets up incremental search for the minor mode.
+ − 501 ;; All the work is done by the isearch-mode commands.
+ − 502
+ − 503 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
+ − 504 "Start isearch minor mode. Called by `isearch-forward', etc.
+ − 505
+ − 506 \\{isearch-mode-map}"
+ − 507
+ − 508 (if executing-kbd-macro (setq recursive-edit nil))
+ − 509
+ − 510 (let ((inhibit-quit t)) ; don't leave things in an inconsistent state...
+ − 511
+ − 512 ;; Initialize global vars.
+ − 513 (setq isearch-buffer (current-buffer)
+ − 514 isearch-forward forward
+ − 515 isearch-regexp regexp
+ − 516 isearch-word word-p
+ − 517 isearch-op-fun op-fun
+ − 518 isearch-case-fold-search case-fold-search
+ − 519 isearch-fixed-case nil
+ − 520 isearch-string ""
+ − 521 isearch-message ""
+ − 522 isearch-cmds nil
+ − 523 isearch-success t
+ − 524 isearch-wrapped nil
+ − 525 isearch-barrier (point)
+ − 526 isearch-adjusted nil
+ − 527 isearch-yank-flag nil
+ − 528 isearch-invalid-regexp nil
+ − 529 isearch-within-brackets nil
+ − 530 isearch-slow-terminal-mode (and (<= (device-baud-rate)
+ − 531 search-slow-speed)
+ − 532 (> (window-height)
+ − 533 (* 4 search-slow-window-lines)))
+ − 534 isearch-other-end nil
+ − 535 isearch-small-window nil
+ − 536 isearch-just-started t
+ − 537
+ − 538 isearch-opoint (point)
+ − 539 search-ring-yank-pointer nil
+ − 540 regexp-search-ring-yank-pointer nil
440
+ − 541 isearch-unhidden-extents nil
428
+ − 542 isearch-window-configuration (current-window-configuration)
+ − 543
+ − 544 ;; #### What we really need is a buffer-local
+ − 545 ;; overriding-local-map. See isearch-pre-command-hook for
+ − 546 ;; more details.
+ − 547 overriding-local-map (progn
+ − 548 (set-keymap-parents isearch-mode-map
+ − 549 (nconc (current-minor-mode-maps)
+ − 550 (and (current-local-map)
+ − 551 (list (current-local-map)))))
+ − 552 isearch-mode-map)
+ − 553 isearch-selected-frame (selected-frame)
+ − 554
+ − 555 )
+ − 556
+ − 557 ;; XEmacs change: without clearing the match data, sometimes old values
+ − 558 ;; of isearch-other-end get used. Don't ask me why...
+ − 559 (store-match-data nil)
+ − 560
+ − 561 (add-hook 'pre-command-hook 'isearch-pre-command-hook)
+ − 562
+ − 563 (setq isearch-mode (gettext " Isearch"))
+ − 564 (redraw-modeline)
+ − 565
+ − 566 (isearch-push-state)
+ − 567
+ − 568 ) ; inhibit-quit is t before here
+ − 569
+ − 570 (isearch-update)
+ − 571 (run-hooks 'isearch-mode-hook)
+ − 572
+ − 573 ;; isearch-mode can be made modal (in the sense of not returning to
+ − 574 ;; the calling function until searching is completed) by entering
+ − 575 ;; a recursive-edit and exiting it when done isearching.
+ − 576 (if recursive-edit
+ − 577 (let ((isearch-recursive-edit t))
+ − 578 (recursive-edit)))
+ − 579 isearch-success)
+ − 580
+ − 581
+ − 582 ;;;====================================================
+ − 583 ;; Some high level utilities. Others below.
+ − 584
+ − 585 (defun isearch-update ()
+ − 586 ;; Called after each command to update the display.
+ − 587 (if (null unread-command-events)
+ − 588 (progn
+ − 589 (if (not (input-pending-p))
+ − 590 (isearch-message))
+ − 591 (if (and isearch-slow-terminal-mode
+ − 592 (not (or isearch-small-window
+ − 593 (pos-visible-in-window-p))))
+ − 594 (let ((found-point (point)))
+ − 595 (setq isearch-small-window t)
+ − 596 (move-to-window-line 0)
+ − 597 (let ((window-min-height 1))
+ − 598 (split-window nil (if (< search-slow-window-lines 0)
+ − 599 (1+ (- search-slow-window-lines))
+ − 600 (- (window-height)
+ − 601 (1+ search-slow-window-lines)))))
+ − 602 (if (< search-slow-window-lines 0)
+ − 603 (progn (vertical-motion (- 1 search-slow-window-lines))
+ − 604 (set-window-start (next-window) (point))
+ − 605 (set-window-hscroll (next-window)
+ − 606 (window-hscroll))
+ − 607 (set-window-hscroll (selected-window) 0))
+ − 608 (other-window 1))
+ − 609 (goto-char found-point)))
+ − 610 (if isearch-other-end
+ − 611 (if (< isearch-other-end (point))
+ − 612 (isearch-highlight isearch-other-end (point))
+ − 613 (isearch-highlight (point) isearch-other-end))
+ − 614 (isearch-dehighlight))
+ − 615 ))
+ − 616 (setq ;; quit-flag nil not for isearch-mode
+ − 617 isearch-adjusted nil
+ − 618 isearch-yank-flag nil)
+ − 619 (isearch-highlight-all-update)
+ − 620 )
+ − 621
+ − 622
+ − 623 (defun isearch-done (&optional nopush edit)
+ − 624 ;; Called by all commands that terminate isearch-mode.
+ − 625 (let ((inhibit-quit t)) ; danger danger!
+ − 626 (if (and isearch-buffer (buffer-live-p isearch-buffer))
+ − 627 ;; Some loser process filter might have switched the window's
+ − 628 ;; buffer, so be sure to set these variables back in the
+ − 629 ;; buffer we frobbed them in. But only if the buffer is still
+ − 630 ;; alive.
+ − 631 (with-current-buffer isearch-buffer
+ − 632 (setq overriding-local-map nil)
+ − 633 ;; Use remove-hook instead of just setting it to our saved value
+ − 634 ;; in case some process filter has created a buffer and modified
+ − 635 ;; the pre-command-hook in that buffer... yeah, this is obscure,
+ − 636 ;; and yeah, I was getting screwed by it. -jwz
+ − 637 (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
+ − 638 (set-keymap-parents isearch-mode-map nil)
+ − 639 (setq isearch-mode nil)
+ − 640 (redraw-modeline)
+ − 641 (isearch-dehighlight)
+ − 642 (isearch-highlight-all-cleanup)
+ − 643 (isearch-restore-invisible-extents nil nil)
+ − 644 ))
+ − 645
+ − 646 ;; it's not critical that this be inside inhibit-quit, but leaving
+ − 647 ;; things in small-window-mode would be bad.
+ − 648 (let ((found-start (window-start (selected-window)))
+ − 649 (found-point (point)))
+ − 650 (cond ((eq (selected-frame) isearch-selected-frame)
+ − 651 (set-window-configuration isearch-window-configuration)
+ − 652
+ − 653 (if isearch-small-window
+ − 654 (goto-char found-point)
+ − 655 ;; Exiting the save-window-excursion clobbers
+ − 656 ;; window-start; restore it.
+ − 657 (set-window-start (selected-window) found-start t))))
+ − 658 ;; If there was movement, mark the starting position.
+ − 659 ;; Maybe should test difference between and set mark iff > threshold.
+ − 660 (if (and (buffer-live-p isearch-buffer)
+ − 661 (/= (point isearch-buffer) isearch-opoint))
+ − 662 ;; #### FSF doesn't do this if the region is active. Should
+ − 663 ;; we do the same?
+ − 664 (progn
+ − 665 (push-mark isearch-opoint t nil isearch-buffer)
+ − 666 (or executing-kbd-macro (> (minibuffer-depth) 0)
+ − 667 (display-message 'command "Mark saved where search started")))))
+ − 668 (setq isearch-buffer nil)
+ − 669 ) ; inhibit-quit is t before here
+ − 670
+ − 671 (if (and (> (length isearch-string) 0) (not nopush))
+ − 672 ;; Update the ring data.
+ − 673 (isearch-update-ring isearch-string isearch-regexp))
+ − 674
+ − 675 (run-hooks 'isearch-mode-end-hook)
+ − 676
+ − 677 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
+ − 678
+ − 679 (defun isearch-update-ring (string &optional regexp)
+ − 680 "Add STRING to the beginning of the search ring.
+ − 681 REGEXP says which ring to use."
444
+ − 682 (if regexp
428
+ − 683 (if (or (null regexp-search-ring)
+ − 684 (not (string= string (car regexp-search-ring))))
+ − 685 (progn
+ − 686 (setq regexp-search-ring
+ − 687 (cons string regexp-search-ring))
+ − 688 (if (> (length regexp-search-ring) regexp-search-ring-max)
+ − 689 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
+ − 690 nil))))
+ − 691 (if (or (null search-ring)
+ − 692 (not (string= string (car search-ring))))
+ − 693 (progn
+ − 694 (setq search-ring (cons string search-ring))
+ − 695 (if (> (length search-ring) search-ring-max)
+ − 696 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
+ − 697
+ − 698
+ − 699 ;;;====================================================
+ − 700 ;; Commands active while inside of the isearch minor mode.
+ − 701
+ − 702 (defun isearch-exit ()
+ − 703 "Exit search normally.
+ − 704 However, if this is the first command after starting incremental
+ − 705 search and `search-nonincremental-instead' is non-nil, do a
+ − 706 nonincremental search instead via `isearch-edit-string'."
+ − 707 (interactive)
+ − 708 (if (and search-nonincremental-instead
+ − 709 (= 0 (length isearch-string)))
+ − 710 (let ((isearch-nonincremental t)
+ − 711 ;; Highlighting only gets in the way of nonincremental
+ − 712 ;; search.
+ − 713 (search-highlight nil)
+ − 714 (isearch-highlight-all-matches nil))
+ − 715 (isearch-edit-string))
+ − 716 (isearch-done)))
+ − 717
+ − 718
+ − 719 (defun isearch-edit-string ()
+ − 720 "Edit the search string in the minibuffer.
+ − 721 The following additional command keys are active while editing.
+ − 722 \\<minibuffer-local-isearch-map>
+ − 723 \\[exit-minibuffer] to resume incremental searching with the edited string.
+ − 724 \\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
+ − 725 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
+ − 726 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
+ − 727 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
+ − 728 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
+ − 729 \\[isearch-complete-edit] to complete the search string using the search ring.
+ − 730 \\<isearch-mode-map>
+ − 731 If first char entered is \\[isearch-yank-word], then do word search instead."
+ − 732
+ − 733 ;; This code is very hairy for several reasons, explained in the code.
+ − 734 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
+ − 735 ;; If there were a way to catch any change of buffer from the minibuffer,
+ − 736 ;; this could be simplified greatly.
+ − 737 ;; Editing doesn't back up the search point. Should it?
+ − 738 (interactive)
+ − 739
+ − 740 (condition-case nil
+ − 741 (progn
+ − 742 (let ((isearch-nonincremental isearch-nonincremental)
+ − 743
+ − 744 ;; Locally bind all isearch global variables to protect them
+ − 745 ;; from recursive isearching.
+ − 746 ;; isearch-string -message and -forward are not bound
+ − 747 ;; so they may be changed. Instead, save the values.
+ − 748 (isearch-new-string isearch-string)
+ − 749 (isearch-new-message isearch-message)
+ − 750 (isearch-new-forward isearch-forward)
+ − 751 (isearch-new-word isearch-word)
+ − 752
+ − 753 (isearch-regexp isearch-regexp)
+ − 754 (isearch-op-fun isearch-op-fun)
+ − 755 (isearch-cmds isearch-cmds)
+ − 756 (isearch-success isearch-success)
+ − 757 (isearch-wrapped isearch-wrapped)
+ − 758 (isearch-barrier isearch-barrier)
+ − 759 (isearch-adjusted isearch-adjusted)
+ − 760 (isearch-fixed-case isearch-fixed-case)
+ − 761 (isearch-yank-flag isearch-yank-flag)
+ − 762 (isearch-invalid-regexp isearch-invalid-regexp)
+ − 763 (isearch-within-brackets isearch-within-brackets)
+ − 764 ;;; Don't bind this. We want isearch-search, below, to set it.
+ − 765 ;;; And the old value won't matter after that.
+ − 766 ;;; (isearch-other-end isearch-other-end)
+ − 767 (isearch-opoint isearch-opoint)
+ − 768 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
+ − 769 (isearch-small-window isearch-small-window)
+ − 770 (isearch-recursive-edit isearch-recursive-edit)
+ − 771 (isearch-window-configuration (current-window-configuration))
+ − 772 (isearch-selected-frame (selected-frame))
+ − 773 )
+ − 774 ;; Actually terminate isearching until editing is done.
+ − 775 ;; This is so that the user can do anything without failure,
+ − 776 ;; like switch buffers and start another isearch, and return.
+ − 777 ;; (condition-case nil
+ − 778 (isearch-done t t)
+ − 779 ;;#### What does this mean? There is no such condition!
+ − 780 ;; (exit nil)) ; was recursive editing
+ − 781
+ − 782 (unwind-protect
+ − 783 (progn
+ − 784 ;; Fake the prompt message for the sake of
+ − 785 ;; next-command-event below.
+ − 786 (isearch-message)
+ − 787 ;; If the first character the user types when we
+ − 788 ;; prompt them for a string is the yank-word
+ − 789 ;; character, then go into word-search mode.
+ − 790 ;; Otherwise unread that character and read a string
+ − 791 ;; the normal way.
+ − 792 (let* ((cursor-in-echo-area t)
+ − 793 (event (next-command-event)))
+ − 794 (if (eq 'isearch-yank-word
+ − 795 (lookup-key isearch-mode-map (vector event)))
+ − 796 (setq isearch-word t;; so message-prefix is right
+ − 797 isearch-new-word t)
+ − 798 (setq unread-command-event event)))
+ − 799 (setq isearch-new-string
+ − 800 (read-from-minibuffer
+ − 801 (isearch-message-prefix nil isearch-nonincremental)
+ − 802 isearch-string
+ − 803 minibuffer-local-isearch-map
+ − 804 nil
+ − 805 't ;does its own history (but shouldn't)
+ − 806 )
+ − 807 isearch-new-message (mapconcat
+ − 808 'isearch-text-char-description
+ − 809 isearch-new-string "")))
+ − 810 ;; Always resume isearching by restarting it.
+ − 811 (isearch-mode isearch-forward
+ − 812 isearch-regexp
+ − 813 isearch-op-fun
+ − 814 isearch-recursive-edit
+ − 815 isearch-word)
+ − 816
+ − 817 ;; Copy new values in outer locals to isearch globals
+ − 818 (setq isearch-string isearch-new-string
+ − 819 isearch-message isearch-new-message
+ − 820 isearch-forward isearch-new-forward
+ − 821 isearch-word isearch-new-word))
+ − 822
+ − 823 ;; Empty isearch-string means use default.
+ − 824 (if (= 0 (length isearch-string))
+ − 825 (setq isearch-string (or (car (if isearch-regexp
+ − 826 regexp-search-ring
+ − 827 search-ring))
+ − 828 ""))))
+ − 829
+ − 830 ;; Reinvoke the pending search.
+ − 831 (isearch-push-state)
+ − 832 (isearch-search)
+ − 833 (isearch-update)
+ − 834 (if isearch-nonincremental (isearch-done)))
+ − 835
+ − 836 (quit ; handle abort-recursive-edit
+ − 837 (isearch-abort) ;; outside of let to restore outside global values
+ − 838 )))
+ − 839
+ − 840 (defun isearch-nonincremental-exit-minibuffer ()
+ − 841 (interactive)
+ − 842 (setq isearch-nonincremental t)
+ − 843 (exit-minibuffer))
+ − 844
+ − 845 (defun isearch-forward-exit-minibuffer ()
+ − 846 (interactive)
+ − 847 (setq isearch-new-forward t)
+ − 848 (exit-minibuffer))
+ − 849
+ − 850 (defun isearch-reverse-exit-minibuffer ()
+ − 851 (interactive)
+ − 852 (setq isearch-new-forward nil)
+ − 853 (exit-minibuffer))
+ − 854
+ − 855 (defun isearch-cancel ()
+ − 856 "Terminate the search and go back to the starting point."
+ − 857 (interactive)
+ − 858 (goto-char isearch-opoint)
+ − 859 (isearch-done t)
+ − 860 (signal 'quit '(isearch))) ; and pass on quit signal
+ − 861
+ − 862 (defun isearch-abort ()
+ − 863 "Abort incremental search mode if searching is successful, signaling quit.
+ − 864 Otherwise, revert to previous successful search and continue searching.
+ − 865 Use `isearch-exit' to quit without signaling."
+ − 866 (interactive)
+ − 867 ;; (ding) signal instead below, if quitting
+ − 868 (discard-input)
+ − 869 (if isearch-success
+ − 870 ;; If search is successful, move back to starting point
+ − 871 ;; and really do quit.
+ − 872 (progn (goto-char isearch-opoint)
+ − 873 (setq isearch-success nil)
+ − 874 (isearch-done t) ; exit isearch
+ − 875 (signal 'quit '(isearch))) ; and pass on quit signal
+ − 876 ;; If search is failing, or has an incomplete regexp,
+ − 877 ;; rub out until it is once more successful.
+ − 878 (while (or (not isearch-success) isearch-invalid-regexp)
+ − 879 (isearch-pop-state))
+ − 880 (isearch-update)))
+ − 881
+ − 882 (defun isearch-repeat (direction)
+ − 883 ;; Utility for isearch-repeat-forward and -backward.
+ − 884 (if (eq isearch-forward (eq direction 'forward))
+ − 885 ;; C-s in forward or C-r in reverse.
+ − 886 (if (equal isearch-string "")
+ − 887 ;; If search string is empty, use last one.
+ − 888 (setq isearch-string
+ − 889 (or (if isearch-regexp
+ − 890 (car regexp-search-ring)
+ − 891 (car search-ring))
+ − 892 "")
+ − 893 isearch-message
+ − 894 (mapconcat 'isearch-text-char-description
+ − 895 isearch-string ""))
+ − 896 ;; If already have what to search for, repeat it.
+ − 897 (or isearch-success
+ − 898 (progn
+ − 899 (goto-char (if isearch-forward (point-min) (point-max)))
+ − 900 (setq isearch-wrapped t))))
+ − 901 ;; C-s in reverse or C-r in forward, change direction.
+ − 902 (setq isearch-forward (not isearch-forward)))
+ − 903
+ − 904 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
+ − 905
+ − 906 (if (equal isearch-string "")
+ − 907 (setq isearch-success t)
+ − 908 (if (and isearch-success (equal (match-end 0) (match-beginning 0))
+ − 909 (not isearch-just-started))
+ − 910 ;; If repeating a search that found
+ − 911 ;; an empty string, ensure we advance.
+ − 912 (if (if isearch-forward (eobp) (bobp))
+ − 913 ;; If there's nowhere to advance to, fail (and wrap next time).
+ − 914 (progn
+ − 915 (setq isearch-success nil)
+ − 916 (and executing-kbd-macro
+ − 917 (not defining-kbd-macro)
+ − 918 (isearch-done))
+ − 919 (ding nil 'isearch-failed))
+ − 920 (forward-char (if isearch-forward 1 -1))
+ − 921 (isearch-search))
+ − 922 (isearch-search)))
+ − 923
+ − 924 (isearch-push-state)
+ − 925 (isearch-update))
+ − 926
+ − 927 (defun isearch-repeat-forward ()
+ − 928 "Repeat incremental search forwards."
+ − 929 (interactive)
+ − 930 (isearch-repeat 'forward))
+ − 931
+ − 932 (defun isearch-repeat-backward ()
+ − 933 "Repeat incremental search backwards."
+ − 934 (interactive)
+ − 935 (isearch-repeat 'backward))
+ − 936
+ − 937 (defun isearch-toggle-regexp ()
+ − 938 "Toggle regexp searching on or off."
+ − 939 ;; The status stack is left unchanged.
+ − 940 (interactive)
+ − 941 (setq isearch-regexp (not isearch-regexp))
+ − 942 (if isearch-regexp (setq isearch-word nil))
+ − 943 (isearch-update))
+ − 944
+ − 945 (defun isearch-toggle-case-fold ()
+ − 946 "Toggle case folding in searching on or off."
+ − 947 (interactive)
+ − 948 (setq isearch-case-fold-search (if isearch-case-fold-search nil 'yes)
+ − 949 isearch-fixed-case t)
+ − 950 (lmessage 'progress "%s%s [case %ssensitive]"
+ − 951 (isearch-message-prefix)
+ − 952 isearch-message
+ − 953 (if isearch-case-fold-search "in" ""))
+ − 954 (setq isearch-adjusted t)
+ − 955 ;; Update the highlighting here so that it gets done before the
+ − 956 ;; one-second pause.
+ − 957 (isearch-highlight-all-update)
+ − 958 (sit-for 1)
+ − 959 (isearch-update))
+ − 960
+ − 961 (defun isearch-delete-char ()
+ − 962 "Discard last input item and move point back.
+ − 963 If no previous match was done, just beep."
+ − 964 (interactive)
+ − 965 (if (null (cdr isearch-cmds))
+ − 966 (ding nil 'isearch-quit)
+ − 967 (isearch-pop-state))
+ − 968 (isearch-update))
+ − 969
+ − 970 (defun isearch-help-or-delete-char ()
+ − 971 "Show Isearch help or delete backward in the search string.
+ − 972 Deletes when `delete-key-deletes-forward' is t and C-h is used for deleting
+ − 973 backwards."
+ − 974 (interactive)
+ − 975 (if (and delete-key-deletes-forward
+ − 976 (case (device-type)
776
+ − 977 (tty (eq (declare-boundp tty-erase-char) ?\C-h))
+ − 978 (x (not (declare-fboundp
+ − 979 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))))))
428
+ − 980 (isearch-delete-char)
+ − 981 (isearch-mode-help)))
+ − 982
+ − 983 ;; This is similar to FSF isearch-yank-string, but more general.
+ − 984 (defun isearch-yank (chunk)
+ − 985 ;; Helper for isearch-yank-* functions. CHUNK can be a string or a
+ − 986 ;; function.
+ − 987 (let ((word (if (stringp chunk)
+ − 988 chunk
+ − 989 (save-excursion
+ − 990 (and (not isearch-forward) isearch-other-end
+ − 991 (goto-char isearch-other-end))
+ − 992 (buffer-substring
+ − 993 (point)
+ − 994 (progn
+ − 995 (funcall chunk)
+ − 996 (point)))))))
+ − 997 ;; if configured so that typing upper-case characters turns off case
+ − 998 ;; folding, then downcase the string so that yanking an upper-case
+ − 999 ;; word doesn't mess with case-foldedness.
+ − 1000 (if (and search-caps-disable-folding isearch-case-fold-search)
+ − 1001 (setq word (downcase word)))
+ − 1002 (if isearch-regexp (setq word (regexp-quote word)))
+ − 1003 (setq isearch-string (concat isearch-string word)
+ − 1004 isearch-message
+ − 1005 (concat isearch-message
+ − 1006 (mapconcat 'isearch-text-char-description
+ − 1007 word ""))
+ − 1008 ;; Don't move cursor in reverse search.
+ − 1009 isearch-yank-flag t))
+ − 1010 (isearch-search-and-update))
+ − 1011
+ − 1012 (defun isearch-yank-word ()
+ − 1013 "Pull next word from buffer into search string."
+ − 1014 (interactive)
+ − 1015 (isearch-yank (function (lambda () (forward-word 1)))))
+ − 1016
+ − 1017 (defun isearch-yank-line ()
+ − 1018 "Pull rest of line from buffer into search string."
+ − 1019 (interactive)
+ − 1020 (isearch-yank 'end-of-line))
+ − 1021
+ − 1022 (defun isearch-yank-kill ()
+ − 1023 "Pull rest of line from kill ring into search string."
+ − 1024 (interactive)
+ − 1025 (isearch-yank (current-kill 0)))
+ − 1026
+ − 1027 (defun isearch-yank-sexp ()
+ − 1028 "Pull next expression from buffer into search string."
+ − 1029 (interactive)
+ − 1030 (isearch-yank 'forward-sexp))
+ − 1031
+ − 1032 (defun isearch-yank-selection ()
+ − 1033 "Pull the current selection into the search string."
+ − 1034 (interactive)
+ − 1035 (isearch-yank (get-selection)))
+ − 1036
+ − 1037 (defun isearch-yank-clipboard ()
+ − 1038 "Pull the current clipboard selection into the search string."
+ − 1039 (interactive)
+ − 1040 (isearch-yank (get-clipboard)))
+ − 1041
+ − 1042 (defun isearch-fix-case ()
+ − 1043 ;; The commented-out (and ...) form implies that, once
+ − 1044 ;; isearch-case-fold-search becomes nil due to a capital letter
+ − 1045 ;; typed in, it can never be restored to the original value. In
+ − 1046 ;; that case, it's impossible to revert a case-sensitive search back
+ − 1047 ;; to case-insensitive.
+ − 1048 (if ;(and isearch-case-fold-search search-caps-disable-folding)
+ − 1049 (and case-fold-search
+ − 1050 ;; Make sure isearch-toggle-case-fold works.
+ − 1051 (not isearch-fixed-case)
+ − 1052 search-caps-disable-folding)
+ − 1053 (setq isearch-case-fold-search
+ − 1054 (no-upper-case-p isearch-string isearch-regexp)))
+ − 1055 (setq isearch-mode (if case-fold-search
+ − 1056 (if isearch-case-fold-search
+ − 1057 " Isearch" ;As God Intended Mode
+ − 1058 " ISeARch") ;Warn about evil case via StuDLYcAps.
+ − 1059 " Isearch")))
+ − 1060
+ − 1061 (defun isearch-search-and-update ()
+ − 1062 ;; Do the search and update the display.
+ − 1063 (if (and (not isearch-success)
+ − 1064 ;; unsuccessful regexp search may become
+ − 1065 ;; successful by addition of characters which
+ − 1066 ;; make isearch-string valid
+ − 1067 (not isearch-regexp))
+ − 1068 nil
+ − 1069 ;; In reverse search, adding stuff at
+ − 1070 ;; the end may cause zero or many more chars to be
+ − 1071 ;; matched, in the string following point.
+ − 1072 ;; Allow all those possibilities without moving point as
+ − 1073 ;; long as the match does not extend past search origin.
+ − 1074 (if (and (not isearch-forward) (not isearch-adjusted)
+ − 1075 (condition-case ()
+ − 1076 (progn
+ − 1077 (isearch-fix-case)
+ − 1078 (let ((case-fold-search isearch-case-fold-search))
+ − 1079 (looking-at (if isearch-regexp isearch-string
+ − 1080 (regexp-quote isearch-string)))))
+ − 1081 (error nil))
+ − 1082 (or isearch-yank-flag
+ − 1083 (<= (match-end 0)
+ − 1084 (min isearch-opoint isearch-barrier))))
+ − 1085 (setq isearch-success t
+ − 1086 isearch-invalid-regexp nil
+ − 1087 isearch-within-brackets nil
+ − 1088 isearch-other-end (match-end 0))
+ − 1089 ;; Not regexp, not reverse, or no match at point.
+ − 1090 (if (and isearch-other-end (not isearch-adjusted))
+ − 1091 (goto-char (if isearch-forward isearch-other-end
+ − 1092 (min isearch-opoint
+ − 1093 isearch-barrier
+ − 1094 (1+ isearch-other-end)))))
+ − 1095 (isearch-search)
+ − 1096 ))
+ − 1097 (isearch-push-state)
+ − 1098 (if isearch-op-fun (funcall isearch-op-fun))
+ − 1099 (isearch-update))
+ − 1100
+ − 1101
+ − 1102 ;; *, ?, and | chars can make a regexp more liberal.
+ − 1103 ;; They can make a regexp match sooner or make it succeed instead of failing.
+ − 1104 ;; So go back to place last successful search started
+ − 1105 ;; or to the last ^S/^R (barrier), whichever is nearer.
+ − 1106 ;; + needs no special handling because the string must match at least once.
+ − 1107
+ − 1108 (defun isearch-*-char ()
+ − 1109 "Handle * and ? specially in regexps."
+ − 1110 (interactive)
+ − 1111 (if isearch-regexp
+ − 1112 (let ((idx (length isearch-string)))
+ − 1113 (while (and (> idx 0)
+ − 1114 (eq (aref isearch-string (1- idx)) ?\\))
+ − 1115 (setq idx (1- idx)))
+ − 1116 (when (= (mod (- (length isearch-string) idx) 2) 0)
+ − 1117 (setq isearch-adjusted t)
+ − 1118 ;; Get the isearch-other-end from before the last search.
+ − 1119 ;; We want to start from there,
+ − 1120 ;; so that we don't retreat farther than that.
+ − 1121 ;; (car isearch-cmds) is after last search;
+ − 1122 ;; (car (cdr isearch-cmds)) is from before it.
+ − 1123 (let ((cs (nth 5 (car (cdr isearch-cmds)))))
+ − 1124 (setq cs (or cs isearch-barrier))
+ − 1125 (goto-char
+ − 1126 (if isearch-forward
+ − 1127 (max cs isearch-barrier)
+ − 1128 (min cs isearch-barrier)))))))
+ − 1129 (isearch-process-search-char last-command-event))
+ − 1130
+ − 1131
+ − 1132
+ − 1133 (defun isearch-|-char ()
+ − 1134 "If in regexp search, jump to the barrier."
+ − 1135 (interactive)
+ − 1136 (if isearch-regexp
+ − 1137 (progn
+ − 1138 (setq isearch-adjusted t)
+ − 1139 (goto-char isearch-barrier)))
+ − 1140 (isearch-process-search-char last-command-event))
+ − 1141
+ − 1142 ;; FSF:
+ − 1143 ;(defalias 'isearch-other-control-char 'isearch-other-meta-char)
+ − 1144 ;
+ − 1145 ;(defun isearch-other-meta-char ()
+ − 1146 ;...
+ − 1147 ;
+ − 1148
+ − 1149 (defun isearch-quote-char ()
+ − 1150 "Quote special characters for incremental search."
+ − 1151 (interactive)
+ − 1152 ;; #### Here FSF does some special conversion of chars in 0200-0377
+ − 1153 ;; range. Maybe we should do the same.
+ − 1154 (isearch-process-search-char (read-quoted-char (isearch-message t))))
+ − 1155
+ − 1156 (defun isearch-return-char ()
+ − 1157 "Convert return into newline for incremental search.
+ − 1158 Obsolete."
+ − 1159 (interactive)
+ − 1160 (isearch-process-search-char ?\n))
+ − 1161
+ − 1162 (defun isearch-printing-char ()
+ − 1163 "Add this ordinary printing character to the search string and search."
+ − 1164 (interactive)
+ − 1165 (let ((event last-command-event))
+ − 1166 ;; If we are called by isearch-whitespace-chars because the
+ − 1167 ;; context disallows whitespace search (e.g. within brackets),
+ − 1168 ;; replace M-SPC with a space. FSF has similar code.
+ − 1169 (and (eq this-command 'isearch-whitespace-chars)
+ − 1170 (null (event-to-character event))
+ − 1171 (setq event (character-to-event ?\ )))
+ − 1172 (isearch-process-search-char event)))
+ − 1173
+ − 1174 (defun isearch-whitespace-chars ()
+ − 1175 "Match all whitespace chars, if in regexp mode."
+ − 1176 ;; FSF docstring adds: "If you want to search for just a space, type
+ − 1177 ;; C-q SPC." But we don't need the addition because we have a
+ − 1178 ;; different (better) default for the variable.
+ − 1179 (interactive)
+ − 1180 (if isearch-regexp
+ − 1181 (if (and search-whitespace-regexp (not isearch-within-brackets)
+ − 1182 (not isearch-invalid-regexp))
+ − 1183 (isearch-process-search-string search-whitespace-regexp " ")
+ − 1184 (isearch-printing-char))
+ − 1185 (progn
+ − 1186 ;; This way of doing word search doesn't correctly extend current search.
+ − 1187 ;; (setq isearch-word t)
+ − 1188 ;; (setq isearch-adjusted t)
+ − 1189 ;; (goto-char isearch-barrier)
+ − 1190 (isearch-printing-char))))
+ − 1191
+ − 1192 (defun isearch-process-search-char (char)
+ − 1193 ;; Append the char to the search string, update the message and re-search.
+ − 1194 (isearch-process-search-string (isearch-char-to-string char)
+ − 1195 (isearch-text-char-description char)))
+ − 1196
+ − 1197 (defun isearch-process-search-string (string message)
+ − 1198 (setq isearch-string (concat isearch-string string)
+ − 1199 isearch-message (concat isearch-message message))
+ − 1200 (isearch-search-and-update))
+ − 1201
+ − 1202
+ − 1203 ;;===========================================================
+ − 1204 ;; Search Ring
+ − 1205
+ − 1206 (defun isearch-ring-adjust1 (advance)
+ − 1207 ;; Helper for isearch-ring-adjust
+ − 1208 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
+ − 1209 (length (length ring))
+ − 1210 (yank-pointer-name (if isearch-regexp
+ − 1211 'regexp-search-ring-yank-pointer
+ − 1212 'search-ring-yank-pointer))
+ − 1213 (yank-pointer (eval yank-pointer-name)))
+ − 1214 (if (zerop length)
+ − 1215 ()
+ − 1216 (set yank-pointer-name
+ − 1217 (setq yank-pointer
+ − 1218 (mod (+ (or yank-pointer 0)
442
+ − 1219 ;; XEmacs change
+ − 1220 (if advance -1 (if yank-pointer 1 0)))
428
+ − 1221 length)))
+ − 1222 (setq isearch-string (nth yank-pointer ring)
+ − 1223 isearch-message (mapconcat 'isearch-text-char-description
+ − 1224 isearch-string "")))))
+ − 1225
+ − 1226 (defun isearch-ring-adjust (advance)
+ − 1227 ;; Helper for isearch-ring-advance and isearch-ring-retreat
+ − 1228 ; (if (cdr isearch-cmds) ;; is there more than one thing on stack?
+ − 1229 ; (isearch-pop-state))
+ − 1230 (isearch-ring-adjust1 advance)
+ − 1231 (if search-ring-update
+ − 1232 (progn
+ − 1233 (isearch-search)
+ − 1234 (isearch-update))
+ − 1235 (isearch-edit-string)
+ − 1236 )
+ − 1237 (isearch-push-state))
+ − 1238
+ − 1239 (defun isearch-ring-advance ()
+ − 1240 "Advance to the next search string in the ring."
+ − 1241 ;; This could be more general to handle a prefix arg, but who would use it.
+ − 1242 (interactive)
+ − 1243 (isearch-ring-adjust 'advance))
+ − 1244
+ − 1245 (defun isearch-ring-retreat ()
+ − 1246 "Retreat to the previous search string in the ring."
+ − 1247 (interactive)
+ − 1248 (isearch-ring-adjust nil))
+ − 1249
+ − 1250 (defun isearch-ring-advance-edit (n)
+ − 1251 "Insert the next element of the search history into the minibuffer."
+ − 1252 (interactive "p")
+ − 1253 (let* ((yank-pointer-name (if isearch-regexp
+ − 1254 'regexp-search-ring-yank-pointer
+ − 1255 'search-ring-yank-pointer))
+ − 1256 (yank-pointer (eval yank-pointer-name))
+ − 1257 (ring (if isearch-regexp regexp-search-ring search-ring))
+ − 1258 (length (length ring)))
+ − 1259 (if (zerop length)
+ − 1260 ()
+ − 1261 (set yank-pointer-name
+ − 1262 (setq yank-pointer
+ − 1263 (mod (- (or yank-pointer 0) n)
+ − 1264 length)))
+ − 1265
+ − 1266 (erase-buffer)
+ − 1267 (insert (nth yank-pointer ring))
+ − 1268 (goto-char (point-max)))))
+ − 1269
+ − 1270 (defun isearch-ring-retreat-edit (n)
+ − 1271 "Inserts the previous element of the search history into the minibuffer."
+ − 1272 (interactive "p")
+ − 1273 (isearch-ring-advance-edit (- n)))
+ − 1274
+ − 1275 ;; Merging note: FSF comments out these functions and implements them
+ − 1276 ;; differently (see above), presumably because the versions below mess
+ − 1277 ;; with isearch-string, while what we really want them to do is simply
+ − 1278 ;; to insert the correct string to the minibuffer.
+ − 1279
+ − 1280 ;;(defun isearch-ring-adjust-edit (advance)
+ − 1281 ;; "Use the next or previous search string in the ring while in minibuffer."
+ − 1282 ;; (isearch-ring-adjust1 advance)
+ − 1283 ;; (erase-buffer)
+ − 1284 ;; (insert isearch-string))
+ − 1285
+ − 1286 ;;(defun isearch-ring-advance-edit ()
+ − 1287 ;; (interactive)
+ − 1288 ;; (isearch-ring-adjust-edit 'advance))
+ − 1289
+ − 1290 ;;(defun isearch-ring-retreat-edit ()
+ − 1291 ;; "Retreat to the previous search string in the ring while in the minibuffer."
+ − 1292 ;; (interactive)
+ − 1293 ;; (isearch-ring-adjust-edit nil))
+ − 1294
+ − 1295
+ − 1296 (defun isearch-complete1 ()
+ − 1297 ;; Helper for isearch-complete and isearch-complete-edit
+ − 1298 ;; Return t if completion OK, nil if no completion exists.
+ − 1299 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
+ − 1300 (alist (mapcar (function (lambda (string) (list string))) ring))
+ − 1301 (completion-ignore-case case-fold-search)
+ − 1302 (completion (try-completion isearch-string alist)))
+ − 1303 (cond
+ − 1304 ((eq completion t)
+ − 1305 ;; isearch-string stays the same
+ − 1306 t)
+ − 1307 ((or completion ; not nil, must be a string
+ − 1308 (= 0 (length isearch-string))) ; shouldn't have to say this
+ − 1309 (if (equal completion isearch-string) ;; no extension?
+ − 1310 (progn
+ − 1311 (if completion-auto-help
+ − 1312 (with-output-to-temp-buffer "*Isearch completions*"
+ − 1313 (display-completion-list
+ − 1314 (all-completions isearch-string alist))))
+ − 1315 t)
+ − 1316 (and completion
+ − 1317 (setq isearch-string completion))))
+ − 1318 (t
+ − 1319 (temp-minibuffer-message "No completion")
+ − 1320 nil))))
+ − 1321
+ − 1322 (defun isearch-complete ()
+ − 1323 "Complete the search string from the strings on the search ring.
+ − 1324 The completed string is then editable in the minibuffer.
+ − 1325 If there is no completion possible, say so and continue searching."
+ − 1326 (interactive)
+ − 1327 (if (isearch-complete1)
+ − 1328 (isearch-edit-string)
+ − 1329 ;; else
+ − 1330 (sit-for 1)
+ − 1331 (isearch-update)))
+ − 1332
+ − 1333 (defun isearch-complete-edit ()
+ − 1334 "Same as `isearch-complete' except in the minibuffer."
+ − 1335 (interactive)
+ − 1336 (setq isearch-string (buffer-string))
+ − 1337 (if (isearch-complete1)
+ − 1338 (progn
+ − 1339 (erase-buffer)
+ − 1340 (insert isearch-string))))
+ − 1341
+ − 1342
+ − 1343 ;;;==============================================================
+ − 1344 ;; The search status stack.
+ − 1345
+ − 1346 (defun isearch-top-state ()
+ − 1347 (let ((cmd (car isearch-cmds)))
+ − 1348 ;; #### Grr, this is so error-prone. If you add something to
440
+ − 1349 ;; isearch-push-state, don't forget to update this. I thought I'd
428
+ − 1350 ;; make a list of variables, and just do (mapcar* #'set vars
+ − 1351 ;; values), but the (point) thing would spoil it, leaving to more
+ − 1352 ;; complication.
+ − 1353 (setq isearch-string (car cmd)
+ − 1354 isearch-message (car (cdr cmd))
+ − 1355 isearch-success (nth 3 cmd)
+ − 1356 isearch-forward (nth 4 cmd)
+ − 1357 isearch-other-end (nth 5 cmd)
+ − 1358 isearch-word (nth 6 cmd)
+ − 1359 isearch-invalid-regexp (nth 7 cmd)
+ − 1360 isearch-wrapped (nth 8 cmd)
+ − 1361 isearch-barrier (nth 9 cmd)
+ − 1362 isearch-within-brackets (nth 10 cmd))
+ − 1363 (goto-char (car (cdr (cdr cmd))))))
+ − 1364
+ − 1365 (defun isearch-pop-state ()
+ − 1366 (pop isearch-cmds)
+ − 1367 (isearch-top-state)
+ − 1368
+ − 1369 ;; Make sure isearch-case-fold-search gets the correct value. FSF
+ − 1370 ;; simply stores isearch-case-fold-search to isearch-cmds. We
+ − 1371 ;; should probably do the same.
+ − 1372 (isearch-fix-case)
+ − 1373
+ − 1374 ;; Here, as well as in isearch-search we must deal with the point
+ − 1375 ;; landing at an invisible area which may need unhiding.
+ − 1376 (if (or (not (eq search-invisible 'open))
+ − 1377 (not isearch-hide-immediately))
+ − 1378 ;; If search-invisible is t, invisible text is just like any
+ − 1379 ;; other text. If it is nil, it is always skipped and we can't
+ − 1380 ;; land inside. In both cases, we don't need to do anything.
+ − 1381 ;;
+ − 1382 ;; Similarly, if isearch-hide-immediately is nil, needn't
+ − 1383 ;; re-hide the area here, and neither can we land back into a
+ − 1384 ;; hidden one.
+ − 1385 nil
+ − 1386 (when isearch-other-end
+ − 1387 ;; This will unhide the extents.
+ − 1388 (isearch-range-invisible (point) isearch-other-end))
+ − 1389 (isearch-restore-invisible-extents (point)
+ − 1390 (or isearch-other-end (point)))))
+ − 1391
+ − 1392 (defun isearch-push-state ()
+ − 1393 (setq isearch-cmds
+ − 1394 (cons (list isearch-string isearch-message (point)
+ − 1395 isearch-success isearch-forward isearch-other-end
+ − 1396 isearch-word
+ − 1397 isearch-invalid-regexp isearch-wrapped isearch-barrier
+ − 1398 isearch-within-brackets)
+ − 1399 isearch-cmds)))
+ − 1400
+ − 1401
+ − 1402 ;;;==================================================================
+ − 1403 ;; Message string
+ − 1404
+ − 1405 (defun isearch-message (&optional c-q-hack ellipsis)
+ − 1406 ;; Generate and print the message string.
+ − 1407 (let ((cursor-in-echo-area ellipsis)
+ − 1408 (m (concat
+ − 1409 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
+ − 1410 isearch-message
+ − 1411 (isearch-message-suffix c-q-hack ellipsis)
+ − 1412 )))
+ − 1413 (if c-q-hack
+ − 1414 m
+ − 1415 (display-message 'progress (format "%s" m)))))
+ − 1416
+ − 1417 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
+ − 1418 ;; If about to search, and previous search regexp was invalid,
+ − 1419 ;; check that it still is. If it is valid now,
+ − 1420 ;; let the message we display while searching say that it is valid.
+ − 1421 (and isearch-invalid-regexp ellipsis
+ − 1422 (condition-case ()
+ − 1423 (progn (re-search-forward isearch-string (point) t)
+ − 1424 (setq isearch-invalid-regexp nil
+ − 1425 isearch-within-brackets nil))
+ − 1426 (error nil)))
+ − 1427 ;; If currently failing, display no ellipsis.
+ − 1428 (or isearch-success (setq ellipsis nil))
+ − 1429 ;; #### - ! Emacs assembles strings all over the place, they can't
+ − 1430 ;; all be internationalized in the manner proposed below... Add an
+ − 1431 ;; explicit call to `gettext' and have the string snarfer pluck the
+ − 1432 ;; english strings out of the comment below. XEmacs is on a
+ − 1433 ;; purespace diet! -Stig
+ − 1434
+ − 1435 ;; The comment below is dead and buried, but it can be rebuilt if
+ − 1436 ;; necessary. -hniksic
+ − 1437 (let ((m (concat (if isearch-success nil "failing ")
+ − 1438 (if (and isearch-wrapped
+ − 1439 (if isearch-forward
+ − 1440 (> (point) isearch-opoint)
+ − 1441 (< (point) isearch-opoint)))
+ − 1442 "overwrapped "
+ − 1443 (if isearch-wrapped "wrapped "))
+ − 1444 (if isearch-word "word ")
+ − 1445 (if isearch-regexp "regexp ")
+ − 1446 (if nonincremental "search" "I-search")
+ − 1447 (if isearch-forward nil " backward")
+ − 1448 ": "
+ − 1449 )))
+ − 1450 (aset m 0 (upcase (aref m 0)))
+ − 1451 (gettext m)))
+ − 1452
+ − 1453 (defun isearch-message-suffix (&optional c-q-hack ellipsis)
+ − 1454 (concat (if c-q-hack "^Q" "")
+ − 1455 (if isearch-invalid-regexp
+ − 1456 (concat " [" isearch-invalid-regexp "]")
+ − 1457 "")))
+ − 1458
+ − 1459 ;;;(let ((i (logior (if isearch-success 32 0)
+ − 1460 ;;; (if isearch-wrapped 16 0)
+ − 1461 ;;; (if isearch-word 8 0)
+ − 1462 ;;; (if isearch-regexp 4 0)
+ − 1463 ;;; (if nonincremental 2 0)
+ − 1464 ;;; (if isearch-forward 1 0))))
+ − 1465 ;;; (cond
+ − 1466 ;;; ((= i 63) (gettext "Wrapped word regexp search: ")) ; 111111
+ − 1467 ;;; ...and so on, ad nauseam...
+ − 1468 ;;; ((= i 0) (gettext "Failing I-search backward: ")) ; 000000
+ − 1469 ;;; (t (error "Something's rotten")))))
+ − 1470
+ − 1471
+ − 1472 ;;;========================================================
+ − 1473 ;;; Exiting
+ − 1474
+ − 1475 (put 'isearch-printing-char 'isearch-command t)
+ − 1476 (put 'isearch-return-char 'isearch-command t)
+ − 1477 (put 'isearch-repeat-forward 'isearch-command t)
+ − 1478 (put 'isearch-repeat-backward 'isearch-command t)
+ − 1479 (put 'isearch-delete-char 'isearch-command t)
+ − 1480 (put 'isearch-help-or-delete-char 'isearch-command t)
+ − 1481 (put 'isearch-cancel 'isearch-command t)
+ − 1482 (put 'isearch-abort 'isearch-command t)
+ − 1483 (put 'isearch-quote-char 'isearch-command t)
+ − 1484 (put 'isearch-exit 'isearch-command t)
+ − 1485 (put 'isearch-printing-char 'isearch-command t)
+ − 1486 (put 'isearch-printing-char 'isearch-command t)
+ − 1487 (put 'isearch-yank-word 'isearch-command t)
+ − 1488 (put 'isearch-yank-line 'isearch-command t)
+ − 1489 (put 'isearch-yank-kill 'isearch-command t)
+ − 1490 (put 'isearch-yank-sexp 'isearch-command t)
+ − 1491 (put 'isearch-*-char 'isearch-command t)
+ − 1492 (put 'isearch-*-char 'isearch-command t)
+ − 1493 (put 'isearch-|-char 'isearch-command t)
+ − 1494 (put 'isearch-toggle-regexp 'isearch-command t)
+ − 1495 (put 'isearch-toggle-case-fold 'isearch-command t)
+ − 1496 (put 'isearch-edit-string 'isearch-command t)
+ − 1497 (put 'isearch-mode-help 'isearch-command t)
+ − 1498 (put 'isearch-ring-advance 'isearch-command t)
+ − 1499 (put 'isearch-ring-retreat 'isearch-command t)
+ − 1500 (put 'isearch-ring-advance-edit 'isearch-command t)
+ − 1501 (put 'isearch-ring-retreat-edit 'isearch-command t)
+ − 1502 (put 'isearch-whitespace-chars 'isearch-command t)
+ − 1503 (put 'isearch-complete 'isearch-command t)
+ − 1504 (put 'isearch-complete-edit 'isearch-command t)
+ − 1505 (put 'isearch-edit-string 'isearch-command t)
+ − 1506 (put 'isearch-toggle-regexp 'isearch-command t)
+ − 1507 (put 'isearch-forward-exit-minibuffer 'isearch-command t)
+ − 1508 (put 'isearch-reverse-exit-minibuffer 'isearch-command t)
+ − 1509 (put 'isearch-nonincremental-exit-minibuffer 'isearch-command t)
+ − 1510 (put 'isearch-yank-selection 'isearch-command t)
+ − 1511 (put 'isearch-yank-clipboard 'isearch-command t)
+ − 1512 (put 'isearch-yank-x-selection 'isearch-command t)
+ − 1513 (put 'isearch-yank-x-clipboard 'isearch-command t)
+ − 1514
+ − 1515 ;; scrolling the scrollbar should not terminate isearch.
+ − 1516
+ − 1517 ;; vertical scrollbar:
+ − 1518 (put 'scrollbar-line-up 'isearch-command t)
+ − 1519 (put 'scrollbar-line-down 'isearch-command t)
+ − 1520 (put 'scrollbar-page-up 'isearch-command t)
+ − 1521 (put 'scrollbar-page-down 'isearch-command t)
+ − 1522 (put 'scrollbar-to-top 'isearch-command t)
+ − 1523 (put 'scrollbar-to-bottom 'isearch-command t)
+ − 1524 (put 'scrollbar-vertical-drag 'isearch-command t)
+ − 1525
+ − 1526 ;; horizontal scrollbar:
+ − 1527 (put 'scrollbar-char-left 'isearch-command t)
+ − 1528 (put 'scrollbar-char-right 'isearch-command t)
+ − 1529 (put 'scrollbar-page-left 'isearch-command t)
+ − 1530 (put 'scrollbar-page-right 'isearch-command t)
+ − 1531 (put 'scrollbar-to-left 'isearch-command t)
+ − 1532 (put 'scrollbar-to-right 'isearch-command t)
+ − 1533 (put 'scrollbar-horizontal-drag 'isearch-command t)
+ − 1534
+ − 1535 (defun isearch-pre-command-hook ()
+ − 1536 ;;
+ − 1537 ;; For use as the value of `pre-command-hook' when isearch-mode is active.
+ − 1538 ;; If the command about to be executed is not one of the isearch commands,
+ − 1539 ;; then isearch-mode is turned off before that command is executed.
+ − 1540 ;;
+ − 1541 ;; If the command about to be executed is self-insert-command, or is a
+ − 1542 ;; keyboard macro of a single key sequence which is bound to self-insert-
+ − 1543 ;; command, then we add those chars to the search ring instead of inserting
+ − 1544 ;; them in the buffer. In this way, the set of self-searching characters
+ − 1545 ;; need not be exhaustively enumerated, but is derived from other maps.
+ − 1546 ;;
+ − 1547 (cond ((not (eq (current-buffer) isearch-buffer))
+ − 1548 ;; If the buffer (likely meaning "frame") has changed, bail.
+ − 1549 ;; This can happen if the user types something into another
+ − 1550 ;; frame. It can also happen if a proc filter has popped up
+ − 1551 ;; another buffer, which is arguably a bad thing for it to
+ − 1552 ;; have done, but the way in which isearch would have hosed
+ − 1553 ;; you in that case is unarguably even worse. -jwz
+ − 1554 (isearch-done)
+ − 1555
+ − 1556 ;; `this-command' is set according to the value of
+ − 1557 ;; `overriding-local-map', set by isearch-mode. This is
+ − 1558 ;; wrong because that keymap makes sense only in isearch
+ − 1559 ;; buffer. To make sure the right command is called, adjust
+ − 1560 ;; `this-command' to the appropriate value, now that
+ − 1561 ;; `isearch-done' has set `overriding-local-map' to nil.
+ − 1562
+ − 1563 ;; FSF does similar magic in `isearch-other-meta-char', which
+ − 1564 ;; is horribly complex. I *hope* what we do works in all
+ − 1565 ;; cases.
+ − 1566 (setq this-command (key-binding (this-command-keys))))
+ − 1567 (t
+ − 1568 (isearch-maybe-frob-keyboard-macros)
+ − 1569 (if (and this-command
+ − 1570 (symbolp this-command)
+ − 1571 (get this-command 'isearch-command))
+ − 1572 nil ; then continue.
+ − 1573 (isearch-done)))))
+ − 1574
+ − 1575 (defun isearch-maybe-frob-keyboard-macros ()
+ − 1576 ;;
+ − 1577 ;; If the command about to be executed is `self-insert-command' then change
+ − 1578 ;; the command to `isearch-printing-char' instead, meaning add the last-
+ − 1579 ;; typed character to the search string.
+ − 1580 ;;
+ − 1581 ;; If `this-command' is a string or a vector (that is, a keyboard macro)
+ − 1582 ;; and it contains only one command, which is bound to self-insert-command,
+ − 1583 ;; then do the same thing as for self-inserting commands: arrange for that
+ − 1584 ;; character to be added to the search string. If we didn't do this, then
+ − 1585 ;; typing a compose sequence (a la x-compose.el) would terminate the search
+ − 1586 ;; and insert the character, instead of searching for that character.
+ − 1587 ;;
+ − 1588 ;; We should continue doing this, since it's pretty much the behavior one
+ − 1589 ;; would expect, but it will stop being so necessary once key-translation-
+ − 1590 ;; map exists and is used by x-compose.el and things like it, since the
+ − 1591 ;; translation will have been done before we see the keys.
+ − 1592 ;;
+ − 1593 (cond ((eq this-command 'self-insert-command)
+ − 1594 (setq this-command 'isearch-printing-char))
+ − 1595 ((and (or (stringp this-command) (vectorp this-command))
+ − 1596 (eq (key-binding this-command) 'self-insert-command))
+ − 1597 (setq last-command-event (character-to-event (aref this-command 0))
+ − 1598 last-command-char (and (stringp this-command)
+ − 1599 (aref this-command 0))
+ − 1600 this-command 'isearch-printing-char))
+ − 1601 ))
+ − 1602
+ − 1603
+ − 1604 ;;;========================================================
+ − 1605 ;;; Highlighting
+ − 1606
+ − 1607 (defvar isearch-extent nil)
+ − 1608
+ − 1609 ;; this face is initialized by faces.el since isearch is preloaded.
+ − 1610 ;(make-face 'isearch)
+ − 1611
+ − 1612 (defun isearch-make-extent (begin end)
+ − 1613 (let ((x (make-extent begin end (current-buffer))))
440
+ − 1614 ;; make the isearch extent always take precedence over any mouse-
428
+ − 1615 ;; highlighted extents we may be passing through, since isearch, being
+ − 1616 ;; modal, is more interesting (there's nothing they could do with a
+ − 1617 ;; mouse-highlighted extent while in the midst of a search anyway).
+ − 1618 (set-extent-priority x (+ mouse-highlight-priority 2))
+ − 1619 (set-extent-face x 'isearch)
+ − 1620 (setq isearch-extent x)))
+ − 1621
+ − 1622 (defun isearch-highlight (begin end)
+ − 1623 (if (null search-highlight)
+ − 1624 nil
+ − 1625 ;; make sure isearch-extent is in the current buffer
+ − 1626 (or (and (extentp isearch-extent)
+ − 1627 (extent-live-p isearch-extent))
+ − 1628 (isearch-make-extent begin end))
+ − 1629 (set-extent-endpoints isearch-extent begin end (current-buffer))))
+ − 1630
+ − 1631 ;; This used to have a TOTALLY flag that also deleted the extent. I
+ − 1632 ;; don't think this is necessary any longer, as isearch-highlight can
+ − 1633 ;; simply move the extent to another buffer. The IGNORED argument is
+ − 1634 ;; for the code that calls this function with an argument. --hniksic
+ − 1635 (defun isearch-dehighlight (&optional ignored)
+ − 1636 (and search-highlight
+ − 1637 (extentp isearch-extent)
+ − 1638 (extent-live-p isearch-extent)
+ − 1639 (detach-extent isearch-extent)))
+ − 1640
+ − 1641
+ − 1642 ;;;========================================================
+ − 1643 ;;; Searching
+ − 1644
+ − 1645 (defun isearch-search ()
+ − 1646 ;; Do the search with the current search string.
+ − 1647 (isearch-message nil t)
+ − 1648 (isearch-fix-case)
+ − 1649 (condition-case lossage
+ − 1650 (let ((inhibit-quit nil)
+ − 1651 (case-fold-search isearch-case-fold-search)
+ − 1652 (retry t))
+ − 1653 (if isearch-regexp (setq isearch-invalid-regexp nil))
+ − 1654 (setq isearch-within-brackets nil)
+ − 1655 (while retry
+ − 1656 (setq isearch-success
+ − 1657 (funcall
+ − 1658 (cond (isearch-word
+ − 1659 (if isearch-forward
+ − 1660 'word-search-forward 'word-search-backward))
+ − 1661 (isearch-regexp
+ − 1662 (if isearch-forward
+ − 1663 're-search-forward 're-search-backward))
+ − 1664 (t
+ − 1665 (if isearch-forward 'search-forward 'search-backward)))
+ − 1666 isearch-string nil t))
+ − 1667 ;; Clear RETRY unless we matched some invisible text
+ − 1668 ;; and we aren't supposed to do that.
+ − 1669 (if (or (eq search-invisible t)
+ − 1670 (not isearch-success)
+ − 1671 (bobp) (eobp)
+ − 1672 (= (match-beginning 0) (match-end 0))
+ − 1673 (not (isearch-range-invisible
+ − 1674 (match-beginning 0) (match-end 0))))
+ − 1675 (setq retry nil)))
+ − 1676 (setq isearch-just-started nil)
+ − 1677 (when isearch-success
+ − 1678 (setq isearch-other-end
+ − 1679 (if isearch-forward (match-beginning 0) (match-end 0)))
+ − 1680 (and isearch-hide-immediately
+ − 1681 (isearch-restore-invisible-extents (match-beginning 0)
+ − 1682 (match-end 0)))))
+ − 1683
+ − 1684 (quit (setq unread-command-events (nconc unread-command-events
+ − 1685 (character-to-event (quit-char))))
+ − 1686 (setq isearch-success nil))
+ − 1687
+ − 1688 (invalid-regexp
+ − 1689 (setq isearch-invalid-regexp (car (cdr lossage)))
+ − 1690 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
+ − 1691 isearch-invalid-regexp))
+ − 1692 (if (string-match
+ − 1693 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
+ − 1694 isearch-invalid-regexp)
+ − 1695 (setq isearch-invalid-regexp (gettext "incomplete input"))))
+ − 1696 (error
+ − 1697 ;; stack overflow in regexp search.
+ − 1698 (setq isearch-invalid-regexp (car (cdr lossage)))))
+ − 1699
+ − 1700 (if isearch-success
+ − 1701 nil
+ − 1702
+ − 1703 ;; If we're being run inside a keyboard macro, then the call to
+ − 1704 ;; ding will signal an error (to terminate the macro). We must
+ − 1705 ;; turn off isearch-mode first, so that we aren't still in isearch
+ − 1706 ;; mode after the macro exits. Note that isearch-recursive-edit
+ − 1707 ;; must not be true if a keyboard macro is executing.
+ − 1708 (if (and executing-kbd-macro (not defining-kbd-macro))
+ − 1709 (progn
+ − 1710 (isearch-done)
+ − 1711 (ding nil 'isearch-failed)))
+ − 1712
+ − 1713 ;; Ding if failed this time after succeeding last time.
+ − 1714 (and (nth 3 (car isearch-cmds))
+ − 1715 (ding nil 'isearch-failed))
+ − 1716 (goto-char (nth 2 (car isearch-cmds)))))
+ − 1717
+ − 1718 ;; Replaced with isearch-edit-string.
+ − 1719 ;(defun nonincremental-search (forward regexp)
+ − 1720 ;...
+ − 1721
+ − 1722 (defun isearch-unhide-extent (extent)
+ − 1723 ;; Store the values for the `invisible' and `intangible'
+ − 1724 ;; properties, and then set them to nil. This way the text hidden
+ − 1725 ;; by this extent becomes visible.
+ − 1726 (put extent 'isearch-invisible (get extent 'invisible))
+ − 1727 (put extent 'isearch-intangible (get extent 'intangible))
+ − 1728 (put extent 'invisible nil)
+ − 1729 (put extent 'intangible nil))
+ − 1730
444
+ − 1731 (defun isearch-range-invisible (start end)
+ − 1732 "Return t if all the text from START to END is invisible.
428
+ − 1733 Before that, if search-invisible is `open', unhide the extents with an
+ − 1734 `isearch-open-invisible' property."
+ − 1735 ;; isearch-search uses this to skip the extents that are invisible,
+ − 1736 ;; but don't have `isearch-open-invisible' set. It is unclear
444
+ − 1737 ;; what's supposed to happen if only a part of [START, END) overlaps
428
+ − 1738 ;; the extent.
+ − 1739 (let (to-be-unhidden)
+ − 1740 (if (map-extents
+ − 1741 (lambda (extent ignored)
444
+ − 1742 (if (and (<= (extent-start-position extent) start)
428
+ − 1743 (>= (extent-end-position extent) end))
+ − 1744 ;; All of the region is covered by the extent.
+ − 1745 (if (and (eq search-invisible 'open)
+ − 1746 (get extent 'isearch-open-invisible))
+ − 1747 (progn
+ − 1748 (push extent to-be-unhidden)
+ − 1749 nil) ; keep mapping
+ − 1750 ;; We can't or won't unhide this extent, so we must
+ − 1751 ;; skip the whole match. We return from map-extents
+ − 1752 ;; immediately.
+ − 1753 t)
+ − 1754 ;; Else, keep looking.
+ − 1755 nil))
444
+ − 1756 nil start end nil 'all-extents-closed 'invisible)
428
+ − 1757 ;; The whole match must be skipped. Signal it by returning t
+ − 1758 ;; to the caller.
+ − 1759 t
+ − 1760 ;; If any extents need to be unhidden, unhide them.
+ − 1761 (mapc #'isearch-unhide-extent to-be-unhidden)
+ − 1762 ;; Will leave this assert for some time, to catch bugs.
+ − 1763 (assert (null (intersection to-be-unhidden isearch-unhidden-extents)))
+ − 1764 (setq isearch-unhidden-extents (nconc to-be-unhidden
+ − 1765 isearch-unhidden-extents))
+ − 1766 nil)))
+ − 1767
+ − 1768 (defun isearch-restore-extent (extent)
+ − 1769 (put extent 'invisible (get extent 'isearch-invisible))
+ − 1770 (put extent 'intangible (get extent 'isearch-intangible))
+ − 1771 (remprop extent 'isearch-invisible)
+ − 1772 (remprop extent 'isearch-intangible))
+ − 1773
+ − 1774 ;; FSF calls this function `isearch-clean-overlays'.
444
+ − 1775 (defun isearch-restore-invisible-extents (start end)
428
+ − 1776 (cond
444
+ − 1777 ((null start)
428
+ − 1778 ;; Delete all -- this is called at the end of isearch.
+ − 1779 (mapc #'isearch-restore-extent isearch-unhidden-extents)
+ − 1780 (setq isearch-unhidden-extents nil))
+ − 1781 (t
+ − 1782 ;; Extents that do not overlap the match area can be safely
+ − 1783 ;; restored to their hidden state.
+ − 1784 (setq isearch-unhidden-extents
+ − 1785 (delete-if (lambda (extent)
444
+ − 1786 (unless (extent-in-region-p extent start end
428
+ − 1787 'all-extents-closed)
+ − 1788 (isearch-restore-extent extent)
+ − 1789 t))
+ − 1790 isearch-unhidden-extents)))))
+ − 1791
+ − 1792 (defun isearch-no-upper-case-p (string)
+ − 1793 "Return t if there are no upper case chars in string.
+ − 1794 But upper case chars preceded by \\ do not count since they
+ − 1795 have special meaning in a regexp."
+ − 1796 ;; this incorrectly returns t for "\\\\A"
+ − 1797 (let ((case-fold-search nil))
+ − 1798 (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string))))
+ − 1799 (make-obsolete 'isearch-no-upper-case-p 'no-upper-case-p)
+ − 1800
+ − 1801 ;; Portability functions to support various Emacs versions.
+ − 1802
+ − 1803 (defun isearch-char-to-string (c)
+ − 1804 (if (eventp c)
+ − 1805 (make-string 1 (event-to-character c nil nil t))
+ − 1806 (make-string 1 c)))
+ − 1807
+ − 1808 ;(defun isearch-text-char-description (c)
+ − 1809 ; (isearch-char-to-string c))
+ − 1810
+ − 1811 (define-function 'isearch-text-char-description 'text-char-description)
+ − 1812
+ − 1813 ;; Used by etags.el and info.el
+ − 1814 (defmacro with-caps-disable-folding (string &rest body) "\
+ − 1815 Eval BODY with `case-fold-search' let to nil if STRING contains
+ − 1816 uppercase letters and `search-caps-disable-folding' is t."
+ − 1817 `(let ((case-fold-search
+ − 1818 (if (and case-fold-search search-caps-disable-folding)
+ − 1819 (isearch-no-upper-case-p ,string)
+ − 1820 case-fold-search)))
+ − 1821 ,@body))
+ − 1822 (make-obsolete 'with-caps-disable-folding 'with-search-caps-disable-folding)
+ − 1823 (put 'with-caps-disable-folding 'lisp-indent-function 1)
+ − 1824 (put 'with-caps-disable-folding 'edebug-form-spec '(form body))
+ − 1825
+ − 1826
+ − 1827 ;;;========================================================
+ − 1828 ;;; Advanced highlighting
+ − 1829
+ − 1830 ;; When active, *every* visible match for the current search string is
+ − 1831 ;; highlighted: the current one using the normal isearch match color
+ − 1832 ;; and all the others using the `isearch-secondary' face. The extra
+ − 1833 ;; highlighting makes it easier to anticipate where the cursor will
+ − 1834 ;; land each time you press C-s or C-r to repeat a pending search.
+ − 1835 ;; Only the matches visible at any point are highlighted -- when you
+ − 1836 ;; move through the buffer, the highlighting is readjusted.
+ − 1837
+ − 1838 ;; This is based on ideas from Bob Glickstein's `ishl' package. It
+ − 1839 ;; has been merged with XEmacs by Darryl Okahata, and then completely
+ − 1840 ;; rewritten by Hrvoje Niksic.
+ − 1841
+ − 1842 ;; The code makes the following assumptions about the rest of this
+ − 1843 ;; file, so be careful when modifying it.
+ − 1844
+ − 1845 ;; * `isearch-highlight-all-update' should get called when the search
+ − 1846 ;; string changes, or when the search advances. This is done from
+ − 1847 ;; `isearch-update'.
+ − 1848 ;; * `isearch-highlight-all-cleanup' should get called when the search
+ − 1849 ;; is done. This is performed in `isearch-done'.
+ − 1850 ;; * `isearch-string' is expected to contain the current search string
+ − 1851 ;; as entered by the user.
+ − 1852 ;; * `isearch-opoint' is expected to contain the location where the
+ − 1853 ;; current search began.
+ − 1854 ;; * the type of the current search is expected to be given by
+ − 1855 ;; `isearch-word' and `isearch-regexp'.
+ − 1856 ;; * the variable `isearch-invalid-regexp' is expected to be true iff
+ − 1857 ;; `isearch-string' is an invalid regexp.
+ − 1858
+ − 1859 (defcustom isearch-highlight-all-matches search-highlight
+ − 1860 "*Non-nil means highlight all visible matches."
+ − 1861 :type 'boolean
+ − 1862 :group 'isearch)
+ − 1863
+ − 1864 ;; We can't create this face here, as isearch.el is preloaded.
+ − 1865 ;; #### Think up a better name for this!
+ − 1866 ;(defface isearch-secondary '((t (:foreground "red3")))
+ − 1867 ; "Face to use for highlighting all matches."
+ − 1868 ; :group 'isearch)
+ − 1869
+ − 1870 (defvar isearch-highlight-extents nil)
+ − 1871 (defvar isearch-window-start nil)
+ − 1872 (defvar isearch-window-end nil)
+ − 1873 ;; We compare isearch-string and isearch-case-fold-search to saved
+ − 1874 ;; values for better efficiency.
+ − 1875 (defvar isearch-highlight-last-string nil)
+ − 1876 (defvar isearch-highlight-last-case-fold-search nil)
+ − 1877 (defvar isearch-highlight-last-regexp nil)
+ − 1878
+ − 1879 (defun isearch-delete-extents-in-range (start end)
+ − 1880 ;; Delete all highlighting extents that overlap [START, END).
+ − 1881 (setq isearch-highlight-extents
+ − 1882 (delete-if (lambda (extent)
+ − 1883 (when (extent-in-region-p extent start end)
+ − 1884 (delete-extent extent)
+ − 1885 t))
+ − 1886 isearch-highlight-extents)))
+ − 1887
+ − 1888 (defun isearch-highlight-all-cleanup ()
+ − 1889 ;; Stop lazily highlighting and remove extra highlighting from
+ − 1890 ;; buffer.
+ − 1891 (mapc #'delete-extent isearch-highlight-extents)
+ − 1892 (setq isearch-highlight-extents nil)
442
+ − 1893 (setq isearch-window-end nil
428
+ − 1894 isearch-highlight-last-string nil))
+ − 1895
+ − 1896 (defun isearch-highlight-all-update ()
+ − 1897 ;; Update the highlighting if necessary. This needs to check if the
+ − 1898 ;; search string has changed, or if the window has changed position
+ − 1899 ;; in the buffer.
+ − 1900 (let ((need-start-over nil))
+ − 1901 ;; NB: we don't check for isearch-success because if the point is
+ − 1902 ;; after the last match, the search can be unsuccessful, and yet
+ − 1903 ;; there are things to highlight.
+ − 1904 (cond ((not isearch-highlight-all-matches))
+ − 1905 ((or (equal isearch-string "")
+ − 1906 isearch-invalid-regexp)
+ − 1907 (isearch-highlight-all-cleanup))
+ − 1908 ((not (eq isearch-case-fold-search
+ − 1909 isearch-highlight-last-case-fold-search))
+ − 1910 ;; This case is usually caused by search string being
+ − 1911 ;; changed, which would be caught below, but it can also be
+ − 1912 ;; tripped using isearch-toggle-case-fold.
+ − 1913 (setq need-start-over t))
+ − 1914 ((not (eq isearch-regexp isearch-highlight-last-regexp))
+ − 1915 ;; Ditto for isearch-toggle-regexp.
+ − 1916 (setq need-start-over t))
+ − 1917 ((equal isearch-string isearch-highlight-last-string)
+ − 1918 ;; The search string is the same. We need to do something
+ − 1919 ;; if our position has changed.
+ − 1920
+ − 1921 ;; It would be nice if we didn't have to do this; however,
+ − 1922 ;; window-start doesn't support a GUARANTEE flag, so we must
440
+ − 1923 ;; force redisplay to get the correct value for start and end
428
+ − 1924 ;; of window.
+ − 1925 (sit-for 0)
+ − 1926
+ − 1927 ;; Check whether our location has changed.
+ − 1928 (let ((start (window-start))
+ − 1929 (end (min (window-end) (point-max))))
+ − 1930 (cond ((and (= start isearch-window-start)
+ − 1931 (= end isearch-window-end))
+ − 1932 ;; Our position is unchanged -- do nothing.
+ − 1933 )
+ − 1934 ((and (> start isearch-window-start)
+ − 1935 (> end isearch-window-end)
+ − 1936 (<= start isearch-window-end))
+ − 1937 ;; We've migrated downward, but we overlap the old
+ − 1938 ;; region. Delete the old non-overlapping extents
+ − 1939 ;; and fill in the rest.
+ − 1940 (isearch-delete-extents-in-range isearch-window-start start)
+ − 1941 (isearch-highlightify-region isearch-window-end end)
+ − 1942 (setq isearch-window-start start
+ − 1943 isearch-window-end end))
+ − 1944 ((and (<= start isearch-window-start)
+ − 1945 (<= end isearch-window-end)
+ − 1946 (> end isearch-window-start))
+ − 1947 ;; We've migrated upward, but we overlap the old
+ − 1948 ;; region. Delete the old non-overlapping extents
+ − 1949 ;; and fill in the rest.
+ − 1950 (isearch-delete-extents-in-range
+ − 1951 end isearch-window-end)
+ − 1952 (isearch-highlightify-region start isearch-window-start)
+ − 1953 (setq isearch-window-start start
+ − 1954 isearch-window-end end))
+ − 1955 (t
+ − 1956 ;; The regions don't overlap, or they overlap in a
+ − 1957 ;; weird way.
+ − 1958 (setq need-start-over t)))))
+ − 1959 (t
+ − 1960 ;; The search string has changed.
+ − 1961
+ − 1962 ;; If more input is pending, don't start over because
+ − 1963 ;; starting over forces redisplay, and that slows down
+ − 1964 ;; typing.
+ − 1965 (unless (input-pending-p)
+ − 1966 (setq need-start-over t))))
+ − 1967 (when need-start-over
+ − 1968 ;; Force redisplay before removing the old extents, in order to
+ − 1969 ;; avoid flicker.
+ − 1970 (sit-for 0)
+ − 1971 (isearch-highlight-all-cleanup)
+ − 1972 (setq isearch-window-start (window-start)
+ − 1973 isearch-window-end (min (window-end) (point-max)))
+ − 1974 (isearch-highlightify-region isearch-window-start isearch-window-end))
+ − 1975
+ − 1976 (setq isearch-highlight-last-string isearch-string
+ − 1977 isearch-highlight-last-case-fold-search isearch-case-fold-search
+ − 1978 isearch-highlight-last-regexp isearch-regexp)))
+ − 1979
+ − 1980 (defun isearch-highlight-advance (string forwardp)
+ − 1981 ;; Search ahead for the next or previous match. This is the same as
+ − 1982 ;; isearch-search, but without the extra baggage. Maybe it should
+ − 1983 ;; be in a separate function.
+ − 1984 (let ((case-fold-search isearch-case-fold-search))
+ − 1985 (funcall (cond (isearch-word (if forwardp
+ − 1986 'word-search-forward
+ − 1987 'word-search-backward))
+ − 1988 (isearch-regexp (if forwardp
+ − 1989 're-search-forward
+ − 1990 're-search-backward))
+ − 1991 (t (if forwardp
+ − 1992 'search-forward
+ − 1993 'search-backward)))
+ − 1994 string nil t)))
+ − 1995
+ − 1996 (defun isearch-highlightify-region (start end)
+ − 1997 ;; Highlight all occurrences of isearch-string between START and
+ − 1998 ;; END. To do this right, we have to search forward as long as
+ − 1999 ;; there are matches that overlap [START, END), and then search
+ − 2000 ;; backward the same way.
+ − 2001 (save-excursion
+ − 2002 (goto-char isearch-opoint)
+ − 2003 (let ((lastpoint (point)))
+ − 2004 (while (and (isearch-highlight-advance isearch-string t)
+ − 2005 (/= lastpoint (point))
+ − 2006 (< (match-beginning 0) end))
+ − 2007 (let ((extent (make-extent (match-beginning 0)
+ − 2008 (match-end 0))))
+ − 2009 (set-extent-priority extent (1+ mouse-highlight-priority))
+ − 2010 (put extent 'face 'isearch-secondary)
+ − 2011 (push extent isearch-highlight-extents))
+ − 2012 (setq lastpoint (point))))
+ − 2013 (goto-char isearch-opoint)
+ − 2014 (let ((lastpoint (point)))
+ − 2015 (while (and (isearch-highlight-advance isearch-string nil)
+ − 2016 (/= lastpoint (point))
+ − 2017 (>= (match-end 0) start))
+ − 2018 (let ((extent (make-extent (match-beginning 0)
+ − 2019 (match-end 0))))
+ − 2020 (set-extent-priority extent (1+ mouse-highlight-priority))
+ − 2021 (put extent 'face 'isearch-secondary)
+ − 2022 (push extent isearch-highlight-extents))
+ − 2023 (setq lastpoint (point))))))
+ − 2024
+ − 2025 ;;; isearch-mode.el ends here