annotate lisp/=isearch-old.el @ 10167:358d48409854

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