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