annotate lisp/=isearch-old.el @ 505:d5b34c57b5e7

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Thu, 16 Jan 1992 03:44:18 +0000
parents 6506740942fa
children 08eb386dd0f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;; Incremental search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; any later version.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; GNU General Public License for more details.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 (defvar search-last-string "" "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 Last string search for by a non-regexp search command.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 This does not include direct calls to the primitive search functions,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 and does not include searches that are aborted.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 (defvar search-last-regexp "" "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 Last string searched for by a regexp search command.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 This does not include direct calls to the primitive search functions,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 and does not include searches that are aborted.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (defconst search-repeat-char ?\C-s "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 *Character to repeat incremental search forwards.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (defconst search-reverse-char ?\C-r "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 *Character to repeat incremental search backwards.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (defconst search-exit-char ?\C-m "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 *Character to exit incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (defconst search-delete-char ?\177 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 *Character to delete from incremental search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 (defconst search-quote-char ?\C-q "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 *Character to quote special characters for incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 (defconst search-yank-word-char ?\C-w "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 *Character to pull next word from buffer into search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (defconst search-yank-line-char ?\C-y "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 *Character to pull rest of line from buffer into search string.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (defconst search-ring-advance-char ?\M-n "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 *Character to pull next (more recent) search string from the ring of same.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (defconst search-ring-retreat-char ?\M-p "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 *Character to pull previous (older) search string from the ring of same.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (defconst search-exit-option t "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 *Non-nil means random control characters terminate incremental search.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (defvar search-slow-window-lines 1 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 *Number of lines in slow search display windows.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 These are the short windows used during incremental search on slow terminals.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Negative means put the slow search window at the top (normally it's at bottom)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 and the value is minus the number of lines.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (defvar search-slow-speed 1200 "\
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 *Highest terminal speed at which to use \"slow\" style incremental search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 This is the style where a one-line window is created to show the line
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 that the search has reached.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (defconst search-upper-case t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 "*Non-nil means an upper-case letter as search input means case-sensitive.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 Any upper-case letter given explicitly as input to the incremental search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 has the effect of turning off `case-fold-search' for the rest of this search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 Deleting the letter from the search string cancels the effect.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 (fset 'search-forward-regexp 're-search-forward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (fset 'search-backward-regexp 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (defvar search-ring nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 "List of recent non-regexp incremental searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 Each element is a cons cell of the form (STRING . UPPERCASE-FLAG).")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (defvar regexp-search-ring nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 "List of recent regexp incremental searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 Each element is a cons cell of the form (STRING . UPPERCASE-FLAG).")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (defconst search-ring-max 16
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 "*Maximum length of search ring before oldest elements are thrown away.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (defvar search-ring-yank-pointer nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 "The tail of the search ring whose car is the last thing searched for.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (defvar regexp-search-ring-yank-pointer nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 "The tail of the regular expression search ring whose car is the last
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 thing searched for.")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (defun isearch-forward ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 "Do incremental search forward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 As you type characters, they add to the search string and are found.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 Type Delete to cancel characters from end of search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 Type RET to exit, leaving point at location found.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 Type C-s to search again forward, C-r to search again backward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 Type C-w to yank word from buffer onto end of search string and search for it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 Type C-y to yank rest of line onto end of search string, etc.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 Type C-q to quote control character to search for it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 Other control and meta characters terminate the search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 and are then executed normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 The above special characters are mostly controlled by parameters;
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 do M-x apropos on search-.*-char to find them.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 C-g while searching or when search has failed
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 cancels input back to what has been found successfully.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 C-g when search is successful aborts and moves point to starting point."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (isearch t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (define-key global-map "\C-s" 'isearch-forward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (defun isearch-forward-regexp ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 "Do incremental search forward for regular expression.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 Like ordinary incremental search except that your input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 is treated as a regexp. See \\[isearch-forward] for more info."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (isearch t t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 (define-key esc-map "\C-s" 'isearch-forward-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (defun isearch-backward ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 "Do incremental search backward.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 See \\[isearch-forward] for more information."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (isearch nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (define-key global-map "\C-r" 'isearch-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (defun isearch-backward-regexp ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 "Do incremental search backward for regular expression.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 Like ordinary incremental search except that your input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 is treated as a regexp. See \\[isearch-forward] for more info."
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (interactive)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (isearch nil t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 ;;;###autoload
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (define-key esc-map "\C-r" 'isearch-backward-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 ;; This function does all the work of incremental search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 ;; The functions attached to ^R and ^S are trivial,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 ;; merely calling this one, but they are always loaded by default
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 ;; whereas this file can optionally be autoloadable.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 ;; This is the only entry point in this file.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 ;; OP-FUN is a function to be called after each input character is processed.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 ;; (It is not called after characters that exit the search.)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (defun isearch (forward &optional regexp op-fun)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (let ((search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (search-message "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 ;; List of previous states during this search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (history nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 ;; t means search is currently successful.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (success t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 ;; Set once the search has wrapped around the end of the buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (wrapped nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 ;; Nominal starting point for searching
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 ;; Usually this is the same as the opoint,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 ;; but it is changed by wrapping
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 ;; and also by repeating the search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (barrier (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 ;; Set temporarily when adding a character to a regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 ;; enables it to match more rather than fewer places in the buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 liberalized
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 ;; Set temporarily by yanking text into the search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 yank-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (invalid-regexp nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 ;; non-nil means an explicit uppercase letter seen in the input
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (uppercase-flag nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 ;; Non-nil means start using a small window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 ;; if the search moves outside what is currently on the screen.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 (slow-terminal-mode (and (<= baud-rate search-slow-speed)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (> (window-height)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (* 4 search-slow-window-lines))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 ;; t means a small window is currently in use.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (small-window nil) ;if t, using a small window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 ;; These variables preserve information from the small window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 ;; through exit from the save-window-excursion.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (found-point nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (found-start nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 ;; Point is at one end of the last match.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 ;; This variable records the other end of that match.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (other-end nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 ;; Value of point at start of search,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 ;; for moving the cursor back on quitting.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (opoint (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (inhibit-quit t) ;Prevent ^G from quitting, so we can read it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 ;; The screen we're working on; if this changes, we exit isearch.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (screen (if (fboundp 'selected-screen) (selected-screen))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (save-window-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (catch 'search-done
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (while t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (or (and (numberp unread-command-char) (>= unread-command-char 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (or (input-pending-p)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (isearch-message))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (if (and slow-terminal-mode
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (not (or small-window (pos-visible-in-window-p))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (setq small-window t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (setq found-point (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (move-to-window-line 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (let ((window-min-height 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (split-window nil (if (< search-slow-window-lines 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (1+ (- search-slow-window-lines))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (- (window-height)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (1+ search-slow-window-lines)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (if (< search-slow-window-lines 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (progn (vertical-motion (- 1 search-slow-window-lines))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (set-window-start (next-window) (point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (set-window-hscroll (next-window)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (window-hscroll))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (set-window-hscroll (selected-window) 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (other-window 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (goto-char found-point)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (let ((char (if quit-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 ?\C-g
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (read-event))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (setq quit-flag nil liberalized nil yank-flag nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (cond ((and (or (not (integerp char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (and (>= char 128)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (not (= char search-ring-advance-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (not (= char search-ring-retreat-char))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 search-exit-option)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 ;; If the user switches to a different screen, exit.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 ((not (eq screen last-event-screen))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 ((eq char search-exit-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 ;; RET means exit search normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 ;; Except, if first thing typed, it means do nonincremental
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (if (= 0 (length search-string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (nonincremental-search forward regexp))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 ((= char ?\C-g)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 ;; ^G means the user tried to quit.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (ding)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (discard-input)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 ;; If search is successful, move back to starting point
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 ;; and really do quit.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (progn (goto-char opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (signal 'quit nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 ;; If search is failing, rub out until it is once more
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 ;; successful.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (while (not success) (isearch-pop))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 ((or (eq char search-repeat-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (eq char search-reverse-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (if (eq forward (eq char search-repeat-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 ;; C-s in forward or C-r in reverse.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (if (equal search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 ;; If search string is empty, use last one.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (isearch-get-string-from-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 ;; If already have what to search for, repeat it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (or success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (progn (goto-char (if forward (point-min) (point-max)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 (setq wrapped t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 ;; C-s in reverse or C-r in forward, change direction.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (setq forward (not forward)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (setq barrier (point)) ; For subsequent \| if regexp.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (setq success t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (or (equal search-string "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 ;; If repeating a search that found an empty string,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 ;; ensure we advance. Test history to make sure we
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ;; actually have done a search already; otherwise,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 ;; the match data will be random.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (if (and (cdr history)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (= (match-end 0) (match-beginning 0)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (forward-char (if forward 1 -1)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (isearch-search)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (isearch-push-state))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 ((= char search-delete-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 ;; Rubout means discard last input item and move point
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 ;; back. If buffer is empty, just beep.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (if (null (cdr history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (ding)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (isearch-pop)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 ((= char search-ring-advance-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (isearch-pop)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (let ((length (length regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (setq regexp-search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (nthcdr (% (+ 1 (- length (length regexp-search-ring-yank-pointer)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 regexp-search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (isearch-get-string-from-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 (let ((length (length search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 (setq search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 (nthcdr (% (+ 1 (- length (length search-ring-yank-pointer)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (isearch-get-string-from-ring))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (isearch-search))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 ((= char search-ring-retreat-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (isearch-pop)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 (let ((length (length regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 (setq regexp-search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (nthcdr (% (+ (- length (length regexp-search-ring-yank-pointer))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 (1- length))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 regexp-search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 (isearch-get-string-from-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (let ((length (length search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (if (zerop length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (setq search-ring-yank-pointer
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (nthcdr (% (+ (- length (length search-ring-yank-pointer))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 (1- length))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 length)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (isearch-get-string-from-ring))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (isearch-push-state)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (isearch-search))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (cond ((or (eq char search-yank-word-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (eq char search-yank-line-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 ;; ^W means gobble next word from buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 ;; ^Y means gobble rest of line from buffer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 (let ((word (save-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (and (not forward) other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (goto-char other-end))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (buffer-substring
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (point)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (save-excursion
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (if (eq char search-yank-line-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (end-of-line)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (forward-word 1))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (point))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (setq word (regexp-quote word)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (setq search-string (concat search-string word)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (concat search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (mapconcat 'text-char-description
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 word ""))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 ;; Don't move cursor in reverse search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 yank-flag t)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 ;; Any other control char =>
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 ;; unread it and exit the search normally.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 ((and search-exit-option
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (/= char search-quote-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (or (>= char ?\177)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (and (< char ? )
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (/= char ?\t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (/= char ?\n))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (setq unread-command-char char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (throw 'search-done t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (t
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 ;; Any other character => add it to the
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 ;; search string and search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (cond ((= char search-quote-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 (setq char (read-quoted-char
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (isearch-message t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 ((= char ?\r)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 ;; RET translates to newline.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (setq char ?\n)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (setq search-string (concat search-string
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (char-to-string char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 search-message (concat search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 (text-char-description char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 uppercase-flag (or uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 (not (= char (downcase char)))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 (if (and (not success)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 ;; unsuccessful regexp search may become
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 ;; successful by addition of characters which
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 ;; make search-string valid
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 (not regexp))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 ;; Check for chars that can make a regexp more liberal.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 ;; They can make a regexp match sooner
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 ;; or make it succeed instead of failing.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 ;; So go back to place last successful search started
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 ;; or to the last ^S/^R (barrier), whichever is nearer.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (and regexp history
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (cond ((and (memq char '(?* ??))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 ;; Don't treat *, ? as special
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 ;; within [] or after \.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 (not (nth 6 (car history))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (setq liberalized t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 ;; This used to use element 2
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 ;; in a reverse search, but it seems that 5
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 ;; (which is the end of the old match)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 ;; is better in that case too.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 (let ((cs (nth 5 ; old other-end.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 (car (cdr history)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 ;; (car history) is after last search;
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 ;; (car (cdr history)) is from before it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (setq cs (or cs barrier))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 (goto-char
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 (if forward
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (max cs barrier)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (min cs barrier)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 ((eq char ?\|)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 (setq liberalized t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (goto-char barrier))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 ;; Turn off case-sensitivity if string requests it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 (let ((case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 (and case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (not (and uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 search-upper-case)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 ;; In reverse search, adding stuff at
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 ;; the end may cause zero or many more chars to be
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 ;; matched, in the string following point.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 ;; Allow all those possibilities without moving point as
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 ;; long as the match does not extend past search origin.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 (if (and (not forward) (not liberalized)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 (condition-case ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (looking-at (if regexp search-string
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (regexp-quote search-string)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (error nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 (or yank-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 ;; Used to have (min opoint barrier)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 ;; instead of barrier.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 ;; This lost when wrapping.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 (<= (match-end 0) barrier)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (setq success t invalid-regexp nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 other-end (match-end 0))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 ;; Not regexp, not reverse, or no match at point.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 (if (and other-end (not liberalized))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 (goto-char (if forward other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 ;; Used to have opoint inside the min.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 ;; This lost when wrapping.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (min barrier (1+ other-end)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 (isearch-search))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 (isearch-push-state))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (if op-fun (funcall op-fun))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (setq found-start (window-start (selected-window)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 (setq found-point (point)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 (if (> (length search-string) 0)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 (if (and regexp (not (member search-string regexp-search-ring)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 (setq regexp-search-ring (cons (cons search-string uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 regexp-search-ring-yank-pointer regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (if (> (length regexp-search-ring) regexp-search-ring-max)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring) nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (if (not (member search-string search-ring))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 (progn
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 (setq search-ring (cons (cons search-string uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 search-ring-yank-pointer search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 (if (> (length search-ring) search-ring-max)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 ;; If we displayed a single-line window, set point in this window.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 (if small-window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 (goto-char found-point))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 ;; If there was movement, mark the starting position.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 ;; Maybe should test difference between and set mark iff > threshold.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 (if (/= (point) opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 (push-mark opoint)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 (message ""))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 (or small-window
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 ;; Exiting the save-window-excursion clobbers this; restore it.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (set-window-start (selected-window) found-start t))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (defun isearch-message (&optional c-q-hack ellipsis)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 ;; If about to search, and previous search regexp was invalid,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 ;; check that it still is. If it is valid now,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 ;; let the message we display while searching say that it is valid.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (and invalid-regexp ellipsis
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 (condition-case ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (progn (re-search-forward search-string (point) t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (setq invalid-regexp nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 (error nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 ;; If currently failing, display no ellipsis.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 (or success (setq ellipsis nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 (let ((m (concat (if success "" "failing ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 (if wrapped "wrapped ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (if (or (not case-fold-search)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (and uppercase-flag search-upper-case))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 "case-sensitive ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (if regexp "regexp " "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 "I-search"
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (if forward ": " " backward: ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 search-message
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (if c-q-hack "^Q" "")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 (if invalid-regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (concat " [" invalid-regexp "]")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 ""))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (aset m 0 (upcase (aref m 0)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 (let ((cursor-in-echo-area ellipsis))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (if c-q-hack m (message "%s" m)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 ;; Get the search string from the "front" of the ring of previous searches.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 (defun isearch-get-string-from-ring ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 (let ((elt (car (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 (or regexp-search-ring-yank-pointer regexp-search-ring)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 (or search-ring-yank-pointer search-ring)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 ;; ELT describes the most recent search or where we have rotated the ring.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 (if elt
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 (setq search-string (car elt)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 uppercase-flag (cdr elt))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 (setq search-string "" uppercase-flag nil)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 ;; Let's give this one the benefit of the doubt.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 (setq invalid-regexp nil)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 (setq search-message (mapconcat 'text-char-description search-string "")))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 (defun isearch-pop ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 (setq history (cdr history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 (let ((cmd (car history)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 (setq search-string (car cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 search-message (car (cdr cmd))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 success (nth 3 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 forward (nth 4 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 other-end (nth 5 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 invalid-regexp (nth 6 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 wrapped (nth 7 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 barrier (nth 8 cmd)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 uppercase-flag (nth 9 cmd))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (goto-char (car (cdr (cdr cmd))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (defun isearch-push-state ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 (setq history (cons (list search-string search-message (point)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 success forward other-end invalid-regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 wrapped barrier uppercase-flag)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 history)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (defun isearch-search ()
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 (let ((case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (and case-fold-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 (not (and uppercase-flag
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 search-upper-case)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 (isearch-message nil t)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 (condition-case lossage
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 (let ((inhibit-quit nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 (if regexp (setq invalid-regexp nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (setq success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 (funcall
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (if forward 're-search-forward 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (if forward 'search-forward 'search-backward))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 search-string nil t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 (setq other-end
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 (if forward (match-beginning 0) (match-end 0)))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (quit (setq unread-command-char ?\C-g)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 (setq success nil))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (invalid-regexp (setq invalid-regexp (car (cdr lossage)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 (if (string-match "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 invalid-regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 (setq invalid-regexp "incomplete input"))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 (if success
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 nil
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 ;; Ding if failed this time after succeeding last time.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 (and (nth 3 (car history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 (ding))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 (goto-char (nth 2 (car history))))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 ;; This is called from incremental-search
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 ;; if the first input character is the exit character.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 ;; The interactive-arg-reader uses free variables `forward' and `regexp'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 ;; which are bound by `incremental-search'.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 ;; We store the search string in `search-string'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 ;; which has been bound already by `incremental-search'
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 ;; so that, when we exit, it is copied into `search-last-string'.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 (defun nonincremental-search (forward regexp)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (let (message char function string inhibit-quit)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 (let ((cursor-in-echo-area t))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 ;; Prompt assuming not word search,
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 (setq message (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 (if forward "Regexp search: "
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 "Regexp search backward: ")
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 (if forward "Search: " "Search backward: ")))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (message "%s" message)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 ;; Read 1 char and switch to word search if it is ^W.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 (setq char (read-event)))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (if (and (numberp char) (eq char search-yank-word-char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 (setq message (if forward "Word search: " "Word search backward: "))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 ;; Otherwise let that 1 char be part of the search string.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 (setq unread-command-char char))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (setq function
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (if (eq char search-yank-word-char)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 (if forward 'word-search-forward 'word-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 (if regexp
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 (if forward 're-search-forward 're-search-backward)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 (if forward 'search-forward 'search-backward))))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 ;; Read the search string with corrected prompt.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 (setq string (read-string message))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 ;; Empty means use default.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 (if (= 0 (length string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (setq string search-last-string)
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 ;; Set last search string now so it is set even if we fail.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 (setq search-last-string string))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 ;; Since we used the minibuffer, we should be available for redo.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 (setq command-history (cons (list function string) command-history))
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 ;; Go ahead and search.
6506740942fa Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 (funcall function string)))