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