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