2233
|
1 ;;; isearch.el --- incremental search minor mode.
|
2230
|
2
|
17637
|
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
|
846
|
4
|
2230
|
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
|
11969
|
6 ;; Maintainer: FSF
|
725
|
7
|
4839
|
8 ;; This file is part of GNU Emacs.
|
725
|
9
|
6736
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
725
|
14
|
6736
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
14169
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
725
|
24
|
2230
|
25 ;;; Commentary:
|
|
26
|
725
|
27 ;; Instructions
|
|
28
|
1142
|
29 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
|
|
30 ;; isearch-mode behaves modally and does not return until the search
|
|
31 ;; is completed. It uses a recursive-edit to behave this way. Note:
|
|
32 ;; gnus does it wrong: (call-interactively 'isearch-forward).
|
|
33
|
725
|
34 ;; The key bindings active within isearch-mode are defined below in
|
1142
|
35 ;; `isearch-mode-map' which is given bindings close to the default
|
|
36 ;; characters of the original isearch.el. With `isearch-mode',
|
|
37 ;; however, you can bind multi-character keys and it should be easier
|
|
38 ;; to add new commands. One bug though: keys with meta-prefix cannot
|
|
39 ;; be longer than two chars. Also see minibuffer-local-isearch-map
|
|
40 ;; for bindings active during `isearch-edit-string'.
|
725
|
41
|
1142
|
42 ;; Note to emacs version 19 users: isearch-mode should work even if
|
|
43 ;; you switch windows with the mouse, in which case isearch-mode is
|
|
44 ;; terminated automatically before the switch. This is true of lemacs
|
|
45 ;; too, with a few more cleanups I've neglected in this release.
|
|
46 ;; No one has supplied patches for epoch yet.
|
725
|
47
|
1142
|
48 ;; The search ring and completion commands automatically put you in
|
|
49 ;; the minibuffer to edit the string. This gives you a chance to
|
|
50 ;; modify the search string before executing the search. There are
|
|
51 ;; three commands to terminate the editing: C-s and C-r exit the
|
|
52 ;; minibuffer and search forward and reverse respectively, while C-m
|
|
53 ;; exits and does a nonincremental search.
|
|
54
|
|
55 ;; Exiting immediately from isearch uses isearch-edit-string instead
|
|
56 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
|
|
57 ;; The name of this option should probably be changed if we decide to
|
|
58 ;; keep the behavior. No point in forcing nonincremental search until
|
|
59 ;; the last possible moment.
|
|
60
|
|
61 ;; TODO
|
3591
|
62 ;; - Integrate the emacs 19 generalized command history.
|
1142
|
63 ;; - Think about incorporating query-replace.
|
|
64 ;; - Hooks and options for failed search.
|
792
|
65
|
2230
|
66 ;;; Change Log:
|
|
67
|
14169
|
68 ;; Changes before those recorded in ChangeLog:
|
792
|
69
|
14169
|
70 ;; Revision 1.4 92/09/14 16:26:02 liberte
|
|
71 ;; Added prefix args to isearch-forward, etc. to switch between
|
|
72 ;; string and regular expression searching.
|
|
73 ;; Added some support for lemacs.
|
|
74 ;; Added general isearch-highlight option - but only for lemacs so far.
|
|
75 ;; Added support for frame switching in emacs 19.
|
|
76 ;; Added word search option to isearch-edit-string.
|
|
77 ;; Renamed isearch-quit to isearch-abort.
|
|
78 ;; Numerous changes to comments and doc strings.
|
|
79 ;;
|
|
80 ;; Revision 1.3 92/06/29 13:10:08 liberte
|
|
81 ;; Moved modal isearch-mode handling into isearch-mode.
|
|
82 ;; Got rid of buffer-local isearch variables.
|
|
83 ;; isearch-edit-string used by ring adjustments, completion, and
|
|
84 ;; nonincremental searching. C-s and C-r are additional exit commands.
|
|
85 ;; Renamed all regex to regexp.
|
|
86 ;; Got rid of found-start and found-point globals.
|
|
87 ;; Generalized handling of upper-case chars.
|
792
|
88
|
14169
|
89 ;; Revision 1.2 92/05/27 11:33:57 liberte
|
|
90 ;; Emacs version 19 has a search ring, which is supported here.
|
|
91 ;; Other fixes found in the version 19 isearch are included here.
|
|
92 ;;
|
|
93 ;; Also see variables search-caps-disable-folding,
|
|
94 ;; search-nonincremental-instead, search-whitespace-regexp, and
|
|
95 ;; commands isearch-toggle-regexp, isearch-edit-string.
|
|
96 ;;
|
|
97 ;; semi-modal isearching is supported.
|
|
98
|
|
99 ;; Changes for 1.1
|
|
100 ;; 3/18/92 Fixed invalid-regexp.
|
|
101 ;; 3/18/92 Fixed yanking in regexps.
|
792
|
102
|
2230
|
103 ;;; Code:
|
1142
|
104
|
|
105
|
9935
|
106 ;;; Some additional options and constants.
|
1142
|
107
|
17637
|
108 (defgroup isearch nil
|
|
109 "Incremental search minor mode."
|
|
110 :prefix "isearch-"
|
|
111 :prefix "search-"
|
|
112 :group 'matching)
|
|
113
|
725
|
114
|
17637
|
115 (defcustom search-exit-option t
|
|
116 "*Non-nil means random control characters terminate incremental search."
|
|
117 :type 'boolean
|
|
118 :group 'isearch)
|
|
119
|
|
120 (defcustom search-slow-window-lines 1
|
1143
|
121 "*Number of lines in slow search display windows.
|
|
122 These are the short windows used during incremental search on slow terminals.
|
|
123 Negative means put the slow search window at the top (normally it's at bottom)
|
17637
|
124 and the value is minus the number of lines."
|
|
125 :type 'integer
|
|
126 :group 'isearch)
|
725
|
127
|
17637
|
128 (defcustom search-slow-speed 1200
|
1143
|
129 "*Highest terminal speed at which to use \"slow\" style incremental search.
|
|
130 This is the style where a one-line window is created to show the line
|
17637
|
131 that the search has reached."
|
|
132 :type 'integer
|
|
133 :group 'isearch)
|
725
|
134
|
17637
|
135 (defcustom search-upper-case 'not-yanks
|
725
|
136 "*If non-nil, upper case chars disable case fold searching.
|
1142
|
137 That is, upper and lower case chars must match exactly.
|
|
138 This applies no matter where the chars come from, but does not
|
1143
|
139 apply to chars in regexps that are prefixed with `\\'.
|
17637
|
140 If this value is `not-yanks', yanked text is always downcased."
|
|
141 :type '(choice (const :tag "off" nil)
|
|
142 (const not-yanks)
|
|
143 (sexp :tag "on" :format "%t\n" t))
|
|
144 :group 'isearch)
|
725
|
145
|
17637
|
146 (defcustom search-nonincremental-instead t
|
725
|
147 "*If non-nil, do a nonincremental search instead if exiting immediately.
|
1142
|
148 Actually, `isearch-edit-string' is called to let you enter the search
|
17637
|
149 string, and RET terminates editing and does a nonincremental search."
|
|
150 :type 'boolean
|
|
151 :group 'isearch)
|
725
|
152
|
17637
|
153 (defcustom search-whitespace-regexp "\\s-+"
|
725
|
154 "*If non-nil, regular expression to match a sequence of whitespace chars.
|
19769
|
155 This applies to regular expression incremental search.
|
17637
|
156 You might want to use something like \"[ \\t\\r\\n]+\" instead."
|
|
157 :type 'regexp
|
|
158 :group 'isearch)
|
725
|
159
|
18037
|
160 (defcustom search-highlight t
|
17637
|
161 "*Non-nil means incremental search highlights the current match."
|
|
162 :type 'boolean
|
|
163 :group 'isearch)
|
1142
|
164
|
18236
|
165 (defcustom search-invisible 'open
|
|
166 "If t incremental search can match hidden text.
|
|
167 nil means don't match invisible text.
|
|
168 If the value is `open', if the text matched is made invisible by
|
|
169 an overlay having an `invisible' property and that overlay has a property
|
|
170 `isearch-open-invisible', then incremental search will show the contents.
|
|
171 \(This applies when using `outline.el' and `hideshow.el'.)"
|
|
172 :type '(choice (const :tag "Match hidden text" t)
|
|
173 (const :tag "Open overlays" open)
|
18866
|
174 (const :tag "Don't match hidden text" nil))
|
18236
|
175 :group 'isearch)
|
|
176
|
|
177 (defcustom isearch-hide-immediately t
|
19069
|
178 "If non-nil, re-hide an invisible match right away.
|
|
179 This variable makes a difference when `search-invisible' is set to `open'.
|
|
180 It means that after search makes some invisible text visible
|
|
181 to show the match, it makes the text invisible again when the match moves.
|
|
182 Ordinarily the text becomes invisible again at the end of the search."
|
18236
|
183 :type 'boolean
|
|
184 :group 'isearch)
|
16990
|
185
|
1142
|
186 (defvar isearch-mode-hook nil
|
|
187 "Function(s) to call after starting up an incremental search.")
|
|
188
|
|
189 (defvar isearch-mode-end-hook nil
|
|
190 "Function(s) to call after terminating an incremental search.")
|
|
191
|
725
|
192 ;;; Search ring.
|
|
193
|
|
194 (defvar search-ring nil
|
|
195 "List of search string sequences.")
|
1142
|
196 (defvar regexp-search-ring nil
|
725
|
197 "List of regular expression search string sequences.")
|
|
198
|
17637
|
199 (defcustom search-ring-max 16
|
|
200 "*Maximum length of search ring before oldest elements are thrown away."
|
|
201 :type 'integer
|
|
202 :group 'isearch)
|
|
203 (defcustom regexp-search-ring-max 16
|
|
204 "*Maximum length of regexp search ring before oldest elements are thrown away."
|
|
205 :type 'integer
|
|
206 :group 'isearch)
|
725
|
207
|
|
208 (defvar search-ring-yank-pointer nil
|
1146
|
209 "Index in `search-ring' of last string reused.
|
|
210 nil if none yet.")
|
1142
|
211 (defvar regexp-search-ring-yank-pointer nil
|
1146
|
212 "Index in `regexp-search-ring' of last string reused.
|
|
213 nil if none yet.")
|
725
|
214
|
17637
|
215 (defcustom search-ring-update nil
|
1142
|
216 "*Non-nil if advancing or retreating in the search ring should cause search.
|
17637
|
217 Default value, nil, means edit the string instead."
|
|
218 :type 'boolean
|
|
219 :group 'isearch)
|
1142
|
220
|
725
|
221 ;;; Define isearch-mode keymap.
|
|
222
|
|
223 (defvar isearch-mode-map nil
|
|
224 "Keymap for isearch-mode.")
|
|
225
|
1142
|
226 (or isearch-mode-map
|
|
227 (let* ((i 0)
|
1143
|
228 (map (make-keymap)))
|
2857
|
229 (or (vectorp (nth 1 map))
|
17781
|
230 (char-table-p (nth 1 map))
|
2857
|
231 (error "The initialization of isearch-mode-map must be updated"))
|
17794
|
232 ;; Make Latin-1, Latin-2, Latin-3 and Latin-4 characters
|
17781
|
233 ;; search for themselves.
|
17794
|
234 (aset (nth 1 map) (make-char 'latin-iso8859-1) 'isearch-printing-char)
|
|
235 (aset (nth 1 map) (make-char 'latin-iso8859-2) 'isearch-printing-char)
|
|
236 (aset (nth 1 map) (make-char 'latin-iso8859-3) 'isearch-printing-char)
|
|
237 (aset (nth 1 map) (make-char 'latin-iso8859-4) 'isearch-printing-char)
|
18440
|
238 (aset (nth 1 map) (make-char 'latin-iso8859-9) 'isearch-printing-char)
|
1458
|
239 ;; Make function keys, etc, exit the search.
|
|
240 (define-key map [t] 'isearch-other-control-char)
|
1142
|
241 ;; Control chars, by default, end isearch mode transparently.
|
1458
|
242 ;; We need these explicit definitions because, in a dense keymap,
|
|
243 ;; the binding for t does not affect characters.
|
|
244 ;; We use a dense keymap to save space.
|
1142
|
245 (while (< i ?\ )
|
|
246 (define-key map (make-string 1 i) 'isearch-other-control-char)
|
|
247 (setq i (1+ i)))
|
|
248
|
20500
|
249 ;; Single-byte printing chars extend the search string by default.
|
1458
|
250 (setq i ?\ )
|
20500
|
251 (while (< i 256)
|
2889
debc28aaae2c
(isearch-mode-map): Use vector, not string, to bind printing characters.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
252 (define-key map (vector i) 'isearch-printing-char)
|
1142
|
253 (setq i (1+ i)))
|
|
254
|
10166
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
255 ;; To handle local bindings with meta char prefix keys, define
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
256 ;; another full keymap. This must be done for any other prefix
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
257 ;; keys as well, one full keymap per char of the prefix key. It
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
258 ;; would be simpler to disable the global keymap, and/or have a
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
259 ;; default local key binding for any key not otherwise bound.
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
260 (let ((meta-map (make-sparse-keymap)))
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
261 (define-key map (char-to-string meta-prefix-char) meta-map)
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
262 (define-key map [escape] meta-map))
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
263 (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
264
|
1142
|
265 ;; Several non-printing chars change the searching behavior.
|
|
266 (define-key map "\C-s" 'isearch-repeat-forward)
|
|
267 (define-key map "\C-r" 'isearch-repeat-backward)
|
|
268 (define-key map "\177" 'isearch-delete-char)
|
|
269 (define-key map "\C-g" 'isearch-abort)
|
10166
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
270 ;; This assumes \e is the meta-prefix-char.
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
271 (or (= ?\e meta-prefix-char)
|
2cc7d710cf56
(isearch-mode-map): Move the code to set up the meta submap earlier in
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
272 (error "Inconsistency in isearch.el"))
|
10117
|
273 (define-key map "\e\e\e" 'isearch-cancel)
|
|
274 (define-key map [escape escape escape] 'isearch-cancel)
|
1142
|
275
|
|
276 (define-key map "\C-q" 'isearch-quote-char)
|
|
277
|
|
278 (define-key map "\r" 'isearch-exit)
|
|
279 (define-key map "\C-j" 'isearch-printing-char)
|
|
280 (define-key map "\t" 'isearch-printing-char)
|
|
281 (define-key map " " 'isearch-whitespace-chars)
|
20056
|
282 (define-key map [?\S-\ ] 'isearch-whitespace-chars)
|
1142
|
283
|
|
284 (define-key map "\C-w" 'isearch-yank-word)
|
|
285 (define-key map "\C-y" 'isearch-yank-line)
|
|
286
|
|
287 ;; Define keys for regexp chars * ? |.
|
|
288 ;; Nothing special for + because it matches at least once.
|
|
289 (define-key map "*" 'isearch-*-char)
|
|
290 (define-key map "?" 'isearch-*-char)
|
|
291 (define-key map "|" 'isearch-|-char)
|
|
292
|
2425
|
293 ;;; Turned off because I find I expect to get the global definition--rms.
|
|
294 ;;; ;; Instead bind C-h to special help command for isearch-mode.
|
|
295 ;;; (define-key map "\C-h" 'isearch-mode-help)
|
1142
|
296
|
|
297 (define-key map "\M-n" 'isearch-ring-advance)
|
|
298 (define-key map "\M-p" 'isearch-ring-retreat)
|
4876
|
299 (define-key map "\M-y" 'isearch-yank-kill)
|
1557
|
300
|
1142
|
301 (define-key map "\M-\t" 'isearch-complete)
|
|
302
|
12284
|
303 ;; Pass frame events transparently so they won't exit the search.
|
|
304 ;; In particular, if we have more than one display open, then a
|
|
305 ;; switch-frame might be generated by someone typing at another keyboard.
|
|
306 (define-key map [switch-frame] nil)
|
|
307 (define-key map [delete-frame] nil)
|
|
308 (define-key map [iconify-frame] nil)
|
|
309 (define-key map [make-frame-visible] nil)
|
17006
|
310 ;; For searching multilingual text.
|
|
311 (define-key map "\C-\\" 'isearch-toggle-input-method)
|
|
312 (define-key map "\C-^" 'isearch-toggle-specified-input-method)
|
12284
|
313
|
1142
|
314 (setq isearch-mode-map map)
|
|
315 ))
|
|
316
|
|
317 ;; Some bindings you may want to put in your isearch-mode-hook.
|
|
318 ;; Suggest some alternates...
|
7294
|
319 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-case-fold)
|
1142
|
320 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
|
|
321 ;; (define-key isearch-mode-map "\C-^" 'isearch-edit-string)
|
725
|
322
|
|
323
|
1142
|
324 (defvar minibuffer-local-isearch-map nil
|
|
325 "Keymap for editing isearch strings in the minibuffer.")
|
725
|
326
|
1142
|
327 (or minibuffer-local-isearch-map
|
|
328 (let ((map (copy-keymap minibuffer-local-map)))
|
|
329 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
|
1184
|
330 (define-key map "\M-n" 'isearch-ring-advance-edit)
|
|
331 (define-key map "\M-p" 'isearch-ring-retreat-edit)
|
1142
|
332 (define-key map "\M-\t" 'isearch-complete-edit)
|
|
333 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
|
|
334 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
|
|
335 (setq minibuffer-local-isearch-map map)
|
|
336 ))
|
725
|
337
|
|
338 ;; Internal variables declared globally for byte-compiler.
|
1142
|
339 ;; These are all set with setq while isearching
|
|
340 ;; and bound locally while editing the search string.
|
|
341
|
|
342 (defvar isearch-forward nil) ; Searching in the forward direction.
|
|
343 (defvar isearch-regexp nil) ; Searching for a regexp.
|
|
344 (defvar isearch-word nil) ; Searching for words.
|
725
|
345
|
1142
|
346 (defvar isearch-cmds nil) ; Stack of search status sets.
|
|
347 (defvar isearch-string "") ; The current search string.
|
|
348 (defvar isearch-message "") ; text-char-description version of isearch-string
|
|
349
|
|
350 (defvar isearch-success t) ; Searching is currently successful.
|
|
351 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
|
5601
|
352 (defvar isearch-within-brackets nil) ; Regexp has unclosed [.
|
1142
|
353 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
|
|
354 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
|
725
|
355 (defvar isearch-barrier 0)
|
13799
|
356 (defvar isearch-just-started nil)
|
725
|
357
|
7294
|
358 ; case-fold-search while searching.
|
|
359 ; either nil, t, or 'yes. 'yes means the same as t except that mixed
|
|
360 ; case in the search string is ignored.
|
|
361 (defvar isearch-case-fold-search nil)
|
725
|
362
|
|
363 (defvar isearch-adjusted nil)
|
|
364 (defvar isearch-slow-terminal-mode nil)
|
1142
|
365 ;;; If t, using a small window.
|
|
366 (defvar isearch-small-window nil)
|
|
367 (defvar isearch-opoint 0)
|
|
368 ;;; The window configuration active at the beginning of the search.
|
|
369 (defvar isearch-window-configuration nil)
|
725
|
370
|
1142
|
371 ;; Flag to indicate a yank occurred, so don't move the cursor.
|
|
372 (defvar isearch-yank-flag nil)
|
725
|
373
|
1142
|
374 ;;; A function to be called after each input character is processed.
|
|
375 ;;; (It is not called after characters that exit the search.)
|
|
376 ;;; It is only set from an optional argument to `isearch-mode'.
|
|
377 (defvar isearch-op-fun nil)
|
725
|
378
|
1142
|
379 ;;; Is isearch-mode in a recursive edit for modal searching.
|
|
380 (defvar isearch-recursive-edit nil)
|
725
|
381
|
1142
|
382 ;;; Should isearch be terminated after doing one search?
|
|
383 (defvar isearch-nonincremental nil)
|
|
384
|
|
385 ;; New value of isearch-forward after isearch-edit-string.
|
|
386 (defvar isearch-new-forward nil)
|
|
387
|
18236
|
388 ;; Accumulate here the overlays opened during searching.
|
|
389 (defvar isearch-opened-overlays nil)
|
725
|
390
|
|
391 ;; Minor-mode-alist changes - kind of redundant with the
|
|
392 ;; echo area, but if isearching in multiple windows, it can be useful.
|
|
393
|
|
394 (or (assq 'isearch-mode minor-mode-alist)
|
|
395 (nconc minor-mode-alist
|
|
396 (list '(isearch-mode isearch-mode))))
|
|
397
|
1142
|
398 (defvar isearch-mode nil) ;; Name of the minor mode, if non-nil.
|
725
|
399 (make-variable-buffer-local 'isearch-mode)
|
|
400
|
1143
|
401 (define-key global-map "\C-s" 'isearch-forward)
|
|
402 (define-key esc-map "\C-s" 'isearch-forward-regexp)
|
|
403 (define-key global-map "\C-r" 'isearch-backward)
|
|
404 (define-key esc-map "\C-r" 'isearch-backward-regexp)
|
|
405
|
725
|
406 ;;; Entry points to isearch-mode.
|
1142
|
407 ;;; These four functions should replace those in loaddefs.el
|
2572
|
408 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
|
1142
|
409 ;;; and look at this-command to set the options accordingly.
|
725
|
410
|
1883
|
411 (defun isearch-forward (&optional regexp-p no-recursive-edit)
|
725
|
412 "\
|
|
413 Do incremental search forward.
|
1142
|
414 With a prefix argument, do an incremental regular expression search instead.
|
725
|
415 \\<isearch-mode-map>
|
1142
|
416 As you type characters, they add to the search string and are found.
|
|
417 The following non-printing keys are bound in `isearch-mode-map'.
|
|
418
|
|
419 Type \\[isearch-delete-char] to cancel characters from end of search string.
|
725
|
420 Type \\[isearch-exit] to exit, leaving point at location found.
|
1142
|
421 Type LFD (C-j) to match end of line.
|
|
422 Type \\[isearch-repeat-forward] to search again forward,\
|
|
423 \\[isearch-repeat-backward] to search again backward.
|
|
424 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
|
|
425 string and search for it.
|
|
426 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
|
|
427 and search for it.
|
16495
|
428 Type \\[isearch-yank-kill] to yank the last string of killed text.
|
725
|
429 Type \\[isearch-quote-char] to quote control character to search for it.
|
1142
|
430 \\[isearch-abort] while searching or when search has failed cancels input\
|
|
431 back to what has
|
|
432 been found successfully.
|
|
433 \\[isearch-abort] when search is successful aborts and moves point to\
|
|
434 starting point.
|
725
|
435
|
|
436 Also supported is a search ring of the previous 16 search strings.
|
|
437 Type \\[isearch-ring-advance] to search for the next item in the search ring.
|
1142
|
438 Type \\[isearch-ring-retreat] to search for the previous item in the search\
|
|
439 ring.
|
|
440 Type \\[isearch-complete] to complete the search string using the search ring.
|
725
|
441
|
1142
|
442 The above keys, bound in `isearch-mode-map', are often controlled by
|
|
443 options; do M-x apropos on search-.* to find them.
|
|
444 Other control and meta characters terminate the search
|
|
445 and are then executed normally (depending on `search-exit-option').
|
13112
|
446 Likewise for function keys and mouse button events.
|
725
|
447
|
1142
|
448 If this function is called non-interactively, it does not return to
|
|
449 the calling function until the search is done."
|
|
450
|
1883
|
451 (interactive "P\np")
|
1885
|
452 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
|
1142
|
453
|
1883
|
454 (defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
|
725
|
455 "\
|
|
456 Do incremental search forward for regular expression.
|
1142
|
457 With a prefix argument, do a regular string search instead.
|
725
|
458 Like ordinary incremental search except that your input
|
|
459 is treated as a regexp. See \\[isearch-forward] for more info."
|
1883
|
460 (interactive "P\np")
|
1885
|
461 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
|
725
|
462
|
1883
|
463 (defun isearch-backward (&optional regexp-p no-recursive-edit)
|
725
|
464 "\
|
|
465 Do incremental search backward.
|
1142
|
466 With a prefix argument, do a regular expression search instead.
|
725
|
467 See \\[isearch-forward] for more information."
|
1883
|
468 (interactive "P\np")
|
1885
|
469 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
|
725
|
470
|
1883
|
471 (defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
|
725
|
472 "\
|
|
473 Do incremental search backward for regular expression.
|
1142
|
474 With a prefix argument, do a regular string search instead.
|
725
|
475 Like ordinary incremental search except that your input
|
|
476 is treated as a regexp. See \\[isearch-forward] for more info."
|
1883
|
477 (interactive "P\np")
|
1885
|
478 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
|
725
|
479
|
|
480
|
1142
|
481 (defun isearch-mode-help ()
|
|
482 (interactive)
|
|
483 (describe-function 'isearch-forward)
|
|
484 (isearch-update))
|
725
|
485
|
|
486
|
|
487 ;; isearch-mode only sets up incremental search for the minor mode.
|
|
488 ;; All the work is done by the isearch-mode commands.
|
|
489
|
1142
|
490 ;; Not used yet:
|
16687
|
491 ;;(defvar isearch-commands '(isearch-forward isearch-backward
|
1142
|
492 ;; isearch-forward-regexp isearch-backward-regexp)
|
|
493 ;; "List of commands for which isearch-mode does not recursive-edit.")
|
|
494
|
|
495
|
|
496 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
|
11643
|
497 "Start isearch minor mode. Called by `isearch-forward', etc.
|
|
498
|
|
499 \\{isearch-mode-map}"
|
725
|
500
|
|
501 ;; Initialize global vars.
|
|
502 (setq isearch-forward forward
|
|
503 isearch-regexp regexp
|
1142
|
504 isearch-word word-p
|
725
|
505 isearch-op-fun op-fun
|
|
506 isearch-case-fold-search case-fold-search
|
|
507 isearch-string ""
|
|
508 isearch-message ""
|
|
509 isearch-cmds nil
|
|
510 isearch-success t
|
|
511 isearch-wrapped nil
|
|
512 isearch-barrier (point)
|
|
513 isearch-adjusted nil
|
|
514 isearch-yank-flag nil
|
|
515 isearch-invalid-regexp nil
|
5601
|
516 isearch-within-brackets nil
|
9940
|
517 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
|
725
|
518 (> (window-height)
|
|
519 (* 4 search-slow-window-lines)))
|
|
520 isearch-other-end nil
|
|
521 isearch-small-window nil
|
13799
|
522 isearch-just-started t
|
725
|
523
|
|
524 isearch-opoint (point)
|
1146
|
525 search-ring-yank-pointer nil
|
18236
|
526 isearch-opened-overlays nil
|
1146
|
527 regexp-search-ring-yank-pointer nil)
|
13799
|
528 (looking-at "")
|
5554
0ac0776c23af
(isearch-mode): If not slow, clear isearch-window-configuration.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
529 (setq isearch-window-configuration
|
0ac0776c23af
(isearch-mode): If not slow, clear isearch-window-configuration.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
530 (if isearch-slow-terminal-mode (current-window-configuration) nil))
|
3476
6c6d1c6afb57
(isearch-mode): Set isearch-window-configuration only if in slow mode.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
531
|
16620
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
532 ;; Maybe make minibuffer frame visible and/or raise it.
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
533 (let ((frame (window-frame (minibuffer-window))))
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
534 (if (not (memq (frame-live-p frame) '(nil t)))
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
535 (progn
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
536 (make-frame-visible frame)
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
537 (if minibuffer-auto-raise
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
538 (raise-frame frame)))))
|
c3a095290ec4
(isearch-mode): Maybe make minibuffer frame visible and/or raise it.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
539
|
725
|
540 (setq isearch-mode " Isearch") ;; forward? regexp?
|
11579
|
541 (force-mode-line-update)
|
725
|
542
|
|
543 (isearch-push-state)
|
|
544
|
12265
1d2296cfa1e3
(isearch-mode): Use overriding-terminal-local-map, not overriding-local-map.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
545 (setq overriding-terminal-local-map isearch-mode-map)
|
725
|
546 (isearch-update)
|
|
547 (run-hooks 'isearch-mode-hook)
|
1142
|
548
|
14939
|
549 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
|
10257
|
550
|
1142
|
551 ;; isearch-mode can be made modal (in the sense of not returning to
|
|
552 ;; the calling function until searching is completed) by entering
|
|
553 ;; a recursive-edit and exiting it when done isearching.
|
3385
|
554 (if recursive-edit
|
|
555 (let ((isearch-recursive-edit t))
|
|
556 (recursive-edit)))
|
8663
|
557 isearch-success)
|
725
|
558
|
|
559
|
|
560 ;; Some high level utilities. Others below.
|
|
561
|
|
562 (defun isearch-update ()
|
|
563 ;; Called after each command to update the display.
|
9935
|
564 (if (null unread-command-events)
|
725
|
565 (progn
|
|
566 (if (not (input-pending-p))
|
|
567 (isearch-message))
|
|
568 (if (and isearch-slow-terminal-mode
|
|
569 (not (or isearch-small-window
|
|
570 (pos-visible-in-window-p))))
|
1142
|
571 (let ((found-point (point)))
|
725
|
572 (setq isearch-small-window t)
|
|
573 (move-to-window-line 0)
|
|
574 (let ((window-min-height 1))
|
|
575 (split-window nil (if (< search-slow-window-lines 0)
|
|
576 (1+ (- search-slow-window-lines))
|
|
577 (- (window-height)
|
|
578 (1+ search-slow-window-lines)))))
|
|
579 (if (< search-slow-window-lines 0)
|
|
580 (progn (vertical-motion (- 1 search-slow-window-lines))
|
|
581 (set-window-start (next-window) (point))
|
|
582 (set-window-hscroll (next-window)
|
|
583 (window-hscroll))
|
|
584 (set-window-hscroll (selected-window) 0))
|
|
585 (other-window 1))
|
1142
|
586 (goto-char found-point)))
|
|
587 (if isearch-other-end
|
|
588 (if (< isearch-other-end (point)) ; isearch-forward?
|
|
589 (isearch-highlight isearch-other-end (point))
|
5328
|
590 (isearch-highlight (point) isearch-other-end))
|
|
591 (isearch-dehighlight nil))
|
1142
|
592 ))
|
725
|
593 (setq ;; quit-flag nil not for isearch-mode
|
|
594 isearch-adjusted nil
|
|
595 isearch-yank-flag nil)
|
|
596 )
|
|
597
|
8663
|
598 (defun isearch-done (&optional nopush edit)
|
14939
|
599 (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
|
725
|
600 ;; Called by all commands that terminate isearch-mode.
|
1184
|
601 ;; If NOPUSH is non-nil, we don't push the string on the search ring.
|
12265
1d2296cfa1e3
(isearch-mode): Use overriding-terminal-local-map, not overriding-local-map.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
602 (setq overriding-terminal-local-map nil)
|
1142
|
603 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
|
|
604 (isearch-dehighlight t)
|
|
605 (let ((found-start (window-start (selected-window)))
|
|
606 (found-point (point)))
|
3476
6c6d1c6afb57
(isearch-mode): Set isearch-window-configuration only if in slow mode.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
607 (if isearch-window-configuration
|
6c6d1c6afb57
(isearch-mode): Set isearch-window-configuration only if in slow mode.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
608 (set-window-configuration isearch-window-configuration))
|
1142
|
609
|
4379
|
610 (if isearch-small-window
|
|
611 (goto-char found-point)
|
|
612 ;; Exiting the save-window-excursion clobbers window-start; restore it.
|
10183
|
613 (set-window-start (selected-window) found-start t))
|
4379
|
614
|
1142
|
615 ;; If there was movement, mark the starting position.
|
|
616 ;; Maybe should test difference between and set mark iff > threshold.
|
|
617 (if (/= (point) isearch-opoint)
|
10183
|
618 (or (and transient-mark-mode mark-active)
|
|
619 (progn
|
|
620 (push-mark isearch-opoint t)
|
13682
|
621 (or executing-kbd-macro (> (minibuffer-depth) 0)
|
10183
|
622 (message "Mark saved where search started"))))))
|
1142
|
623
|
|
624 (setq isearch-mode nil)
|
11579
|
625 (force-mode-line-update)
|
725
|
626
|
1184
|
627 (if (and (> (length isearch-string) 0) (not nopush))
|
725
|
628 ;; Update the ring data.
|
11100
|
629 (isearch-update-ring isearch-string isearch-regexp))
|
725
|
630
|
1142
|
631 (run-hooks 'isearch-mode-end-hook)
|
8663
|
632 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
|
1142
|
633
|
11100
|
634 (defun isearch-update-ring (string &optional regexp)
|
|
635 "Add STRING to the beginning of the search ring.
|
|
636 REGEXP says which ring to use."
|
|
637 (if regexp
|
|
638 (if (or (null regexp-search-ring)
|
11526
|
639 (not (string= string (car regexp-search-ring))))
|
11100
|
640 (progn
|
|
641 (setq regexp-search-ring
|
11526
|
642 (cons string regexp-search-ring))
|
11100
|
643 (if (> (length regexp-search-ring) regexp-search-ring-max)
|
|
644 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
|
|
645 nil))))
|
|
646 (if (or (null search-ring)
|
11526
|
647 (not (string= string (car search-ring))))
|
11100
|
648 (progn
|
11526
|
649 (setq search-ring (cons string search-ring))
|
11100
|
650 (if (> (length search-ring) search-ring-max)
|
|
651 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
|
|
652
|
1142
|
653 ;;; Switching buffers should first terminate isearch-mode.
|
3591
|
654 ;;; This is done quite differently for each variant of emacs.
|
1142
|
655 ;;; For lemacs, see Exiting in lemacs below
|
725
|
656
|
1142
|
657 ;; For Emacs 19, the frame switch event is handled.
|
|
658 (defun isearch-switch-frame-handler ()
|
|
659 (interactive) ;; Is this necessary?
|
|
660 ;; First terminate isearch-mode.
|
|
661 (isearch-done)
|
18236
|
662 (isearch-clean-overlays)
|
2296
|
663 (handle-switch-frame (car (cdr (isearch-last-command-char)))))
|
725
|
664
|
|
665
|
|
666 ;; Commands active while inside of the isearch minor mode.
|
|
667
|
|
668 (defun isearch-exit ()
|
|
669 "Exit search normally.
|
|
670 However, if this is the first command after starting incremental
|
|
671 search and `search-nonincremental-instead' is non-nil, do a
|
1142
|
672 nonincremental search instead via `isearch-edit-string'."
|
725
|
673 (interactive)
|
|
674 (if (and search-nonincremental-instead
|
|
675 (= 0 (length isearch-string)))
|
1142
|
676 (let ((isearch-nonincremental t))
|
|
677 (isearch-edit-string)))
|
18236
|
678 (isearch-done)
|
|
679 (isearch-clean-overlays))
|
725
|
680
|
|
681
|
|
682 (defun isearch-edit-string ()
|
1142
|
683 "Edit the search string in the minibuffer.
|
|
684 The following additional command keys are active while editing.
|
|
685 \\<minibuffer-local-isearch-map>
|
|
686 \\[exit-minibuffer] to resume incremental searching with the edited string.
|
|
687 \\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
|
|
688 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
|
7378
|
689 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
|
1142
|
690 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
|
3591
|
691 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
|
1142
|
692 \\[isearch-complete-edit] to complete the search string using the search ring.
|
7378
|
693 \\<isearch-mode-map>
|
1142
|
694 If first char entered is \\[isearch-yank-word], then do word search instead."
|
|
695
|
|
696 ;; This code is very hairy for several reasons, explained in the code.
|
|
697 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
|
|
698 ;; If there were a way to catch any change of buffer from the minibuffer,
|
|
699 ;; this could be simplified greatly.
|
3591
|
700 ;; Editing doesn't back up the search point. Should it?
|
725
|
701 (interactive)
|
1142
|
702 (condition-case err
|
16737
|
703 (progn
|
|
704 (let ((isearch-nonincremental isearch-nonincremental)
|
1142
|
705
|
16737
|
706 ;; Locally bind all isearch global variables to protect them
|
|
707 ;; from recursive isearching.
|
|
708 ;; isearch-string -message and -forward are not bound
|
|
709 ;; so they may be changed. Instead, save the values.
|
|
710 (isearch-new-string isearch-string)
|
|
711 (isearch-new-message isearch-message)
|
|
712 (isearch-new-forward isearch-forward)
|
|
713 (isearch-new-word isearch-word)
|
1142
|
714
|
16737
|
715 (isearch-regexp isearch-regexp)
|
|
716 (isearch-op-fun isearch-op-fun)
|
|
717 (isearch-cmds isearch-cmds)
|
|
718 (isearch-success isearch-success)
|
|
719 (isearch-wrapped isearch-wrapped)
|
|
720 (isearch-barrier isearch-barrier)
|
|
721 (isearch-adjusted isearch-adjusted)
|
|
722 (isearch-yank-flag isearch-yank-flag)
|
|
723 (isearch-invalid-regexp isearch-invalid-regexp)
|
|
724 (isearch-within-brackets isearch-within-brackets)
|
|
725 ;;; Don't bind this. We want isearch-search, below, to set it.
|
|
726 ;;; And the old value won't matter after that.
|
|
727 ;;; (isearch-other-end isearch-other-end)
|
|
728 ;;; Perhaps some of these other variables should be bound for a
|
|
729 ;;; shorter period, ending before the next isearch-search.
|
|
730 ;;; But there doesn't seem to be a real bug, so let's not risk it now.
|
|
731 (isearch-opoint isearch-opoint)
|
|
732 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
|
|
733 (isearch-small-window isearch-small-window)
|
|
734 (isearch-recursive-edit isearch-recursive-edit)
|
|
735 ;; Save current configuration so we can restore it here.
|
|
736 (isearch-window-configuration (current-window-configuration))
|
|
737 )
|
1142
|
738
|
16737
|
739 ;; Actually terminate isearching until editing is done.
|
|
740 ;; This is so that the user can do anything without failure,
|
|
741 ;; like switch buffers and start another isearch, and return.
|
|
742 (condition-case err
|
|
743 (isearch-done t t)
|
|
744 (exit nil)) ; was recursive editing
|
1142
|
745
|
16737
|
746 (isearch-message) ;; for read-char
|
|
747 (unwind-protect
|
|
748 (let* (;; Why does following read-char echo?
|
|
749 ;;(echo-keystrokes 0) ;; not needed with above message
|
|
750 (e (let ((cursor-in-echo-area t))
|
|
751 (read-event)))
|
|
752 ;; Binding minibuffer-history-symbol to nil is a work-around
|
|
753 ;; for some incompatibility with gmhist.
|
|
754 (minibuffer-history-symbol)
|
|
755 (message-log-max nil))
|
|
756 ;; If the first character the user types when we prompt them
|
|
757 ;; for a string is the yank-word character, then go into
|
|
758 ;; word-search mode. Otherwise unread that character and
|
|
759 ;; read a key the normal way.
|
|
760 ;; Word search does not apply (yet) to regexp searches,
|
|
761 ;; no check is made here.
|
|
762 (message (isearch-message-prefix nil nil t))
|
|
763 (if (eq 'isearch-yank-word
|
|
764 (lookup-key isearch-mode-map (vector e)))
|
|
765 (setq isearch-word t;; so message-prefix is right
|
|
766 isearch-new-word t)
|
|
767 (cancel-kbd-macro-events)
|
|
768 (isearch-unread e))
|
|
769 (setq cursor-in-echo-area nil)
|
|
770 (setq isearch-new-string
|
|
771 (let (junk-ring)
|
|
772 (read-from-minibuffer
|
|
773 (isearch-message-prefix nil nil isearch-nonincremental)
|
|
774 isearch-string
|
|
775 minibuffer-local-isearch-map nil
|
|
776 'junk-ring))
|
|
777 isearch-new-message
|
|
778 (mapconcat 'isearch-text-char-description
|
|
779 isearch-new-string "")))
|
|
780 ;; Always resume isearching by restarting it.
|
|
781 (isearch-mode isearch-forward
|
|
782 isearch-regexp
|
|
783 isearch-op-fun
|
|
784 nil
|
|
785 isearch-word)
|
1142
|
786
|
16737
|
787 ;; Copy new local values to isearch globals
|
|
788 (setq isearch-string isearch-new-string
|
|
789 isearch-message isearch-new-message
|
|
790 isearch-forward isearch-new-forward
|
|
791 isearch-word isearch-new-word))
|
1142
|
792
|
16737
|
793 ;; Empty isearch-string means use default.
|
|
794 (if (= 0 (length isearch-string))
|
|
795 (setq isearch-string (or (car (if isearch-regexp
|
|
796 regexp-search-ring
|
|
797 search-ring))
|
|
798 ""))
|
|
799 ;; This used to set the last search string,
|
|
800 ;; but I think it is not right to do that here.
|
|
801 ;; Only the string actually used should be saved.
|
|
802 ))
|
|
803
|
|
804 ;; Push the state as of before this C-s.
|
|
805 (isearch-push-state)
|
1142
|
806
|
|
807 ;; Reinvoke the pending search.
|
|
808 (isearch-search)
|
|
809 (isearch-update)
|
|
810 (if isearch-nonincremental
|
|
811 (progn
|
|
812 ;; (sit-for 1) ;; needed if isearch-done does: (message "")
|
|
813 (isearch-done))))
|
|
814
|
|
815 (quit ; handle abort-recursive-edit
|
|
816 (isearch-abort) ;; outside of let to restore outside global values
|
|
817 )))
|
|
818
|
|
819 (defun isearch-nonincremental-exit-minibuffer ()
|
|
820 (interactive)
|
|
821 (setq isearch-nonincremental t)
|
|
822 (exit-minibuffer))
|
|
823
|
|
824 (defun isearch-forward-exit-minibuffer ()
|
|
825 (interactive)
|
|
826 (setq isearch-new-forward t)
|
|
827 (exit-minibuffer))
|
|
828
|
|
829 (defun isearch-reverse-exit-minibuffer ()
|
|
830 (interactive)
|
|
831 (setq isearch-new-forward nil)
|
|
832 (exit-minibuffer))
|
725
|
833
|
10117
|
834 (defun isearch-cancel ()
|
|
835 "Terminate the search and go back to the starting point."
|
|
836 (interactive)
|
|
837 (goto-char isearch-opoint)
|
|
838 (isearch-done t)
|
18236
|
839 (isearch-clean-overlays)
|
10117
|
840 (signal 'quit nil)) ; and pass on quit signal
|
725
|
841
|
1142
|
842 (defun isearch-abort ()
|
13991
|
843 "Abort incremental search mode if searching is successful, signaling quit.
|
1142
|
844 Otherwise, revert to previous successful search and continue searching.
|
13991
|
845 Use `isearch-exit' to quit without signaling."
|
725
|
846 (interactive)
|
3591
|
847 ;; (ding) signal instead below, if quitting
|
725
|
848 (discard-input)
|
|
849 (if isearch-success
|
|
850 ;; If search is successful, move back to starting point
|
|
851 ;; and really do quit.
|
|
852 (progn (goto-char isearch-opoint)
|
11046
|
853 (setq isearch-success nil)
|
1184
|
854 (isearch-done t) ; exit isearch
|
18236
|
855 (isearch-clean-overlays)
|
1146
|
856 (signal 'quit nil)) ; and pass on quit signal
|
11061
|
857 ;; If search is failing, or has an incomplete regexp,
|
|
858 ;; rub out until it is once more successful.
|
|
859 (while (or (not isearch-success) isearch-invalid-regexp)
|
|
860 (isearch-pop-state))
|
725
|
861 (isearch-update)))
|
|
862
|
|
863 (defun isearch-repeat (direction)
|
|
864 ;; Utility for isearch-repeat-forward and -backward.
|
|
865 (if (eq isearch-forward (eq direction 'forward))
|
|
866 ;; C-s in forward or C-r in reverse.
|
|
867 (if (equal isearch-string "")
|
|
868 ;; If search string is empty, use last one.
|
|
869 (setq isearch-string
|
|
870 (or (if isearch-regexp
|
1146
|
871 (car regexp-search-ring)
|
|
872 (car search-ring))
|
725
|
873 "")
|
|
874 isearch-message
|
1142
|
875 (mapconcat 'isearch-text-char-description
|
725
|
876 isearch-string ""))
|
|
877 ;; If already have what to search for, repeat it.
|
|
878 (or isearch-success
|
|
879 (progn
|
|
880 (goto-char (if isearch-forward (point-min) (point-max)))
|
|
881 (setq isearch-wrapped t))))
|
|
882 ;; C-s in reverse or C-r in forward, change direction.
|
|
883 (setq isearch-forward (not isearch-forward)))
|
|
884
|
|
885 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
|
5411
|
886
|
|
887 (if (equal isearch-string "")
|
|
888 (setq isearch-success t)
|
13799
|
889 (if (and isearch-success (equal (match-end 0) (match-beginning 0))
|
|
890 (not isearch-just-started))
|
725
|
891 ;; If repeating a search that found
|
|
892 ;; an empty string, ensure we advance.
|
5411
|
893 (if (if isearch-forward (eobp) (bobp))
|
|
894 ;; If there's nowhere to advance to, fail (and wrap next time).
|
|
895 (progn
|
|
896 (setq isearch-success nil)
|
|
897 (ding))
|
|
898 (forward-char (if isearch-forward 1 -1))
|
|
899 (isearch-search))
|
|
900 (isearch-search)))
|
|
901
|
725
|
902 (isearch-push-state)
|
|
903 (isearch-update))
|
|
904
|
|
905 (defun isearch-repeat-forward ()
|
|
906 "Repeat incremental search forwards."
|
|
907 (interactive)
|
|
908 (isearch-repeat 'forward))
|
|
909
|
|
910 (defun isearch-repeat-backward ()
|
|
911 "Repeat incremental search backwards."
|
|
912 (interactive)
|
|
913 (isearch-repeat 'backward))
|
|
914
|
|
915 (defun isearch-toggle-regexp ()
|
|
916 "Toggle regexp searching on or off."
|
|
917 ;; The status stack is left unchanged.
|
|
918 (interactive)
|
|
919 (setq isearch-regexp (not isearch-regexp))
|
1142
|
920 (if isearch-regexp (setq isearch-word nil))
|
725
|
921 (isearch-update))
|
|
922
|
7294
|
923 (defun isearch-toggle-case-fold ()
|
|
924 "Toggle case folding in searching on or off."
|
|
925 (interactive)
|
|
926 (setq isearch-case-fold-search
|
|
927 (if isearch-case-fold-search nil 'yes))
|
10397
|
928 (let ((message-log-max nil))
|
|
929 (message "%s%s [case %ssensitive]"
|
|
930 (isearch-message-prefix nil nil isearch-nonincremental)
|
|
931 isearch-message
|
|
932 (if isearch-case-fold-search "in" "")))
|
7294
|
933 (setq isearch-adjusted t)
|
|
934 (sit-for 1)
|
|
935 (isearch-update))
|
|
936
|
725
|
937 (defun isearch-delete-char ()
|
|
938 "Discard last input item and move point back.
|
|
939 If no previous match was done, just beep."
|
|
940 (interactive)
|
|
941 (if (null (cdr isearch-cmds))
|
|
942 (ding)
|
|
943 (isearch-pop-state))
|
|
944 (isearch-update))
|
|
945
|
|
946
|
20275
|
947 (defun isearch-yank-string (string)
|
|
948 "Pull STRING into search string."
|
|
949 ;; Downcase the string if not supposed to case-fold yanked strings.
|
|
950 (if (and isearch-case-fold-search
|
|
951 (eq 'not-yanks search-upper-case))
|
|
952 (setq string (downcase string)))
|
|
953 (if isearch-regexp (setq string (regexp-quote string)))
|
|
954 (setq isearch-string (concat isearch-string string)
|
|
955 isearch-message
|
|
956 (concat isearch-message
|
|
957 (mapconcat 'isearch-text-char-description
|
|
958 string ""))
|
|
959 ;; Don't move cursor in reverse search.
|
|
960 isearch-yank-flag t)
|
725
|
961 (isearch-search-and-update))
|
|
962
|
4876
|
963 (defun isearch-yank-kill ()
|
|
964 "Pull string from kill ring into search string."
|
|
965 (interactive)
|
20275
|
966 (isearch-yank-string (current-kill 0)))
|
|
967
|
|
968 (defun isearch-yank-x-selection ()
|
|
969 "Pull current X selection into search string."
|
|
970 (interactive)
|
|
971 (isearch-yank-string (x-get-selection)))
|
725
|
972
|
|
973 (defun isearch-yank-word ()
|
|
974 "Pull next word from buffer into search string."
|
|
975 (interactive)
|
20275
|
976 (isearch-yank-string
|
|
977 (save-excursion
|
|
978 (and (not isearch-forward) isearch-other-end
|
|
979 (goto-char isearch-other-end))
|
|
980 (buffer-substring (point) (progn (forward-word 1) (point))))))
|
725
|
981
|
|
982 (defun isearch-yank-line ()
|
|
983 "Pull rest of line from buffer into search string."
|
|
984 (interactive)
|
20275
|
985 (isearch-yank-string
|
|
986 (save-excursion
|
|
987 (and (not isearch-forward) isearch-other-end
|
|
988 (goto-char isearch-other-end))
|
|
989 (buffer-substring (point) (line-end-position)))))
|
725
|
990
|
|
991
|
|
992 (defun isearch-search-and-update ()
|
|
993 ;; Do the search and update the display.
|
|
994 (if (and (not isearch-success)
|
|
995 ;; unsuccessful regexp search may become
|
|
996 ;; successful by addition of characters which
|
|
997 ;; make isearch-string valid
|
|
998 (not isearch-regexp))
|
|
999 nil
|
|
1000 ;; In reverse search, adding stuff at
|
|
1001 ;; the end may cause zero or many more chars to be
|
|
1002 ;; matched, in the string following point.
|
|
1003 ;; Allow all those possibilities without moving point as
|
|
1004 ;; long as the match does not extend past search origin.
|
|
1005 (if (and (not isearch-forward) (not isearch-adjusted)
|
|
1006 (condition-case ()
|
13799
|
1007 (let ((case-fold-search isearch-case-fold-search))
|
|
1008 (looking-at (if isearch-regexp isearch-string
|
|
1009 (regexp-quote isearch-string))))
|
725
|
1010 (error nil))
|
21070
|
1011 (or isearch-yank-flag
|
|
1012 (<= (match-end 0)
|
|
1013 (min isearch-opoint isearch-barrier))))
|
18440
|
1014 (progn
|
|
1015 (setq isearch-success t
|
|
1016 isearch-invalid-regexp nil
|
|
1017 isearch-within-brackets nil
|
|
1018 isearch-other-end (match-end 0))
|
|
1019 (if (and (eq isearch-case-fold-search t) search-upper-case)
|
|
1020 (setq isearch-case-fold-search
|
|
1021 (isearch-no-upper-case-p isearch-string isearch-regexp))))
|
725
|
1022 ;; Not regexp, not reverse, or no match at point.
|
|
1023 (if (and isearch-other-end (not isearch-adjusted))
|
|
1024 (goto-char (if isearch-forward isearch-other-end
|
|
1025 (min isearch-opoint
|
|
1026 isearch-barrier
|
|
1027 (1+ isearch-other-end)))))
|
|
1028 (isearch-search)
|
|
1029 ))
|
|
1030 (isearch-push-state)
|
|
1031 (if isearch-op-fun (funcall isearch-op-fun))
|
|
1032 (isearch-update))
|
|
1033
|
|
1034
|
|
1035 ;; *, ?, and | chars can make a regexp more liberal.
|
1142
|
1036 ;; They can make a regexp match sooner or make it succeed instead of failing.
|
725
|
1037 ;; So go back to place last successful search started
|
|
1038 ;; or to the last ^S/^R (barrier), whichever is nearer.
|
1142
|
1039 ;; + needs no special handling because the string must match at least once.
|
725
|
1040
|
|
1041 (defun isearch-*-char ()
|
|
1042 "Handle * and ? specially in regexps."
|
|
1043 (interactive)
|
|
1044 (if isearch-regexp
|
21070
|
1045 (let ((idx (length isearch-string)))
|
|
1046 (while (and (> idx 0)
|
|
1047 (eq (aref isearch-string (1- idx)) ?\\))
|
|
1048 (setq idx (1- idx)))
|
|
1049 (when (= (mod (- (length isearch-string) idx) 2) 0)
|
|
1050 (setq isearch-adjusted t)
|
|
1051 ;; Get the isearch-other-end from before the last search.
|
|
1052 ;; We want to start from there,
|
|
1053 ;; so that we don't retreat farther than that.
|
|
1054 ;; (car isearch-cmds) is after last search;
|
|
1055 ;; (car (cdr isearch-cmds)) is from before it.
|
|
1056 (let ((cs (nth 5 (car (cdr isearch-cmds)))))
|
|
1057 (setq cs (or cs isearch-barrier))
|
|
1058 (goto-char
|
|
1059 (if isearch-forward
|
|
1060 (max cs isearch-barrier)
|
|
1061 (min cs isearch-barrier)))))))
|
1142
|
1062 (isearch-process-search-char (isearch-last-command-char)))
|
725
|
1063
|
|
1064
|
|
1065 (defun isearch-|-char ()
|
|
1066 "If in regexp search, jump to the barrier."
|
|
1067 (interactive)
|
|
1068 (if isearch-regexp
|
|
1069 (progn
|
|
1070 (setq isearch-adjusted t)
|
|
1071 (goto-char isearch-barrier)))
|
1142
|
1072 (isearch-process-search-char (isearch-last-command-char)))
|
725
|
1073
|
|
1074
|
2572
|
1075 (defalias 'isearch-other-control-char 'isearch-other-meta-char)
|
725
|
1076
|
|
1077 (defun isearch-other-meta-char ()
|
2031
|
1078 "Exit the search normally and reread this key sequence.
|
1184
|
1079 But only if `search-exit-option' is non-nil, the default.
|
|
1080 If it is the symbol `edit', the search string is edited in the minibuffer
|
|
1081 and the meta character is unread so that it applies to editing the string."
|
725
|
1082 (interactive)
|
12106
|
1083 (let* ((key (this-command-keys))
|
|
1084 (main-event (aref key 0))
|
|
1085 (keylist (listify-key-sequence key)))
|
12716
|
1086 (cond ((and (= (length key) 1)
|
12824
|
1087 (let ((lookup (lookup-key function-key-map key)))
|
14288
|
1088 (not (or (null lookup) (integerp lookup)
|
|
1089 (keymapp lookup)))))
|
12716
|
1090 ;; Handle a function key that translates into something else.
|
|
1091 ;; If the key has a global definition too,
|
|
1092 ;; exit and unread the key itself, so its global definition runs.
|
|
1093 ;; Otherwise, unread the translation,
|
|
1094 ;; so that the translated key takes effect within isearch.
|
12824
|
1095 (cancel-kbd-macro-events)
|
12716
|
1096 (if (lookup-key global-map key)
|
|
1097 (progn
|
|
1098 (isearch-done)
|
|
1099 (apply 'isearch-unread keylist))
|
|
1100 (apply 'isearch-unread
|
|
1101 (listify-key-sequence (lookup-key function-key-map key)))))
|
|
1102 (
|
12106
|
1103 ;; Handle an undefined shifted control character
|
|
1104 ;; by downshifting it if that makes it defined.
|
|
1105 ;; (As read-key-sequence would normally do,
|
|
1106 ;; if we didn't have a default definition.)
|
|
1107 (let ((mods (event-modifiers main-event)))
|
|
1108 (and (integerp main-event)
|
|
1109 (memq 'shift mods)
|
|
1110 (memq 'control mods)
|
|
1111 (lookup-key isearch-mode-map
|
|
1112 (let ((copy (copy-sequence key)))
|
|
1113 (aset copy 0
|
|
1114 (- main-event (- ?\C-\S-a ?\C-a)))
|
|
1115 copy)
|
|
1116 nil)))
|
|
1117 (setcar keylist (- main-event (- ?\C-\S-a ?\C-a)))
|
12824
|
1118 (cancel-kbd-macro-events)
|
12106
|
1119 (apply 'isearch-unread keylist))
|
|
1120 ((eq search-exit-option 'edit)
|
|
1121 (apply 'isearch-unread keylist)
|
|
1122 (isearch-edit-string))
|
|
1123 (search-exit-option
|
|
1124 (let (window)
|
12824
|
1125 (cancel-kbd-macro-events)
|
12106
|
1126 (apply 'isearch-unread keylist)
|
|
1127 ;; Properly handle scroll-bar and mode-line clicks
|
|
1128 ;; for which a dummy prefix event was generated as (aref key 0).
|
|
1129 (and (> (length key) 1)
|
|
1130 (symbolp (aref key 0))
|
|
1131 (listp (aref key 1))
|
|
1132 (not (numberp (posn-point (event-start (aref key 1)))))
|
|
1133 ;; Convert the event back into its raw form,
|
|
1134 ;; with the dummy prefix implicit in the mouse event,
|
|
1135 ;; so it will get split up once again.
|
|
1136 (progn (setq unread-command-events
|
|
1137 (cdr unread-command-events))
|
|
1138 (setq main-event (car unread-command-events))
|
|
1139 (setcar (cdr (event-start main-event))
|
|
1140 (car (nth 1 (event-start main-event))))))
|
|
1141 ;; If we got a mouse click, maybe it was read with the buffer
|
|
1142 ;; it was clicked on. If so, that buffer, not the current one,
|
|
1143 ;; is in isearch mode. So end the search in that buffer.
|
|
1144 (if (and (listp main-event)
|
|
1145 (setq window (posn-window (event-start main-event)))
|
19127
|
1146 (windowp window)
|
|
1147 (or (> (minibuffer-depth) 0)
|
|
1148 (not (window-minibuffer-p window))))
|
12106
|
1149 (save-excursion
|
|
1150 (set-buffer (window-buffer window))
|
18236
|
1151 (isearch-done)
|
|
1152 (isearch-clean-overlays))
|
|
1153 (isearch-done)
|
|
1154 (isearch-clean-overlays))))
|
12106
|
1155 (t;; otherwise nil
|
|
1156 (isearch-process-search-string key key)))))
|
725
|
1157
|
|
1158 (defun isearch-quote-char ()
|
|
1159 "Quote special characters for incremental search."
|
|
1160 (interactive)
|
19146
|
1161 (let ((char (read-quoted-char (isearch-message t))))
|
|
1162 ;; Assume character codes 0200 - 0377 stand for
|
|
1163 ;; European characters in Latin-1, and convert them
|
|
1164 ;; to Emacs characters.
|
|
1165 (and enable-multibyte-characters
|
|
1166 (>= char ?\200)
|
|
1167 (<= char ?\377)
|
|
1168 (setq char (+ char nonascii-insert-offset)))
|
|
1169 (isearch-process-search-char char)))
|
725
|
1170
|
|
1171 (defun isearch-return-char ()
|
|
1172 "Convert return into newline for incremental search.
|
|
1173 Obsolete."
|
|
1174 (interactive)
|
|
1175 (isearch-process-search-char ?\n))
|
|
1176
|
|
1177 (defun isearch-printing-char ()
|
2533
|
1178 "Add this ordinary printing character to the search string and search."
|
725
|
1179 (interactive)
|
19587
|
1180 (let ((char (isearch-last-command-char)))
|
20056
|
1181 (if (= char ?\S-\ )
|
|
1182 (setq char ?\ ))
|
19587
|
1183 (if (and enable-multibyte-characters
|
|
1184 (>= char ?\200)
|
|
1185 (<= char ?\377))
|
|
1186 (isearch-process-search-char (+ char nonascii-insert-offset))
|
|
1187 (if current-input-method
|
|
1188 (isearch-process-search-multibyte-characters char)
|
|
1189 (isearch-process-search-char char)))))
|
725
|
1190
|
|
1191 (defun isearch-whitespace-chars ()
|
1142
|
1192 "Match all whitespace chars, if in regexp mode.
|
2533
|
1193 If you want to search for just a space, type C-q SPC."
|
725
|
1194 (interactive)
|
1142
|
1195 (if isearch-regexp
|
15858
946a4fb104ef
(isearch-whitespace-chars): If isearch-invalid-regexp, insert just a space.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1196 (if (and search-whitespace-regexp (not isearch-within-brackets)
|
946a4fb104ef
(isearch-whitespace-chars): If isearch-invalid-regexp, insert just a space.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1197 (not isearch-invalid-regexp))
|
1142
|
1198 (isearch-process-search-string search-whitespace-regexp " ")
|
|
1199 (isearch-printing-char))
|
|
1200 (progn
|
3591
|
1201 ;; This way of doing word search doesn't correctly extend current search.
|
1142
|
1202 ;; (setq isearch-word t)
|
|
1203 ;; (setq isearch-adjusted t)
|
|
1204 ;; (goto-char isearch-barrier)
|
|
1205 (isearch-printing-char))))
|
725
|
1206
|
|
1207 (defun isearch-process-search-char (char)
|
|
1208 ;; Append the char to the search string, update the message and re-search.
|
1142
|
1209 (isearch-process-search-string
|
|
1210 (isearch-char-to-string char)
|
17794
|
1211 (if (>= char 0200)
|
|
1212 (char-to-string char)
|
|
1213 (isearch-text-char-description char))))
|
725
|
1214
|
|
1215 (defun isearch-process-search-string (string message)
|
|
1216 (setq isearch-string (concat isearch-string string)
|
|
1217 isearch-message (concat isearch-message message))
|
|
1218 (isearch-search-and-update))
|
|
1219
|
|
1220
|
|
1221 ;; Search Ring
|
|
1222
|
1142
|
1223 (defun isearch-ring-adjust1 (advance)
|
|
1224 ;; Helper for isearch-ring-adjust
|
|
1225 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
|
725
|
1226 (length (length ring))
|
|
1227 (yank-pointer-name (if isearch-regexp
|
1142
|
1228 'regexp-search-ring-yank-pointer
|
725
|
1229 'search-ring-yank-pointer))
|
|
1230 (yank-pointer (eval yank-pointer-name)))
|
|
1231 (if (zerop length)
|
|
1232 ()
|
|
1233 (set yank-pointer-name
|
|
1234 (setq yank-pointer
|
4512
ed1f6abba5c5
(isearch-ring-adjust1, isearch-ring-advance-edit): Replace `%' by `mod' and simplify.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1235 (mod (+ (or yank-pointer 0)
|
ed1f6abba5c5
(isearch-ring-adjust1, isearch-ring-advance-edit): Replace `%' by `mod' and simplify.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1236 (if advance -1 1))
|
ed1f6abba5c5
(isearch-ring-adjust1, isearch-ring-advance-edit): Replace `%' by `mod' and simplify.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1237 length)))
|
1146
|
1238 (setq isearch-string (nth yank-pointer ring)
|
1142
|
1239 isearch-message (mapconcat 'isearch-text-char-description
|
|
1240 isearch-string "")))))
|
|
1241
|
|
1242 (defun isearch-ring-adjust (advance)
|
|
1243 ;; Helper for isearch-ring-advance and isearch-ring-retreat
|
|
1244 (isearch-ring-adjust1 advance)
|
|
1245 (if search-ring-update
|
|
1246 (progn
|
|
1247 (isearch-search)
|
|
1248 (isearch-update))
|
|
1249 (isearch-edit-string)
|
16711
|
1250 )
|
|
1251 (isearch-push-state))
|
725
|
1252
|
|
1253 (defun isearch-ring-advance ()
|
|
1254 "Advance to the next search string in the ring."
|
1142
|
1255 ;; This could be more general to handle a prefix arg, but who would use it.
|
725
|
1256 (interactive)
|
|
1257 (isearch-ring-adjust 'advance))
|
|
1258
|
|
1259 (defun isearch-ring-retreat ()
|
|
1260 "Retreat to the previous search string in the ring."
|
|
1261 (interactive)
|
|
1262 (isearch-ring-adjust nil))
|
|
1263
|
1146
|
1264 (defun isearch-ring-advance-edit (n)
|
|
1265 "Insert the next element of the search history into the minibuffer."
|
|
1266 (interactive "p")
|
|
1267 (let* ((yank-pointer-name (if isearch-regexp
|
|
1268 'regexp-search-ring-yank-pointer
|
|
1269 'search-ring-yank-pointer))
|
|
1270 (yank-pointer (eval yank-pointer-name))
|
|
1271 (ring (if isearch-regexp regexp-search-ring search-ring))
|
|
1272 (length (length ring)))
|
|
1273 (if (zerop length)
|
|
1274 ()
|
|
1275 (set yank-pointer-name
|
|
1276 (setq yank-pointer
|
4512
ed1f6abba5c5
(isearch-ring-adjust1, isearch-ring-advance-edit): Replace `%' by `mod' and simplify.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1277 (mod (- (or yank-pointer 0) n)
|
ed1f6abba5c5
(isearch-ring-adjust1, isearch-ring-advance-edit): Replace `%' by `mod' and simplify.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1278 length)))
|
725
|
1279
|
1146
|
1280 (erase-buffer)
|
1184
|
1281 (insert (nth yank-pointer ring))
|
1380
|
1282 (goto-char (point-max)))))
|
725
|
1283
|
1146
|
1284 (defun isearch-ring-retreat-edit (n)
|
|
1285 "Inserts the previous element of the search history into the minibuffer."
|
|
1286 (interactive "p")
|
|
1287 (isearch-ring-advance-edit (- n)))
|
|
1288
|
|
1289 ;;(defun isearch-ring-adjust-edit (advance)
|
|
1290 ;; "Use the next or previous search string in the ring while in minibuffer."
|
|
1291 ;; (isearch-ring-adjust1 advance)
|
|
1292 ;; (erase-buffer)
|
|
1293 ;; (insert isearch-string))
|
|
1294
|
|
1295 ;;(defun isearch-ring-advance-edit ()
|
|
1296 ;; (interactive)
|
|
1297 ;; (isearch-ring-adjust-edit 'advance))
|
|
1298
|
|
1299 ;;(defun isearch-ring-retreat-edit ()
|
|
1300 ;; "Retreat to the previous search string in the ring while in the minibuffer."
|
|
1301 ;; (interactive)
|
|
1302 ;; (isearch-ring-adjust-edit nil))
|
725
|
1303
|
|
1304
|
1142
|
1305 (defun isearch-complete1 ()
|
|
1306 ;; Helper for isearch-complete and isearch-complete-edit
|
|
1307 ;; Return t if completion OK, nil if no completion exists.
|
|
1308 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
|
|
1309 (alist (mapcar (function (lambda (string) (list string))) ring))
|
|
1310 (completion-ignore-case case-fold-search)
|
|
1311 (completion (try-completion isearch-string alist)))
|
|
1312 (cond
|
|
1313 ((eq completion t)
|
|
1314 ;; isearch-string stays the same
|
|
1315 t)
|
|
1316 ((or completion ; not nil, must be a string
|
13991
|
1317 (= 0 (length isearch-string))) ; shouldn't have to say this
|
1142
|
1318 (if (equal completion isearch-string) ;; no extension?
|
16566
|
1319 (progn
|
|
1320 (if completion-auto-help
|
|
1321 (with-output-to-temp-buffer "*Isearch completions*"
|
|
1322 (display-completion-list
|
|
1323 (all-completions isearch-string alist))))
|
|
1324 t)
|
|
1325 (and completion
|
|
1326 (setq isearch-string completion))))
|
1142
|
1327 (t
|
|
1328 (message "No completion") ; waits a second if in minibuffer
|
|
1329 nil))))
|
|
1330
|
|
1331 (defun isearch-complete ()
|
|
1332 "Complete the search string from the strings on the search ring.
|
|
1333 The completed string is then editable in the minibuffer.
|
|
1334 If there is no completion possible, say so and continue searching."
|
|
1335 (interactive)
|
|
1336 (if (isearch-complete1)
|
|
1337 (isearch-edit-string)
|
|
1338 ;; else
|
|
1339 (sit-for 1)
|
|
1340 (isearch-update)))
|
|
1341
|
|
1342 (defun isearch-complete-edit ()
|
|
1343 "Same as `isearch-complete' except in the minibuffer."
|
|
1344 (interactive)
|
|
1345 (setq isearch-string (buffer-string))
|
|
1346 (if (isearch-complete1)
|
725
|
1347 (progn
|
1142
|
1348 (erase-buffer)
|
|
1349 (insert isearch-string))))
|
725
|
1350
|
|
1351
|
|
1352 ;; The search status stack (and isearch window-local variables, not used).
|
1142
|
1353 ;; Need a structure for this.
|
725
|
1354
|
|
1355 (defun isearch-top-state ()
|
|
1356 (let ((cmd (car isearch-cmds)))
|
|
1357 (setq isearch-string (car cmd)
|
|
1358 isearch-message (car (cdr cmd))
|
|
1359 isearch-success (nth 3 cmd)
|
|
1360 isearch-forward (nth 4 cmd)
|
|
1361 isearch-other-end (nth 5 cmd)
|
1142
|
1362 isearch-word (nth 6 cmd)
|
|
1363 isearch-invalid-regexp (nth 7 cmd)
|
|
1364 isearch-wrapped (nth 8 cmd)
|
5601
|
1365 isearch-barrier (nth 9 cmd)
|
5637
|
1366 isearch-within-brackets (nth 10 cmd)
|
|
1367 isearch-case-fold-search (nth 11 cmd))
|
725
|
1368 (goto-char (car (cdr (cdr cmd))))))
|
|
1369
|
|
1370 (defun isearch-pop-state ()
|
|
1371 (setq isearch-cmds (cdr isearch-cmds))
|
|
1372 (isearch-top-state)
|
|
1373 )
|
|
1374
|
|
1375 (defun isearch-push-state ()
|
|
1376 (setq isearch-cmds
|
|
1377 (cons (list isearch-string isearch-message (point)
|
|
1378 isearch-success isearch-forward isearch-other-end
|
1142
|
1379 isearch-word
|
5601
|
1380 isearch-invalid-regexp isearch-wrapped isearch-barrier
|
5637
|
1381 isearch-within-brackets isearch-case-fold-search)
|
725
|
1382 isearch-cmds)))
|
|
1383
|
|
1384
|
|
1385 ;; Message string
|
|
1386
|
|
1387 (defun isearch-message (&optional c-q-hack ellipsis)
|
|
1388 ;; Generate and print the message string.
|
|
1389 (let ((cursor-in-echo-area ellipsis)
|
|
1390 (m (concat
|
1142
|
1391 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
|
725
|
1392 isearch-message
|
|
1393 (isearch-message-suffix c-q-hack ellipsis)
|
|
1394 )))
|
10397
|
1395 (if c-q-hack
|
|
1396 m
|
|
1397 (let ((message-log-max nil))
|
|
1398 (message "%s" m)))))
|
725
|
1399
|
1142
|
1400 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
|
725
|
1401 ;; If about to search, and previous search regexp was invalid,
|
|
1402 ;; check that it still is. If it is valid now,
|
|
1403 ;; let the message we display while searching say that it is valid.
|
|
1404 (and isearch-invalid-regexp ellipsis
|
|
1405 (condition-case ()
|
|
1406 (progn (re-search-forward isearch-string (point) t)
|
7378
|
1407 (setq isearch-invalid-regexp nil
|
|
1408 isearch-within-brackets nil))
|
725
|
1409 (error nil)))
|
|
1410 ;; If currently failing, display no ellipsis.
|
|
1411 (or isearch-success (setq ellipsis nil))
|
|
1412 (let ((m (concat (if isearch-success "" "failing ")
|
13254
|
1413 (if (and isearch-wrapped
|
|
1414 (if isearch-forward
|
|
1415 (> (point) isearch-opoint)
|
|
1416 (< (point) isearch-opoint)))
|
|
1417 "over")
|
725
|
1418 (if isearch-wrapped "wrapped ")
|
1142
|
1419 (if isearch-word "word " "")
|
725
|
1420 (if isearch-regexp "regexp " "")
|
1142
|
1421 (if nonincremental "search" "I-search")
|
17006
|
1422 (if isearch-forward "" " backward")
|
19408
|
1423 (if current-input-method
|
|
1424 (concat " [" current-input-method-title "]: ")
|
17006
|
1425 ": ")
|
725
|
1426 )))
|
|
1427 (aset m 0 (upcase (aref m 0)))
|
|
1428 m))
|
|
1429
|
|
1430
|
|
1431 (defun isearch-message-suffix (&optional c-q-hack ellipsis)
|
|
1432 (concat (if c-q-hack "^Q" "")
|
|
1433 (if isearch-invalid-regexp
|
|
1434 (concat " [" isearch-invalid-regexp "]")
|
|
1435 "")))
|
|
1436
|
|
1437
|
|
1438 ;;; Searching
|
|
1439
|
|
1440 (defun isearch-search ()
|
|
1441 ;; Do the search with the current search string.
|
|
1442 (isearch-message nil t)
|
7294
|
1443 (if (and (eq isearch-case-fold-search t) search-upper-case)
|
3526
|
1444 (setq isearch-case-fold-search
|
|
1445 (isearch-no-upper-case-p isearch-string isearch-regexp)))
|
725
|
1446 (condition-case lossage
|
18866
|
1447 (let ((inhibit-point-motion-hooks search-invisible)
|
|
1448 (inhibit-quit nil)
|
16990
|
1449 (case-fold-search isearch-case-fold-search)
|
|
1450 (retry t))
|
725
|
1451 (if isearch-regexp (setq isearch-invalid-regexp nil))
|
5601
|
1452 (setq isearch-within-brackets nil)
|
16990
|
1453 (while retry
|
|
1454 (setq isearch-success
|
|
1455 (funcall
|
|
1456 (cond (isearch-word
|
|
1457 (if isearch-forward
|
|
1458 'word-search-forward 'word-search-backward))
|
|
1459 (isearch-regexp
|
|
1460 (if isearch-forward
|
|
1461 're-search-forward 're-search-backward))
|
|
1462 (t
|
|
1463 (if isearch-forward 'search-forward 'search-backward)))
|
|
1464 isearch-string nil t))
|
|
1465 ;; Clear RETRY unless we matched some invisible text
|
|
1466 ;; and we aren't supposed to do that.
|
18236
|
1467 (if (or (eq search-invisible t)
|
16990
|
1468 (not isearch-success)
|
|
1469 (bobp) (eobp)
|
|
1470 (= (match-beginning 0) (match-end 0))
|
|
1471 (not (isearch-range-invisible
|
|
1472 (match-beginning 0) (match-end 0))))
|
|
1473 (setq retry nil)))
|
13799
|
1474 (setq isearch-just-started nil)
|
725
|
1475 (if isearch-success
|
|
1476 (setq isearch-other-end
|
|
1477 (if isearch-forward (match-beginning 0) (match-end 0)))))
|
|
1478
|
5196
|
1479 (quit (isearch-unread ?\C-g)
|
725
|
1480 (setq isearch-success nil))
|
|
1481
|
|
1482 (invalid-regexp
|
|
1483 (setq isearch-invalid-regexp (car (cdr lossage)))
|
5601
|
1484 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
|
|
1485 isearch-invalid-regexp))
|
725
|
1486 (if (string-match
|
|
1487 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
|
|
1488 isearch-invalid-regexp)
|
1534
dd292c7ef749
(isearch-search): Handle all sorts of errors from regexp search.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1489 (setq isearch-invalid-regexp "incomplete input")))
|
dd292c7ef749
(isearch-search): Handle all sorts of errors from regexp search.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1490 (error
|
dd292c7ef749
(isearch-search): Handle all sorts of errors from regexp search.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1491 ;; stack overflow in regexp search.
|
dd292c7ef749
(isearch-search): Handle all sorts of errors from regexp search.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1492 (setq isearch-invalid-regexp (car (cdr lossage)))))
|
725
|
1493
|
|
1494 (if isearch-success
|
|
1495 nil
|
|
1496 ;; Ding if failed this time after succeeding last time.
|
|
1497 (and (nth 3 (car isearch-cmds))
|
|
1498 (ding))
|
|
1499 (goto-char (nth 2 (car isearch-cmds)))))
|
|
1500
|
18236
|
1501
|
|
1502 ;;; Called when opening an overlay, and we are still in isearch.
|
|
1503 (defun isearch-open-overlay-temporary (ov)
|
|
1504 (if (not (null (overlay-get ov 'isearch-open-invisible-temporary)))
|
|
1505 ;; Some modes would want to open the overlays temporary during
|
|
1506 ;; isearch in their own way, they should set the
|
|
1507 ;; `isearch-open-invisible-temporary' to a function doing this.
|
|
1508 (funcall (overlay-get ov 'isearch-open-invisible-temporary) ov nil)
|
|
1509 ;; Store the values for the `invisible' and `intangible'
|
|
1510 ;; properties, and then set them to nil. This way the text hidden
|
|
1511 ;; by this overlay becomes visible.
|
|
1512
|
|
1513 ;; Do we realy need to set the `intangible' property to t? Can we
|
|
1514 ;; have the point inside an overlay with an `intangible' property?
|
|
1515 ;; In 19.34 this does not exist so I cannot test it.
|
|
1516 (overlay-put ov 'isearch-invisible (overlay-get ov 'invisible))
|
|
1517 (overlay-put ov 'isearch-intangible (overlay-get ov 'intangible))
|
|
1518 (overlay-put ov 'invisible nil)
|
|
1519 (overlay-put ov 'intangible nil)))
|
|
1520
|
|
1521
|
|
1522 ;;; This is called at the end of isearch. I will open the overlays
|
|
1523 ;;; that contain the latest match. Obviously in case of a C-g the
|
|
1524 ;;; point returns to the original location which surely is not contain
|
|
1525 ;;; in any of these overlays, se we are safe in this case too.
|
|
1526 (defun isearch-open-necessary-overlays (ov)
|
|
1527 (let ((inside-overlay (and (> (point) (overlay-start ov))
|
|
1528 (< (point) (overlay-end ov))))
|
|
1529 ;; If this exists it means that the overlay was opened using
|
|
1530 ;; this function, not by us tweaking the overlay properties.
|
|
1531 (fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
|
|
1532 (when (or inside-overlay (not fct-temp))
|
|
1533 ;; restore the values for the `invisible' and `intangible'
|
|
1534 ;; properties
|
|
1535 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
|
|
1536 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
|
|
1537 (overlay-put ov 'isearch-invisible nil)
|
|
1538 (overlay-put ov 'isearch-intangible nil))
|
|
1539 (if inside-overlay
|
|
1540 (funcall (overlay-get ov 'isearch-open-invisible) ov)
|
|
1541 (if fct-temp
|
|
1542 (funcall fct-temp ov t)))))
|
|
1543
|
|
1544 ;;; This is called when exiting isearch. It closes the temporary
|
|
1545 ;;; opened overlays, except the ones that contain the latest match.
|
|
1546 (defun isearch-clean-overlays ()
|
|
1547 (when isearch-opened-overlays
|
|
1548 ;; Use a cycle instead of a mapcar here?
|
|
1549 (mapcar
|
|
1550 (function isearch-open-necessary-overlays) isearch-opened-overlays)
|
|
1551 (setq isearch-opened-overlays nil)))
|
|
1552
|
|
1553 ;;; Verify if the current match is outside of each element of
|
|
1554 ;;; `isearch-opened-overlays', if so close that overlay.
|
|
1555 (defun isearch-close-unecessary-overlays (begin end)
|
|
1556 (let ((ov-list isearch-opened-overlays)
|
|
1557 ov
|
|
1558 inside-overlay
|
|
1559 fct-temp)
|
|
1560 (setq isearch-opened-overlays nil)
|
|
1561 (while ov-list
|
|
1562 (setq ov (car ov-list))
|
|
1563 (setq ov-list (cdr ov-list))
|
|
1564 (setq inside-overlay (or (and (> begin (overlay-start ov))
|
|
1565 (< begin (overlay-end ov)))
|
|
1566 (and (> end (overlay-start ov))
|
|
1567 (< end (overlay-end ov)))))
|
|
1568 ;; If this exists it means that the overlay was opened using
|
|
1569 ;; this function, not by us tweaking the overlay properties.
|
|
1570 (setq fct-temp (overlay-get ov 'isearch-open-invisible-temporary))
|
|
1571 (if inside-overlay
|
|
1572 (setq isearch-opened-overlays (cons ov isearch-opened-overlays))
|
|
1573 (if fct-temp
|
|
1574 (funcall fct-temp ov t)
|
|
1575 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
|
|
1576 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
|
|
1577 (overlay-put ov 'isearch-invisible nil)
|
|
1578 (overlay-put ov 'isearch-intangible nil))))))
|
|
1579
|
16990
|
1580 (defun isearch-range-invisible (beg end)
|
18866
|
1581 "Return t if all the text from BEG to END is invisible."
|
16990
|
1582 (and (/= beg end)
|
|
1583 ;; Check that invisibility runs up to END.
|
|
1584 (save-excursion
|
|
1585 (goto-char beg)
|
18236
|
1586 (let
|
|
1587 ;; can-be-opened keeps track if we can open some overlays.
|
|
1588 ((can-be-opened (eq search-invisible 'open))
|
|
1589 ;; the list of overlays that could be opened
|
|
1590 (crt-overlays nil))
|
|
1591 (when (and can-be-opened isearch-hide-immediately)
|
|
1592 (isearch-close-unecessary-overlays beg end))
|
|
1593 ;; If the following character is currently invisible,
|
|
1594 ;; skip all characters with that same `invisible' property value.
|
|
1595 ;; Do that over and over.
|
|
1596 (while (and (< (point) end)
|
|
1597 (let ((prop
|
|
1598 (get-char-property (point) 'invisible)))
|
|
1599 (if (eq buffer-invisibility-spec t)
|
|
1600 prop
|
|
1601 (or (memq prop buffer-invisibility-spec)
|
|
1602 (assq prop buffer-invisibility-spec)))))
|
|
1603 (if (get-text-property (point) 'invisible)
|
|
1604 (progn
|
|
1605 (goto-char (next-single-property-change (point) 'invisible
|
|
1606 nil end))
|
|
1607 ;; if text is hidden by an `invisible' text property
|
|
1608 ;; we cannot open it at all.
|
|
1609 (setq can-be-opened nil))
|
|
1610 (unless (null can-be-opened)
|
|
1611 (let ((overlays (overlays-at (point)))
|
|
1612 ov-list
|
|
1613 o
|
|
1614 invis-prop)
|
|
1615 (while overlays
|
|
1616 (setq o (car overlays)
|
|
1617 invis-prop (overlay-get o 'invisible))
|
|
1618 (if (or (memq invis-prop buffer-invisibility-spec)
|
|
1619 (assq invis-prop buffer-invisibility-spec))
|
|
1620 (if (overlay-get o 'isearch-open-invisible)
|
|
1621 (setq ov-list (cons o ov-list))
|
|
1622 ;; We found one overlay that cannot be
|
|
1623 ;; opened, that means the whole chunk
|
|
1624 ;; cannot be opened.
|
|
1625 (setq can-be-opened nil)))
|
|
1626 (setq overlays (cdr overlays)))
|
|
1627 (if can-be-opened
|
|
1628 ;; It makes sense to append to the open
|
|
1629 ;; overlays list only if we know that this is
|
|
1630 ;; t.
|
20812
d21a1c41800f
(isearch-range-invisible): Avoid infinite loop when search-invisible is nil.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1631 (setq crt-overlays (append ov-list crt-overlays)))))
|
d21a1c41800f
(isearch-range-invisible): Avoid infinite loop when search-invisible is nil.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1632 (goto-char (next-overlay-change (point)))))
|
16990
|
1633 ;; See if invisibility reaches up thru END.
|
18236
|
1634 (if (>= (point) end)
|
|
1635 (if (and (not (null can-be-opened)) (consp crt-overlays))
|
|
1636 (progn
|
|
1637 (setq isearch-opened-overlays
|
|
1638 (append isearch-opened-overlays crt-overlays))
|
|
1639 ;; maybe use a cycle instead of mapcar?
|
|
1640 (mapcar (function isearch-open-overlay-temporary)
|
|
1641 crt-overlays)
|
|
1642 nil)
|
|
1643 t))))))
|
1142
|
1644
|
|
1645
|
|
1646 ;;; Highlighting
|
|
1647
|
3526
|
1648 (defvar isearch-overlay nil)
|
1142
|
1649
|
3526
|
1650 (defun isearch-highlight (beg end)
|
5649
|
1651 (if (or (null search-highlight) (null window-system))
|
1142
|
1652 nil
|
3526
|
1653 (or isearch-overlay (setq isearch-overlay (make-overlay beg end)))
|
|
1654 (move-overlay isearch-overlay beg end (current-buffer))
|
3717
|
1655 (overlay-put isearch-overlay 'face
|
|
1656 (if (internal-find-face 'isearch nil)
|
|
1657 'isearch 'region))))
|
1142
|
1658
|
3526
|
1659 (defun isearch-dehighlight (totally)
|
|
1660 (if isearch-overlay
|
|
1661 (delete-overlay isearch-overlay)))
|
725
|
1662
|
1142
|
1663 ;;; General utilities
|
|
1664
|
|
1665
|
3526
|
1666 (defun isearch-no-upper-case-p (string regexp-flag)
|
|
1667 "Return t if there are no upper case chars in STRING.
|
13991
|
1668 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
|
3526
|
1669 since they have special meaning in a regexp."
|
16635
|
1670 (let (quote-flag (i 0) (len (length string)) found)
|
|
1671 (while (and (not found) (< i len))
|
|
1672 (let ((char (aref string i)))
|
|
1673 (if (and regexp-flag (eq char ?\\))
|
|
1674 (setq quote-flag (not quote-flag))
|
|
1675 (if (and (not quote-flag) (not (eq char (downcase char))))
|
|
1676 (setq found t))))
|
|
1677 (setq i (1+ i)))
|
|
1678 (not found)))
|
1142
|
1679
|
3526
|
1680 ;; Portability functions to support various Emacs versions.
|
725
|
1681
|
1142
|
1682 (defun isearch-char-to-string (c)
|
18783
|
1683 (char-to-string c))
|
1142
|
1684
|
|
1685 (defun isearch-text-char-description (c)
|
5277
|
1686 (if (and (integerp c) (or (< c ?\ ) (= c ?\^?)))
|
|
1687 (text-char-description c)
|
|
1688 (isearch-char-to-string c)))
|
1142
|
1689
|
9934
|
1690 ;; General function to unread characters or events.
|
13799
|
1691 ;; Also insert them in a keyboard macro being defined.
|
2031
|
1692 (defun isearch-unread (&rest char-or-events)
|
13799
|
1693 (mapcar 'store-kbd-macro-event char-or-events)
|
9934
|
1694 (setq unread-command-events
|
|
1695 (append char-or-events unread-command-events)))
|
1142
|
1696
|
|
1697 (defun isearch-last-command-char ()
|
|
1698 ;; General function to return the last command character.
|
9935
|
1699 last-command-char)
|
1142
|
1700
|
2230
|
1701 ;;; isearch.el ends here
|