Mercurial > hg > xemacs-beta
annotate lisp/isearch-mode.el @ 5724:ede80ef92a74
Make soft links in src for module source files, if built in to the executable.
This ensures that those files are built with the same compiler flags as all
other source files.
See these xemacs-beta messages:
<CAHCOHQn+q=Xuwq+y68dvqi7afAP9f-TdB7=8YiZ8VYO816sjHg@mail.gmail.com>
<f5by5ejqiyk.fsf@calexico.inf.ed.ac.uk>
author | Jerry James <james@xemacs.org> |
---|---|
date | Sat, 02 Mar 2013 14:32:37 -0700 |
parents | b7ae5f44b950 |
children | 2b8edd304c2b |
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-adjust (advance) | |
1224 ;; Helper for isearch-ring-advance and isearch-ring-retreat | |
1225 ; (if (cdr isearch-cmds) ;; is there more than one thing on stack? | |
1226 ; (isearch-pop-state)) | |
5655
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1227 (labels |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1228 ((isearch-ring-adjust1 (advance) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1229 ;; Helper for isearch-ring-adjust |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1230 (let* ((ring (if isearch-regexp regexp-search-ring search-ring)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1231 (length (length ring)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1232 (yank-pointer-name (if isearch-regexp |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1233 'regexp-search-ring-yank-pointer |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1234 'search-ring-yank-pointer)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1235 (yank-pointer (symbol-value yank-pointer-name))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1236 (if (zerop length) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1237 () |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1238 (set yank-pointer-name |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1239 (setq yank-pointer |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1240 (mod (+ (or yank-pointer 0) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1241 ;; XEmacs change |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1242 (if advance -1 (if yank-pointer 1 0))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1243 length))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1244 (setq isearch-string (nth yank-pointer ring) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1245 isearch-message (mapconcat 'isearch-text-char-description |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1246 isearch-string "")))))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1247 (isearch-ring-adjust1 advance) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1248 (if search-ring-update |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1249 (progn |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1250 (isearch-search) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1251 (isearch-update)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1252 (isearch-edit-string)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1253 (isearch-push-state))) |
428 | 1254 |
1255 (defun isearch-ring-advance () | |
1256 "Advance to the next search string in the ring." | |
1257 ;; This could be more general to handle a prefix arg, but who would use it. | |
1258 (interactive) | |
1259 (isearch-ring-adjust 'advance)) | |
1260 | |
1261 (defun isearch-ring-retreat () | |
1262 "Retreat to the previous search string in the ring." | |
1263 (interactive) | |
1264 (isearch-ring-adjust nil)) | |
1265 | |
1266 (defun isearch-ring-advance-edit (n) | |
1267 "Insert the next element of the search history into the minibuffer." | |
1268 (interactive "p") | |
1269 (let* ((yank-pointer-name (if isearch-regexp | |
1270 'regexp-search-ring-yank-pointer | |
1271 'search-ring-yank-pointer)) | |
1272 (yank-pointer (eval yank-pointer-name)) | |
1273 (ring (if isearch-regexp regexp-search-ring search-ring)) | |
1274 (length (length ring))) | |
1275 (if (zerop length) | |
1276 () | |
1277 (set yank-pointer-name | |
1278 (setq yank-pointer | |
1279 (mod (- (or yank-pointer 0) n) | |
1280 length))) | |
1281 | |
1282 (erase-buffer) | |
1283 (insert (nth yank-pointer ring)) | |
1284 (goto-char (point-max))))) | |
1285 | |
1286 (defun isearch-ring-retreat-edit (n) | |
1287 "Inserts the previous element of the search history into the minibuffer." | |
1288 (interactive "p") | |
1289 (isearch-ring-advance-edit (- n))) | |
1290 | |
1291 ;; Merging note: FSF comments out these functions and implements them | |
1292 ;; differently (see above), presumably because the versions below mess | |
1293 ;; with isearch-string, while what we really want them to do is simply | |
1294 ;; to insert the correct string to the minibuffer. | |
1295 | |
1296 ;;(defun isearch-ring-adjust-edit (advance) | |
1297 ;; "Use the next or previous search string in the ring while in minibuffer." | |
1298 ;; (isearch-ring-adjust1 advance) | |
1299 ;; (erase-buffer) | |
1300 ;; (insert isearch-string)) | |
1301 | |
1302 ;;(defun isearch-ring-advance-edit () | |
1303 ;; (interactive) | |
1304 ;; (isearch-ring-adjust-edit 'advance)) | |
1305 | |
1306 ;;(defun isearch-ring-retreat-edit () | |
1307 ;; "Retreat to the previous search string in the ring while in the minibuffer." | |
1308 ;; (interactive) | |
1309 ;; (isearch-ring-adjust-edit nil)) | |
1310 | |
1311 | |
1312 (defun isearch-complete1 () | |
1313 ;; Helper for isearch-complete and isearch-complete-edit | |
1314 ;; Return t if completion OK, nil if no completion exists. | |
1315 (let* ((ring (if isearch-regexp regexp-search-ring search-ring)) | |
1316 (alist (mapcar (function (lambda (string) (list string))) ring)) | |
1317 (completion-ignore-case case-fold-search) | |
1318 (completion (try-completion isearch-string alist))) | |
1319 (cond | |
1320 ((eq completion t) | |
1321 ;; isearch-string stays the same | |
1322 t) | |
1323 ((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
|
1324 (eql 0 (length isearch-string))) ; shouldn't have to say this |
428 | 1325 (if (equal completion isearch-string) ;; no extension? |
1326 (progn | |
1327 (if completion-auto-help | |
1328 (with-output-to-temp-buffer "*Isearch completions*" | |
1329 (display-completion-list | |
1330 (all-completions isearch-string alist)))) | |
1331 t) | |
1332 (and completion | |
1333 (setq isearch-string completion)))) | |
1334 (t | |
1335 (temp-minibuffer-message "No completion") | |
1336 nil)))) | |
1337 | |
1338 (defun isearch-complete () | |
1339 "Complete the search string from the strings on the search ring. | |
1340 The completed string is then editable in the minibuffer. | |
1341 If there is no completion possible, say so and continue searching." | |
1342 (interactive) | |
1343 (if (isearch-complete1) | |
1344 (isearch-edit-string) | |
1345 ;; else | |
1346 (sit-for 1) | |
1347 (isearch-update))) | |
1348 | |
1349 (defun isearch-complete-edit () | |
1350 "Same as `isearch-complete' except in the minibuffer." | |
1351 (interactive) | |
1352 (setq isearch-string (buffer-string)) | |
1353 (if (isearch-complete1) | |
1354 (progn | |
1355 (erase-buffer) | |
1356 (insert isearch-string)))) | |
1357 | |
1358 | |
1359 ;;;============================================================== | |
1360 ;; The search status stack. | |
1361 | |
1362 (defun isearch-top-state () | |
1363 (let ((cmd (car isearch-cmds))) | |
1364 ;; #### Grr, this is so error-prone. If you add something to | |
440 | 1365 ;; isearch-push-state, don't forget to update this. I thought I'd |
428 | 1366 ;; make a list of variables, and just do (mapcar* #'set vars |
1367 ;; values), but the (point) thing would spoil it, leaving to more | |
1368 ;; complication. | |
1369 (setq isearch-string (car cmd) | |
1370 isearch-message (car (cdr cmd)) | |
1371 isearch-success (nth 3 cmd) | |
1372 isearch-forward (nth 4 cmd) | |
1373 isearch-other-end (nth 5 cmd) | |
1374 isearch-word (nth 6 cmd) | |
1375 isearch-invalid-regexp (nth 7 cmd) | |
1376 isearch-wrapped (nth 8 cmd) | |
1377 isearch-barrier (nth 9 cmd) | |
1378 isearch-within-brackets (nth 10 cmd)) | |
1379 (goto-char (car (cdr (cdr cmd)))))) | |
1380 | |
1381 (defun isearch-pop-state () | |
1382 (pop isearch-cmds) | |
1383 (isearch-top-state) | |
1384 | |
1385 ;; Make sure isearch-case-fold-search gets the correct value. FSF | |
1386 ;; simply stores isearch-case-fold-search to isearch-cmds. We | |
1387 ;; should probably do the same. | |
1388 (isearch-fix-case) | |
1389 | |
1390 ;; Here, as well as in isearch-search we must deal with the point | |
1391 ;; landing at an invisible area which may need unhiding. | |
1392 (if (or (not (eq search-invisible 'open)) | |
1393 (not isearch-hide-immediately)) | |
1394 ;; If search-invisible is t, invisible text is just like any | |
1395 ;; other text. If it is nil, it is always skipped and we can't | |
1396 ;; land inside. In both cases, we don't need to do anything. | |
1397 ;; | |
1398 ;; Similarly, if isearch-hide-immediately is nil, needn't | |
1399 ;; re-hide the area here, and neither can we land back into a | |
1400 ;; hidden one. | |
1401 nil | |
1402 (when isearch-other-end | |
1403 ;; This will unhide the extents. | |
1404 (isearch-range-invisible (point) isearch-other-end)) | |
1405 (isearch-restore-invisible-extents (point) | |
1406 (or isearch-other-end (point))))) | |
1407 | |
1408 (defun isearch-push-state () | |
1409 (setq isearch-cmds | |
1410 (cons (list isearch-string isearch-message (point) | |
1411 isearch-success isearch-forward isearch-other-end | |
1412 isearch-word | |
1413 isearch-invalid-regexp isearch-wrapped isearch-barrier | |
1414 isearch-within-brackets) | |
1415 isearch-cmds))) | |
1416 | |
1417 | |
1418 ;;;================================================================== | |
1419 ;; Message string | |
1420 | |
1421 (defun isearch-message (&optional c-q-hack ellipsis) | |
1422 ;; Generate and print the message string. | |
1423 (let ((cursor-in-echo-area ellipsis) | |
1424 (m (concat | |
1425 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental) | |
1426 isearch-message | |
1427 (isearch-message-suffix c-q-hack ellipsis) | |
1428 ))) | |
1429 (if c-q-hack | |
1430 m | |
1431 (display-message 'progress (format "%s" m))))) | |
1432 | |
1433 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental) | |
1434 ;; If about to search, and previous search regexp was invalid, | |
1435 ;; check that it still is. If it is valid now, | |
1436 ;; let the message we display while searching say that it is valid. | |
1437 (and isearch-invalid-regexp ellipsis | |
1438 (condition-case () | |
1439 (progn (re-search-forward isearch-string (point) t) | |
1440 (setq isearch-invalid-regexp nil | |
1441 isearch-within-brackets nil)) | |
1442 (error nil))) | |
1443 ;; If currently failing, display no ellipsis. | |
1444 (or isearch-success (setq ellipsis nil)) | |
1445 ;; #### - ! Emacs assembles strings all over the place, they can't | |
1446 ;; all be internationalized in the manner proposed below... Add an | |
1447 ;; explicit call to `gettext' and have the string snarfer pluck the | |
1448 ;; english strings out of the comment below. XEmacs is on a | |
1449 ;; purespace diet! -Stig | |
1450 | |
1451 ;; The comment below is dead and buried, but it can be rebuilt if | |
1452 ;; necessary. -hniksic | |
1453 (let ((m (concat (if isearch-success nil "failing ") | |
1454 (if (and isearch-wrapped | |
1455 (if isearch-forward | |
1456 (> (point) isearch-opoint) | |
1457 (< (point) isearch-opoint))) | |
1458 "overwrapped " | |
1459 (if isearch-wrapped "wrapped ")) | |
1460 (if isearch-word "word ") | |
1461 (if isearch-regexp "regexp ") | |
1462 (if nonincremental "search" "I-search") | |
1463 (if isearch-forward nil " backward") | |
1464 ": " | |
1465 ))) | |
1466 (aset m 0 (upcase (aref m 0))) | |
1467 (gettext m))) | |
1468 | |
1469 (defun isearch-message-suffix (&optional c-q-hack ellipsis) | |
1470 (concat (if c-q-hack "^Q" "") | |
1471 (if isearch-invalid-regexp | |
1472 (concat " [" isearch-invalid-regexp "]") | |
1473 ""))) | |
1474 | |
1475 ;;;(let ((i (logior (if isearch-success 32 0) | |
1476 ;;; (if isearch-wrapped 16 0) | |
1477 ;;; (if isearch-word 8 0) | |
1478 ;;; (if isearch-regexp 4 0) | |
1479 ;;; (if nonincremental 2 0) | |
1480 ;;; (if isearch-forward 1 0)))) | |
1481 ;;; (cond | |
1482 ;;; ((= i 63) (gettext "Wrapped word regexp search: ")) ; 111111 | |
1483 ;;; ...and so on, ad nauseam... | |
1484 ;;; ((= i 0) (gettext "Failing I-search backward: ")) ; 000000 | |
1485 ;;; (t (error "Something's rotten"))))) | |
1486 | |
1487 | |
1488 ;;;======================================================== | |
1489 ;;; Exiting | |
1490 | |
1491 (put 'isearch-printing-char 'isearch-command t) | |
1492 (put 'isearch-return-char 'isearch-command t) | |
1493 (put 'isearch-repeat-forward 'isearch-command t) | |
1494 (put 'isearch-repeat-backward 'isearch-command t) | |
1495 (put 'isearch-delete-char 'isearch-command t) | |
1496 (put 'isearch-help-or-delete-char 'isearch-command t) | |
1497 (put 'isearch-cancel 'isearch-command t) | |
1498 (put 'isearch-abort 'isearch-command t) | |
1499 (put 'isearch-quote-char 'isearch-command t) | |
1500 (put 'isearch-exit 'isearch-command t) | |
1501 (put 'isearch-printing-char 'isearch-command t) | |
1502 (put 'isearch-printing-char 'isearch-command t) | |
1503 (put 'isearch-yank-word 'isearch-command t) | |
1504 (put 'isearch-yank-line 'isearch-command t) | |
1505 (put 'isearch-yank-kill 'isearch-command t) | |
1506 (put 'isearch-yank-sexp 'isearch-command t) | |
1507 (put 'isearch-*-char 'isearch-command t) | |
1508 (put 'isearch-*-char 'isearch-command t) | |
1509 (put 'isearch-|-char 'isearch-command t) | |
1510 (put 'isearch-toggle-regexp 'isearch-command t) | |
1511 (put 'isearch-toggle-case-fold 'isearch-command t) | |
1512 (put 'isearch-edit-string 'isearch-command t) | |
1513 (put 'isearch-mode-help 'isearch-command t) | |
1514 (put 'isearch-ring-advance 'isearch-command t) | |
1515 (put 'isearch-ring-retreat 'isearch-command t) | |
1516 (put 'isearch-ring-advance-edit 'isearch-command t) | |
1517 (put 'isearch-ring-retreat-edit 'isearch-command t) | |
1518 (put 'isearch-whitespace-chars 'isearch-command t) | |
1519 (put 'isearch-complete 'isearch-command t) | |
1520 (put 'isearch-complete-edit 'isearch-command t) | |
1521 (put 'isearch-edit-string 'isearch-command t) | |
1522 (put 'isearch-toggle-regexp 'isearch-command t) | |
1523 (put 'isearch-forward-exit-minibuffer 'isearch-command t) | |
1524 (put 'isearch-reverse-exit-minibuffer 'isearch-command t) | |
1525 (put 'isearch-nonincremental-exit-minibuffer 'isearch-command t) | |
1526 (put 'isearch-yank-selection 'isearch-command t) | |
1527 (put 'isearch-yank-clipboard 'isearch-command t) | |
1528 (put 'isearch-yank-x-selection 'isearch-command t) | |
1529 (put 'isearch-yank-x-clipboard 'isearch-command t) | |
1530 | |
1531 ;; scrolling the scrollbar should not terminate isearch. | |
1532 | |
1533 ;; vertical scrollbar: | |
1534 (put 'scrollbar-line-up 'isearch-command t) | |
1535 (put 'scrollbar-line-down 'isearch-command t) | |
1536 (put 'scrollbar-page-up 'isearch-command t) | |
1537 (put 'scrollbar-page-down 'isearch-command t) | |
1538 (put 'scrollbar-to-top 'isearch-command t) | |
1539 (put 'scrollbar-to-bottom 'isearch-command t) | |
1540 (put 'scrollbar-vertical-drag 'isearch-command t) | |
1541 | |
1542 ;; horizontal scrollbar: | |
1543 (put 'scrollbar-char-left 'isearch-command t) | |
1544 (put 'scrollbar-char-right 'isearch-command t) | |
1545 (put 'scrollbar-page-left 'isearch-command t) | |
1546 (put 'scrollbar-page-right 'isearch-command t) | |
1547 (put 'scrollbar-to-left 'isearch-command t) | |
1548 (put 'scrollbar-to-right 'isearch-command t) | |
1549 (put 'scrollbar-horizontal-drag 'isearch-command t) | |
1550 | |
1551 (defun isearch-pre-command-hook () | |
1552 ;; | |
1553 ;; For use as the value of `pre-command-hook' when isearch-mode is active. | |
1554 ;; If the command about to be executed is not one of the isearch commands, | |
1555 ;; then isearch-mode is turned off before that command is executed. | |
1556 ;; | |
1557 ;; If the command about to be executed is self-insert-command, or is a | |
1558 ;; keyboard macro of a single key sequence which is bound to self-insert- | |
1559 ;; command, then we add those chars to the search ring instead of inserting | |
1560 ;; them in the buffer. In this way, the set of self-searching characters | |
1561 ;; need not be exhaustively enumerated, but is derived from other maps. | |
1562 ;; | |
1563 (cond ((not (eq (current-buffer) isearch-buffer)) | |
1564 ;; If the buffer (likely meaning "frame") has changed, bail. | |
1565 ;; This can happen if the user types something into another | |
1566 ;; frame. It can also happen if a proc filter has popped up | |
1567 ;; another buffer, which is arguably a bad thing for it to | |
1568 ;; have done, but the way in which isearch would have hosed | |
1569 ;; you in that case is unarguably even worse. -jwz | |
1570 (isearch-done) | |
1571 | |
1572 ;; `this-command' is set according to the value of | |
1573 ;; `overriding-local-map', set by isearch-mode. This is | |
1574 ;; wrong because that keymap makes sense only in isearch | |
1575 ;; buffer. To make sure the right command is called, adjust | |
1576 ;; `this-command' to the appropriate value, now that | |
1577 ;; `isearch-done' has set `overriding-local-map' to nil. | |
1578 | |
1579 ;; FSF does similar magic in `isearch-other-meta-char', which | |
1580 ;; is horribly complex. I *hope* what we do works in all | |
1581 ;; cases. | |
1582 (setq this-command (key-binding (this-command-keys)))) | |
1583 (t | |
5655
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1584 (labels |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1585 ((isearch-maybe-frob-keyboard-macros () |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1586 ;; If the command about to be executed is |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1587 ;; `self-insert-command' then change the command to |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1588 ;; `isearch-printing-char' instead, meaning add the last- |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1589 ;; typed character to the search string. |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1590 ;; |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1591 ;; If `this-command' is a string or a vector (that is, a |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1592 ;; keyboard macro) and it contains only one command, which is |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1593 ;; bound to self-insert-command, then do the same thing as for |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1594 ;; self-inserting commands: arrange for that character to be |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1595 ;; added to the search string. If we didn't do this, then |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1596 ;; typing a compose sequence (a la x-compose.el) would |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1597 ;; terminate the search and insert the character, instead of |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1598 ;; searching for that character. |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1599 ;; |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1600 ;; We should continue doing this, since it's pretty much the |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1601 ;; behavior one would expect, but it will stop being so |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1602 ;; necessary once key-translation- map exists and is used by |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1603 ;; x-compose.el and things like it, since the translation will |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1604 ;; have been done before we see the keys. |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1605 ;; |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1606 (cond ((eq this-command 'self-insert-command) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1607 (setq this-command 'isearch-printing-char)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1608 ((and (or (stringp this-command) (vectorp this-command)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1609 (eq (key-binding this-command) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1610 'self-insert-command)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1611 (setq last-command-event |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1612 (character-to-event (aref this-command 0)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1613 last-command-char (and (stringp this-command) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1614 (aref this-command 0)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1615 this-command 'isearch-printing-char)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1616 ((and (null this-command) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1617 (eq 'key-press (event-type last-command-event)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1618 (current-local-map) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1619 (let* ((this-command-keys (this-command-keys)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1620 (this-command-keys (or (lookup-key |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1621 function-key-map |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1622 this-command-keys) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1623 this-command-keys)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1624 (lookup-key (lookup-key global-map |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1625 this-command-keys))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1626 (and (eq 'self-insert-command lookup-key) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1627 ;; The feature here that a modification |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1628 ;; of last-command-event is respected is |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1629 ;; undocumented, and only applies when |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1630 ;; this-command is nil. The design isn't |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1631 ;; great, and I welcome suggestions for a |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1632 ;; better one. |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1633 (setq last-command-event |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1634 (find-if 'key-press-event-p |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1635 this-command-keys |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1636 :from-end t) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1637 last-command-char |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1638 (event-to-character |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1639 last-command-event) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1640 this-command |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1641 'isearch-printing-char)))))))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1642 (isearch-maybe-frob-keyboard-macros) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1643 (if (and this-command |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1644 (symbolp this-command) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1645 (get this-command 'isearch-command)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1646 nil ; then continue. |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1647 (isearch-done)))))) |
428 | 1648 |
1649 ;;;======================================================== | |
1650 ;;; Highlighting | |
1651 | |
1652 (defvar isearch-extent nil) | |
1653 | |
1654 ;; this face is initialized by faces.el since isearch is preloaded. | |
1655 ;(make-face 'isearch) | |
1656 | |
1657 (defun isearch-highlight (begin end) | |
5655
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1658 (labels |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1659 ((isearch-make-extent (begin end) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1660 (let ((x (make-extent begin end (current-buffer)))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1661 ;; make the isearch extent always take precedence over any mouse- |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1662 ;; highlighted extents we may be passing through, since isearch, |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1663 ;; being modal, is more interesting (there's nothing they could do |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1664 ;; with a mouse-highlighted extent while in the midst of a search |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1665 ;; anyway). |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1666 (set-extent-priority x (+ mouse-highlight-priority 2)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1667 (set-extent-face x 'isearch) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1668 (setq isearch-extent x)))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1669 (if (null search-highlight) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1670 nil |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1671 ;; make sure isearch-extent is in the current buffer |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1672 (or (and (extentp isearch-extent) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1673 (extent-live-p isearch-extent)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1674 (isearch-make-extent begin end)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1675 (set-extent-endpoints isearch-extent begin end (current-buffer))))) |
428 | 1676 |
1677 ;; This used to have a TOTALLY flag that also deleted the extent. I | |
1678 ;; don't think this is necessary any longer, as isearch-highlight can | |
1679 ;; simply move the extent to another buffer. The IGNORED argument is | |
1680 ;; for the code that calls this function with an argument. --hniksic | |
1681 (defun isearch-dehighlight (&optional ignored) | |
1682 (and search-highlight | |
1683 (extentp isearch-extent) | |
1684 (extent-live-p isearch-extent) | |
1685 (detach-extent isearch-extent))) | |
1686 | |
1687 | |
1688 ;;;======================================================== | |
1689 ;;; Searching | |
1690 | |
1691 (defun isearch-search () | |
1692 ;; Do the search with the current search string. | |
1693 (isearch-message nil t) | |
1694 (isearch-fix-case) | |
1695 (condition-case lossage | |
1696 (let ((inhibit-quit nil) | |
1697 (case-fold-search isearch-case-fold-search) | |
1698 (retry t)) | |
1699 (if isearch-regexp (setq isearch-invalid-regexp nil)) | |
1700 (setq isearch-within-brackets nil) | |
1701 (while retry | |
1702 (setq isearch-success | |
1703 (funcall | |
1704 (cond (isearch-word | |
1705 (if isearch-forward | |
1706 'word-search-forward 'word-search-backward)) | |
1707 (isearch-regexp | |
1708 (if isearch-forward | |
1709 're-search-forward 're-search-backward)) | |
1710 (t | |
1711 (if isearch-forward 'search-forward 'search-backward))) | |
1712 isearch-string nil t)) | |
1713 ;; Clear RETRY unless we matched some invisible text | |
1714 ;; and we aren't supposed to do that. | |
1715 (if (or (eq search-invisible t) | |
1716 (not isearch-success) | |
1717 (bobp) (eobp) | |
1718 (= (match-beginning 0) (match-end 0)) | |
1719 (not (isearch-range-invisible | |
1720 (match-beginning 0) (match-end 0)))) | |
1721 (setq retry nil))) | |
1722 (setq isearch-just-started nil) | |
1723 (when isearch-success | |
1724 (setq isearch-other-end | |
1725 (if isearch-forward (match-beginning 0) (match-end 0))) | |
1726 (and isearch-hide-immediately | |
1727 (isearch-restore-invisible-extents (match-beginning 0) | |
1728 (match-end 0))))) | |
1729 | |
1730 (quit (setq unread-command-events (nconc unread-command-events | |
1731 (character-to-event (quit-char)))) | |
1732 (setq isearch-success nil)) | |
1733 | |
1734 (invalid-regexp | |
1735 (setq isearch-invalid-regexp (car (cdr lossage))) | |
1736 (setq isearch-within-brackets (string-match "\\`Unmatched \\[" | |
1737 isearch-invalid-regexp)) | |
1738 (if (string-match | |
1739 "\\`Premature \\|\\`Unmatched \\|\\`Invalid " | |
1740 isearch-invalid-regexp) | |
1741 (setq isearch-invalid-regexp (gettext "incomplete input")))) | |
1742 (error | |
1743 ;; stack overflow in regexp search. | |
1744 (setq isearch-invalid-regexp (car (cdr lossage))))) | |
1745 | |
1746 (if isearch-success | |
1747 nil | |
1748 | |
1749 ;; If we're being run inside a keyboard macro, then the call to | |
1750 ;; ding will signal an error (to terminate the macro). We must | |
1751 ;; turn off isearch-mode first, so that we aren't still in isearch | |
1752 ;; mode after the macro exits. Note that isearch-recursive-edit | |
1753 ;; must not be true if a keyboard macro is executing. | |
1754 (if (and executing-kbd-macro (not defining-kbd-macro)) | |
1755 (progn | |
1756 (isearch-done) | |
1757 (ding nil 'isearch-failed))) | |
1758 | |
1759 ;; Ding if failed this time after succeeding last time. | |
1760 (and (nth 3 (car isearch-cmds)) | |
1761 (ding nil 'isearch-failed)) | |
1762 (goto-char (nth 2 (car isearch-cmds))))) | |
1763 | |
1764 ;; Replaced with isearch-edit-string. | |
1765 ;(defun nonincremental-search (forward regexp) | |
1766 ;... | |
1767 | |
1768 (defun isearch-unhide-extent (extent) | |
1769 ;; Store the values for the `invisible' and `intangible' | |
1770 ;; properties, and then set them to nil. This way the text hidden | |
1771 ;; by this extent becomes visible. | |
1772 (put extent 'isearch-invisible (get extent 'invisible)) | |
1773 (put extent 'isearch-intangible (get extent 'intangible)) | |
1774 (put extent 'invisible nil) | |
1775 (put extent 'intangible nil)) | |
1776 | |
444 | 1777 (defun isearch-range-invisible (start end) |
1778 "Return t if all the text from START to END is invisible. | |
428 | 1779 Before that, if search-invisible is `open', unhide the extents with an |
1780 `isearch-open-invisible' property." | |
1781 ;; isearch-search uses this to skip the extents that are invisible, | |
1782 ;; but don't have `isearch-open-invisible' set. It is unclear | |
444 | 1783 ;; what's supposed to happen if only a part of [START, END) overlaps |
428 | 1784 ;; the extent. |
1785 (let (to-be-unhidden) | |
1786 (if (map-extents | |
1787 (lambda (extent ignored) | |
444 | 1788 (if (and (<= (extent-start-position extent) start) |
428 | 1789 (>= (extent-end-position extent) end)) |
1790 ;; All of the region is covered by the extent. | |
1791 (if (and (eq search-invisible 'open) | |
1792 (get extent 'isearch-open-invisible)) | |
1793 (progn | |
1794 (push extent to-be-unhidden) | |
1795 nil) ; keep mapping | |
1796 ;; We can't or won't unhide this extent, so we must | |
1797 ;; skip the whole match. We return from map-extents | |
1798 ;; immediately. | |
1799 t) | |
1800 ;; Else, keep looking. | |
1801 nil)) | |
444 | 1802 nil start end nil 'all-extents-closed 'invisible) |
428 | 1803 ;; The whole match must be skipped. Signal it by returning t |
1804 ;; to the caller. | |
1805 t | |
1806 ;; If any extents need to be unhidden, unhide them. | |
1807 (mapc #'isearch-unhide-extent to-be-unhidden) | |
1808 ;; Will leave this assert for some time, to catch bugs. | |
1809 (assert (null (intersection to-be-unhidden isearch-unhidden-extents))) | |
1810 (setq isearch-unhidden-extents (nconc to-be-unhidden | |
1811 isearch-unhidden-extents)) | |
1812 nil))) | |
1813 | |
1814 (defun isearch-restore-extent (extent) | |
1815 (put extent 'invisible (get extent 'isearch-invisible)) | |
1816 (put extent 'intangible (get extent 'isearch-intangible)) | |
1817 (remprop extent 'isearch-invisible) | |
1818 (remprop extent 'isearch-intangible)) | |
1819 | |
1820 ;; FSF calls this function `isearch-clean-overlays'. | |
444 | 1821 (defun isearch-restore-invisible-extents (start end) |
428 | 1822 (cond |
444 | 1823 ((null start) |
428 | 1824 ;; Delete all -- this is called at the end of isearch. |
1825 (mapc #'isearch-restore-extent isearch-unhidden-extents) | |
1826 (setq isearch-unhidden-extents nil)) | |
1827 (t | |
1828 ;; Extents that do not overlap the match area can be safely | |
1829 ;; restored to their hidden state. | |
1830 (setq isearch-unhidden-extents | |
1831 (delete-if (lambda (extent) | |
444 | 1832 (unless (extent-in-region-p extent start end |
428 | 1833 'all-extents-closed) |
1834 (isearch-restore-extent extent) | |
1835 t)) | |
1836 isearch-unhidden-extents))))) | |
1837 | |
1838 (defun isearch-no-upper-case-p (string) | |
1839 "Return t if there are no upper case chars in string. | |
1840 But upper case chars preceded by \\ do not count since they | |
1841 have special meaning in a regexp." | |
1842 ;; this incorrectly returns t for "\\\\A" | |
1843 (let ((case-fold-search nil)) | |
1844 (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string)))) | |
1845 (make-obsolete 'isearch-no-upper-case-p 'no-upper-case-p) | |
1846 | |
1847 ;; Portability functions to support various Emacs versions. | |
1848 | |
1849 (defun isearch-char-to-string (c) | |
1850 (if (eventp c) | |
2828 | 1851 (make-string 1 (event-to-character c)) |
428 | 1852 (make-string 1 c))) |
1853 | |
1854 ;(defun isearch-text-char-description (c) | |
1855 ; (isearch-char-to-string c)) | |
1856 | |
1857 (define-function 'isearch-text-char-description 'text-char-description) | |
1858 | |
1859 ;; Used by etags.el and info.el | |
1860 (defmacro with-caps-disable-folding (string &rest body) "\ | |
1861 Eval BODY with `case-fold-search' let to nil if STRING contains | |
1862 uppercase letters and `search-caps-disable-folding' is t." | |
1863 `(let ((case-fold-search | |
1864 (if (and case-fold-search search-caps-disable-folding) | |
1865 (isearch-no-upper-case-p ,string) | |
1866 case-fold-search))) | |
1867 ,@body)) | |
1868 (make-obsolete 'with-caps-disable-folding 'with-search-caps-disable-folding) | |
1869 (put 'with-caps-disable-folding 'lisp-indent-function 1) | |
1870 (put 'with-caps-disable-folding 'edebug-form-spec '(form body)) | |
1871 | |
1872 | |
1873 ;;;======================================================== | |
1874 ;;; Advanced highlighting | |
1875 | |
1876 ;; When active, *every* visible match for the current search string is | |
1877 ;; highlighted: the current one using the normal isearch match color | |
1878 ;; and all the others using the `isearch-secondary' face. The extra | |
1879 ;; highlighting makes it easier to anticipate where the cursor will | |
1880 ;; land each time you press C-s or C-r to repeat a pending search. | |
1881 ;; Only the matches visible at any point are highlighted -- when you | |
1882 ;; move through the buffer, the highlighting is readjusted. | |
1883 | |
1884 ;; This is based on ideas from Bob Glickstein's `ishl' package. It | |
1885 ;; has been merged with XEmacs by Darryl Okahata, and then completely | |
1886 ;; rewritten by Hrvoje Niksic. | |
1887 | |
1888 ;; The code makes the following assumptions about the rest of this | |
1889 ;; file, so be careful when modifying it. | |
1890 | |
1891 ;; * `isearch-highlight-all-update' should get called when the search | |
1892 ;; string changes, or when the search advances. This is done from | |
1893 ;; `isearch-update'. | |
1894 ;; * `isearch-highlight-all-cleanup' should get called when the search | |
1895 ;; is done. This is performed in `isearch-done'. | |
1896 ;; * `isearch-string' is expected to contain the current search string | |
1897 ;; as entered by the user. | |
1898 ;; * `isearch-opoint' is expected to contain the location where the | |
1899 ;; current search began. | |
1900 ;; * the type of the current search is expected to be given by | |
1901 ;; `isearch-word' and `isearch-regexp'. | |
1902 ;; * the variable `isearch-invalid-regexp' is expected to be true iff | |
1903 ;; `isearch-string' is an invalid regexp. | |
1904 | |
1905 (defcustom isearch-highlight-all-matches search-highlight | |
1906 "*Non-nil means highlight all visible matches." | |
1907 :type 'boolean | |
1908 :group 'isearch) | |
1909 | |
1910 ;; We can't create this face here, as isearch.el is preloaded. | |
1911 ;; #### Think up a better name for this! | |
1912 ;(defface isearch-secondary '((t (:foreground "red3"))) | |
1913 ; "Face to use for highlighting all matches." | |
1914 ; :group 'isearch) | |
1915 | |
1916 (defvar isearch-highlight-extents nil) | |
1917 (defvar isearch-window-start nil) | |
1918 (defvar isearch-window-end nil) | |
1919 ;; We compare isearch-string and isearch-case-fold-search to saved | |
1920 ;; values for better efficiency. | |
1921 (defvar isearch-highlight-last-string nil) | |
1922 (defvar isearch-highlight-last-case-fold-search nil) | |
1923 (defvar isearch-highlight-last-regexp nil) | |
1924 | |
1925 (defun isearch-delete-extents-in-range (start end) | |
1926 ;; Delete all highlighting extents that overlap [START, END). | |
1927 (setq isearch-highlight-extents | |
1928 (delete-if (lambda (extent) | |
1929 (when (extent-in-region-p extent start end) | |
1930 (delete-extent extent) | |
1931 t)) | |
1932 isearch-highlight-extents))) | |
1933 | |
1934 (defun isearch-highlight-all-cleanup () | |
1935 ;; Stop lazily highlighting and remove extra highlighting from | |
1936 ;; buffer. | |
1937 (mapc #'delete-extent isearch-highlight-extents) | |
1938 (setq isearch-highlight-extents nil) | |
442 | 1939 (setq isearch-window-end nil |
428 | 1940 isearch-highlight-last-string nil)) |
1941 | |
1942 (defun isearch-highlight-all-update () | |
1943 ;; Update the highlighting if necessary. This needs to check if the | |
1944 ;; search string has changed, or if the window has changed position | |
1945 ;; in the buffer. | |
1946 (let ((need-start-over nil)) | |
1947 ;; NB: we don't check for isearch-success because if the point is | |
1948 ;; after the last match, the search can be unsuccessful, and yet | |
1949 ;; there are things to highlight. | |
1950 (cond ((not isearch-highlight-all-matches)) | |
1951 ((or (equal isearch-string "") | |
1952 isearch-invalid-regexp) | |
1953 (isearch-highlight-all-cleanup)) | |
1954 ((not (eq isearch-case-fold-search | |
1955 isearch-highlight-last-case-fold-search)) | |
1956 ;; This case is usually caused by search string being | |
1957 ;; changed, which would be caught below, but it can also be | |
1958 ;; tripped using isearch-toggle-case-fold. | |
1959 (setq need-start-over t)) | |
1960 ((not (eq isearch-regexp isearch-highlight-last-regexp)) | |
1961 ;; Ditto for isearch-toggle-regexp. | |
1962 (setq need-start-over t)) | |
1963 ((equal isearch-string isearch-highlight-last-string) | |
1964 ;; The search string is the same. We need to do something | |
1965 ;; if our position has changed. | |
1966 | |
1967 ;; It would be nice if we didn't have to do this; however, | |
1968 ;; window-start doesn't support a GUARANTEE flag, so we must | |
440 | 1969 ;; force redisplay to get the correct value for start and end |
428 | 1970 ;; of window. |
1971 (sit-for 0) | |
1972 | |
1973 ;; Check whether our location has changed. | |
1974 (let ((start (window-start)) | |
1975 (end (min (window-end) (point-max)))) | |
1976 (cond ((and (= start isearch-window-start) | |
1977 (= end isearch-window-end)) | |
1978 ;; Our position is unchanged -- do nothing. | |
1979 ) | |
1980 ((and (> start isearch-window-start) | |
1981 (> end isearch-window-end) | |
1982 (<= start isearch-window-end)) | |
1983 ;; We've migrated downward, 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 isearch-window-start start) | |
1987 (isearch-highlightify-region isearch-window-end end) | |
1988 (setq isearch-window-start start | |
1989 isearch-window-end end)) | |
1990 ((and (<= start isearch-window-start) | |
1991 (<= end isearch-window-end) | |
1992 (> end isearch-window-start)) | |
1993 ;; We've migrated upward, but we overlap the old | |
1994 ;; region. Delete the old non-overlapping extents | |
1995 ;; and fill in the rest. | |
1996 (isearch-delete-extents-in-range | |
1997 end isearch-window-end) | |
1998 (isearch-highlightify-region start isearch-window-start) | |
1999 (setq isearch-window-start start | |
2000 isearch-window-end end)) | |
2001 (t | |
2002 ;; The regions don't overlap, or they overlap in a | |
2003 ;; weird way. | |
2004 (setq need-start-over t))))) | |
2005 (t | |
2006 ;; The search string has changed. | |
2007 | |
2008 ;; If more input is pending, don't start over because | |
2009 ;; starting over forces redisplay, and that slows down | |
2010 ;; typing. | |
2011 (unless (input-pending-p) | |
2012 (setq need-start-over t)))) | |
2013 (when need-start-over | |
2014 ;; Force redisplay before removing the old extents, in order to | |
2015 ;; avoid flicker. | |
2016 (sit-for 0) | |
2017 (isearch-highlight-all-cleanup) | |
2018 (setq isearch-window-start (window-start) | |
2019 isearch-window-end (min (window-end) (point-max))) | |
2020 (isearch-highlightify-region isearch-window-start isearch-window-end)) | |
2021 | |
2022 (setq isearch-highlight-last-string isearch-string | |
2023 isearch-highlight-last-case-fold-search isearch-case-fold-search | |
2024 isearch-highlight-last-regexp isearch-regexp))) | |
2025 | |
2026 (defun isearch-highlight-advance (string forwardp) | |
2027 ;; Search ahead for the next or previous match. This is the same as | |
2028 ;; isearch-search, but without the extra baggage. Maybe it should | |
2029 ;; be in a separate function. | |
2030 (let ((case-fold-search isearch-case-fold-search)) | |
2031 (funcall (cond (isearch-word (if forwardp | |
2032 'word-search-forward | |
2033 'word-search-backward)) | |
2034 (isearch-regexp (if forwardp | |
2035 're-search-forward | |
2036 're-search-backward)) | |
2037 (t (if forwardp | |
2038 'search-forward | |
2039 'search-backward))) | |
2040 string nil t))) | |
2041 | |
2042 (defun isearch-highlightify-region (start end) | |
2043 ;; Highlight all occurrences of isearch-string between START and | |
2044 ;; END. To do this right, we have to search forward as long as | |
2045 ;; there are matches that overlap [START, END), and then search | |
2046 ;; backward the same way. | |
2047 (save-excursion | |
2048 (goto-char isearch-opoint) | |
2049 (let ((lastpoint (point))) | |
2050 (while (and (isearch-highlight-advance isearch-string t) | |
2051 (/= lastpoint (point)) | |
2052 (< (match-beginning 0) end)) | |
2053 (let ((extent (make-extent (match-beginning 0) | |
2054 (match-end 0)))) | |
2055 (set-extent-priority extent (1+ mouse-highlight-priority)) | |
2056 (put extent 'face 'isearch-secondary) | |
2057 (push extent isearch-highlight-extents)) | |
2058 (setq lastpoint (point)))) | |
2059 (goto-char isearch-opoint) | |
2060 (let ((lastpoint (point))) | |
2061 (while (and (isearch-highlight-advance isearch-string nil) | |
2062 (/= lastpoint (point)) | |
2063 (>= (match-end 0) start)) | |
2064 (let ((extent (make-extent (match-beginning 0) | |
2065 (match-end 0)))) | |
2066 (set-extent-priority extent (1+ mouse-highlight-priority)) | |
2067 (put extent 'face 'isearch-secondary) | |
2068 (push extent isearch-highlight-extents)) | |
2069 (setq lastpoint (point)))))) | |
2070 | |
2071 ;;; isearch-mode.el ends here |