annotate lisp/isearch.el @ 882:bff32d8ecc5e

entered into RCS
author Richard M. Stallman <rms@gnu.org>
date Mon, 27 Jul 1992 08:52:26 +0000
parents 224b0d5d1a38
children 7fc9de9d8cef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
792
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
1 ;; isearch-mode.el --- incremental search minor mode.
725
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 792
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 792
diff changeset
4
792
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
6 ;; Version: 1.2
725
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; GNU Emacs is distributed in the hope that it will be useful,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; accepts responsibility to anyone for the consequences of using it
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; or for whether it serves any particular purpose or works at all,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; License for full details.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; Everyone is granted permission to copy, modify and redistribute
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; GNU Emacs, but only under the conditions described in the
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; GNU Emacs General Public License. A copy of this license is
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; supposed to have been given to you along with GNU Emacs so you
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; can know your rights and responsibilities. It should be in a
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; file named COPYING. Among other things, the copyright notice
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; and this notice must be preserved on all copies.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24
792
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
25 ;;; Commentary:
725
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 ;;;====================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 ;; Instructions
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 ;; Searching with isearch-mode.el should work just like isearch.el,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;; except it is done in a temporary minor mode that terminates when
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; you finish searching.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; To use isearch-mode instead of the standard isearch.el, add the
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; following to your .emacs file. The standard key bindings to
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; isearch-forward, etc, will then use isearch-mode instead of
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; isearch.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; (fset 'isearch 'isearch-mode)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; (autoload 'isearch-mode "isearch-mode")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; The key bindings active within isearch-mode are defined below in
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;; `isearch-mode-map' and `isearch-mode-meta-map' which are given
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; bindings close to the default characters of isearch.el for
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; version 19. With `isearch-mode', however, you can bind
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; multi-character keys and it should be easier to add new commands.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; Note to epoch and emacs version 19 users: isearch-mode should
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; work even if you switch windows with the mouse. However, if
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;; you isearch in a buffer that is also displayed in another window,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;; when you switch to that other window you will still be in
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;; isearch mode but not necessarily in the right state for it to work.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 ;; So ... don't do it unless you are in an experimental mood.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 ;; You can also experiment with the window-local-variable routines
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 ;; contained in this package but not yet used.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 ;; Also, I am not sure what happens when you return to an isearching
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ;; buffer; ideally, the echo area should redisplay the searching status.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 ;; A select-window-hook might be useful.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
792
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
60 ;;; Change Log:
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
61
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
62 ;;;====================================================================
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
63
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
64 ;;; Revision 1.2 92/05/27 11:33:57 liberte
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
65 ;;; Several new commands and features have been added. Emacs version
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
66 ;;; 19 has a search ring, which is supported here. Other fixes found
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
67 ;;; in the version 19 isearch are included here. Also see variables
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
68 ;;; search-caps-disable-folding, search-nonincremental-instead,
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
69 ;;; search-whitespace-regexp, and commands isearch-toggle-regexp,
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
70 ;;; isearch-edit-string,
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
71 ;;;
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
72 ;;; Semi-modal searching is supported, using a recursive edit. If
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
73 ;;; isearching is started non-interactively by calling one of the
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
74 ;;; isearch commands (e.g. isearch-forward), it does not return
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
75 ;;; until the search is completed. You should still be able switch
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
76 ;;; buffers, so be careful not to get things confused.
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
77 ;;;
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
78
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
79 ;;; Changes for 1.1
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
80 ;;; 3/18/92 Fixed invalid-regexp.
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
81 ;;; 3/18/92 Fixed yanking in regexps.
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
82
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
83 ;;; Code:
45d748a65f24 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 725
diff changeset
84
725
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 ;;;=========================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 ;;; The following, defined in loaddefs.el, are still used with isearch-mode.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 ;(defvar search-last-string ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 ; "Last string search for by a search command.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 ;This does not include direct calls to the primitive search functions,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 ;and does not include searches that are aborted.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 ;(defvar search-last-regexp ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 ; "Last string searched for by a regexp search command.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 ;This does not include direct calls to the primitive search functions,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 ;and does not include searches that are aborted.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 ;(defconst search-exit-option t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 ; "Non-nil means random control characters terminate incremental search.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 ;(defvar search-slow-window-lines 1
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 ; "*Number of lines in slow search display windows.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 ;(defconst search-slow-speed 1200
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 ; "*Highest terminal speed at which to use \"slow\" style incremental search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ;This is the style where a one-line window is created to show the line
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 ;that the search has reached.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 ;;;========================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 ;;; Some additional options and constants.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (defvar search-caps-disable-folding t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 "*If non-nil, upper case chars disable case fold searching.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 This does not yet apply to yanked strings, however.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (defvar search-nonincremental-instead t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 "*If non-nil, do a nonincremental search instead if exiting immediately.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 The default value of t reflects the default behavior of old
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 isearch.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (defconst search-whitespace-regexp "\\s-+"
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 "*If non-nil, regular expression to match a sequence of whitespace chars.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 You might want to use something like \"[ \\t\\r\\n]+\" instead.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 ;;;==================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 ;;; Search ring.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 ;;; "regex" == "regexp". One should become the standard term.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (defvar search-ring nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 "List of search string sequences.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (defvar regex-search-ring nil ;; Is `regex' the new spelling?
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 "List of regular expression search string sequences.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (defconst search-ring-max 16
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 "*Maximum length of search ring before oldest elements are thrown away.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 (defconst regex-search-ring-max 16
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 "*Maximum length of regex search ring before oldest elements are thrown away.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (defvar search-ring-yank-pointer nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 "The tail of the search ring whose car is the last thing searched for.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (defvar regex-search-ring-yank-pointer nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 "The tail of the regular expression search ring whose car is the last
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 thing searched for.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 ;;;====================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 ;;; Define isearch-mode keymap.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (defvar isearch-mode-map nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 "Keymap for isearch-mode.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 (defvar isearch-mode-meta-map nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 "Keymap for isearch-mode for keys with meta char prefix.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 ;; To handle meta char prefix keys, define another full keymap.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 ;; The same must be done for any other prefix keys.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 ;; It would be simpler to disable to global keymap, and/or
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 ;; have a default local key binding for any key not otherwise bound.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (if isearch-mode-meta-map
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (setq isearch-mode-meta-map
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (list 'keymap (make-vector 128 'isearch-other-meta-char)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (define-key isearch-mode-meta-map "n" 'isearch-ring-advance)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (define-key isearch-mode-meta-map "p" 'isearch-ring-retreat)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (define-key isearch-mode-meta-map " " 'isearch-whitespace-chars)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 ;for regexps
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 ;; (define-key isearch-mode-meta-map "?" nil) ; my help key is M-?
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (if isearch-mode-map
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (let ((i 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 ;; Printing chars extend the selection by default.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (array (make-vector 128 'isearch-printing-char)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 ;; Non-printing chars by default suspend isearch mode transparently
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (while (< i ?\ )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (aset array i 'isearch-other-control-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (setq i (1+ i)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (setq i ?A)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (while (<= i ?Z)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (aset array i 'isearch-upper-case-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (setq i (1+ i)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (setq isearch-mode-map (list 'keymap array))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 ;; You can reenable global keys by unbinding them locally.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 ;; For the help char this doesnt work quite as expected because
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 ;; isearch-mode is not a major mode, and the echo area is not
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 ;; restored after the help command.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 ;; Also, we should not assume that the help-command is on C-h.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 ;; If it is not, and the prefix is not the meta-char, we would
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 ;; have to create another map for its prefix.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 ; (define-key isearch-mode-map "\C-h" nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 ;; Several non-printing chars change the searching behavior.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 (define-key isearch-mode-map "\C-s" 'isearch-repeat-forward)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (define-key isearch-mode-map "\C-r" 'isearch-repeat-backward)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (define-key isearch-mode-map "\177" 'isearch-delete-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (define-key isearch-mode-map "\C-g" 'isearch-quit)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (define-key isearch-mode-map "\C-q" 'isearch-quote-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 ;; (define-key isearch-mode-map "\r" 'isearch-return-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 ;; For version 19, CR (C-m) terminates search and LFD (C-j) matches eol.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (define-key isearch-mode-map "\r" 'isearch-exit)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (define-key isearch-mode-map "\C-j" 'isearch-printing-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (define-key isearch-mode-map "\C-w" 'isearch-yank-word)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (define-key isearch-mode-map "\C-y" 'isearch-yank-line)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (define-key isearch-mode-map "\C-^" 'isearch-edit-string)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 ;; define keys for regexp chars * ? |
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (define-key isearch-mode-map "*" 'isearch-*-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (define-key isearch-mode-map "?" 'isearch-*-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (define-key isearch-mode-map "|" 'isearch-|-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 ;; Assumes meta-prefix-char is \e.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 ;; isearch-mode-meta-map must be a keymap before this.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (define-key isearch-mode-map "\e" isearch-mode-meta-map)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 ))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 ;;;========================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 ;; Internal variables declared globally for byte-compiler.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 ;; These are all made buffer-local during searching.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (defvar isearch-cmds nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 "Stack of search status sets.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (defvar isearch-string ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 "The current search string.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (defvar isearch-message ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 "The text-char-description version of isearch-string")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (defvar isearch-success t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (defvar isearch-forward nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (defvar isearch-other-end nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 "Start of last match if forward, end if backward.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (defvar isearch-invalid-regexp nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (defvar isearch-wrapped nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (defvar isearch-barrier 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (defvar isearch-regexp nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (defvar isearch-case-fold-search nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 "Value of case-fold-search while actually searching.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (defvar isearch-adjusted nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (defvar isearch-slow-terminal-mode nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (defvar isearch-small-window nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 "If t, using a small window.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (defvar isearch-found-point nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 "to restore point from a small window.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (defvar isearch-found-start nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 "This is the window-start value found by the search.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (defvar isearch-opoint 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (defvar isearch-window-configuration nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 "The window configuration active at the beginning of the search.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (defvar isearch-old-local-map [])
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (defvar isearch-yank-flag nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 "Flag to indicate a yank occurred, so don't move the cursor.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (defvar isearch-op-fun nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 "A function to be called after each input character is processed.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (It is not called after characters that exit the search.)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 It is only set from an optional argument to `isearch-mode'.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 ;; This is a global variable to avoid byte-compile warnings.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (defvar isearch-last-command-char -1
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 "Last command char.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (defvar isearch-mode-hook nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 "List of functions to call after starting up an incremental search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 See `isearch-modal' for an example.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 Set with `(setq isearch-mode-hook (cons 'myhook isearch-mode-hook))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 where myhook can be a function name or lambda expression.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (defvar isearch-mode-end-hook nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 "List of functions to call after terminating an incremental search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 See `isearch-mode-hook' for more details.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 ;;;==============================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 ;; Minor-mode-alist changes - kind of redundant with the
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ;; echo area, but if isearching in multiple windows, it can be useful.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (or (assq 'isearch-mode minor-mode-alist)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (nconc minor-mode-alist
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (list '(isearch-mode isearch-mode))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (defvar isearch-mode nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (make-variable-buffer-local 'isearch-mode)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 ;;;===============================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 ;;; Entry points to isearch-mode.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 ;;; These four functions should be moved to loaddefs.el
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (defun isearch-forward ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 "\
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 Do incremental search forward.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 As you type characters, they add to the search string and are found.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 \\<isearch-mode-map>
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 Type \\[isearch-delete-char] to cancel characters from end of search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 string.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 Type \\[isearch-exit] to exit, leaving point at location found.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 Type \\[isearch-repeat-forward] to search again forward,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 \\[isearch-repeat-backward] to search again backward.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 Type \\[isearch-yank-word] to yank word from buffer onto end of
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 search string and search for it.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 Type \\[isearch-yank-line] to yank rest of line onto end of search string, etc.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 Type \\[isearch-quote-char] to quote control character to search for it.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 Type C-j to match end of line.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 Also supported is a search ring of the previous 16 search strings.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 Type \\[isearch-ring-advance] to search for the next item in the search ring.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 Type \\[isearch-ring-retreat] to search for the previous item in the search ring.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 Other control and meta characters terminate the search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 and are then executed normally.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 \\[isearch-quit] while searching or when search has failed
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 cancels input back to what has been found successfully.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 \\[isearch-quit] when search is successful aborts and moves point to starting point.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 All of these keys are bound in `isearch-mode-map' and
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 `isearch-mode-meta-map'. If `isearch-forward' is called
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 non-interactively, it does not return to the calling function until
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 the search is done."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (if (interactive-p)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (isearch-mode t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (isearch-modal t)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 (defun isearch-forward-regexp ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 "\
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 Do incremental search forward for regular expression.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 Like ordinary incremental search except that your input
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 is treated as a regexp. See \\[isearch-forward] for more info."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (if (interactive-p)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (isearch-mode t t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (isearch-modal t t)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (defun isearch-backward ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 "\
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 Do incremental search backward.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 See \\[isearch-forward] for more information."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (if (interactive-p)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (isearch-mode nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (isearch-modal nil)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (defun isearch-backward-regexp ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 "\
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 Do incremental search backward for regular expression.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 Like ordinary incremental search except that your input
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 is treated as a regexp. See \\[isearch-forward] for more info."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (if (interactive-p)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (isearch-mode nil t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (isearch-modal nil t)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (defun isearch-modal (forward &optional regexp op-fun)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 ;; As an example of using the hooks, isearch-mode can be made
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 ;; modal (in the sense of not returning to the calling function
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 ;; until searching is completed) by entering a recursive-edit.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 ;; This is used if the above functions are called non-interactively.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (let ((isearch-mode-hook
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (cons (function (lambda () (recursive-edit)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 isearch-mode-hook))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (isearch-mode-end-hook
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (cons (function (lambda () (exit-recursive-edit)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 isearch-mode-end-hook)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 (isearch-mode forward regexp op-fun)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 ;;;==================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 ;; isearch-mode only sets up incremental search for the minor mode.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 ;; All the work is done by the isearch-mode commands.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (defun isearch-mode (forward &optional regexp op-fun)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 "Start isearch minor mode. Called by isearch-forward, etc."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 ;; Make buffer-local variables for isearching.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 ;; We really need window-local variables.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 (mapcar
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 'make-local-variable
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 '(isearch-forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 isearch-regexp isearch-string isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 isearch-case-fold-search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 isearch-cmds isearch-success isearch-wrapped
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 isearch-barrier isearch-adjusted isearch-invalid-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 isearch-slow-terminal-mode isearch-other-end isearch-small-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 isearch-found-point isearch-found-start isearch-opoint
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 isearch-window-configuration isearch-old-local-map))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 ;; Initialize global vars.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 (setq isearch-forward forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 isearch-regexp regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 isearch-op-fun op-fun
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 isearch-case-fold-search case-fold-search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 isearch-string ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 isearch-message ""
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 isearch-cmds nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 isearch-success t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 isearch-wrapped nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 isearch-barrier (point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 isearch-adjusted nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 isearch-yank-flag nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 isearch-invalid-regexp nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 isearch-slow-terminal-mode (and (<= (baud-rate) search-slow-speed)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 (> (window-height)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 (* 4 search-slow-window-lines)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 isearch-other-end nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 isearch-small-window nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 isearch-found-point nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 isearch-found-start nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 isearch-opoint (point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 isearch-window-configuration (current-window-configuration)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 isearch-old-local-map (current-local-map)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 ;; inhibit-quit t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (setq isearch-mode " Isearch") ;; forward? regexp?
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 (set-buffer-modified-p (buffer-modified-p)) ; update modeline
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 (isearch-push-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 (use-local-map isearch-mode-map)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 (isearch-update)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 (run-hooks 'isearch-mode-hook)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 ;;;====================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 ;; Some high level utilities. Others below.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (defun isearch-update ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 ;; Called after each command to update the display.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 (or unread-command-char
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 (if (not (input-pending-p))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 (isearch-message))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 (if (and isearch-slow-terminal-mode
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 (not (or isearch-small-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 (pos-visible-in-window-p))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (setq isearch-small-window t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 (setq isearch-found-point (point))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 (move-to-window-line 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (let ((window-min-height 1))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (split-window nil (if (< search-slow-window-lines 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 (1+ (- search-slow-window-lines))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 (- (window-height)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 (1+ search-slow-window-lines)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (if (< search-slow-window-lines 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 (progn (vertical-motion (- 1 search-slow-window-lines))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (set-window-start (next-window) (point))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 (set-window-hscroll (next-window)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (window-hscroll))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (set-window-hscroll (selected-window) 0))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (other-window 1))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 (goto-char isearch-found-point)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 (setq ;; quit-flag nil not for isearch-mode
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 isearch-adjusted nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 isearch-yank-flag nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 (defun isearch-done ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 ;; Called by all commands that terminate isearch-mode.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 (use-local-map isearch-old-local-map)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 (setq isearch-found-start (window-start (selected-window)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 (setq isearch-found-point (point))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 (set-window-configuration isearch-window-configuration)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 (if (> (length isearch-string) 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 ;; Update the ring data.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 (if (not (setq regex-search-ring-yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (memq isearch-string regex-search-ring)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (setq regex-search-ring (cons isearch-string regex-search-ring)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 regex-search-ring-yank-pointer regex-search-ring)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (if (> (length regex-search-ring) regex-search-ring-max)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 (setcdr (nthcdr (1- search-ring-max) regex-search-ring)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 nil))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (if (not (setq search-ring-yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 (memq isearch-string search-ring)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 (setq search-ring (cons isearch-string search-ring)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 search-ring-yank-pointer search-ring)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 (if (> (length search-ring) search-ring-max)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 ;; If there was movement, mark the starting position.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 ;; Maybe should test difference between and set mark iff > threshold.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 (if (/= (point) isearch-opoint)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (push-mark isearch-opoint)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (message ""))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (if isearch-small-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 (goto-char isearch-found-point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 ;; Exiting the save-window-excursion clobbers window-start; restore it.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (set-window-start (selected-window) isearch-found-start t))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 ;; Kill buffer-local variables for isearching
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (mapcar
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 'kill-local-variable
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 '(isearch-forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 isearch-regexp isearch-string isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 isearch-case-fold-search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 isearch-cmds isearch-success isearch-wrapped
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 isearch-barrier isearch-adjusted isearch-invalid-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 isearch-slow-terminal-mode isearch-other-end isearch-small-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 isearch-found-point isearch-found-start isearch-opoint
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 isearch-window-configuration isearch-old-local-map))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 (setq isearch-mode nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 (set-buffer-modified-p (buffer-modified-p))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 (run-hooks 'isearch-mode-end-hook)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 ;;;====================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 ;; Commands active while inside of the isearch minor mode.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 (defun isearch-exit ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 "Exit search normally.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 However, if this is the first command after starting incremental
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 search and `search-nonincremental-instead' is non-nil, do a
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 nonincremental search instead."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 (if (and search-nonincremental-instead
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (= 0 (length isearch-string)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (nonincremental-search isearch-forward isearch-regexp))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (isearch-done))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (defun isearch-edit-string ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 "Edit the search string in the minibuffer and return to incremental search."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 ;; This doesnt back up the search point.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 (setq isearch-string (read-string (isearch-message-prefix) isearch-string)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 isearch-message (mapconcat 'text-char-description
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 isearch-string ""))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 (isearch-push-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 (isearch-search)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (defun isearch-quit ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 "Quit incremental search mode if searching is successful.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 Otherwise, revert to previous successful search and continue searching."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (ding)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 (discard-input)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 (if isearch-success
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 ;; If search is successful, move back to starting point
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 ;; and really do quit.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (progn (goto-char isearch-opoint)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 (isearch-done)) ; exit and quit
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 ;; If search is failing, rub out until it is once more
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 ;; successful.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 (while (not isearch-success) (isearch-pop-state))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 (isearch-update)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 (defun isearch-repeat (direction)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 ;; Utility for isearch-repeat-forward and -backward.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 (if (eq isearch-forward (eq direction 'forward))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 ;; C-s in forward or C-r in reverse.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 (if (equal isearch-string "")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 ;; If search string is empty, use last one.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (setq isearch-string
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 ;; (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 ;; search-last-regexp search-last-string)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 (or (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 (if regex-search-ring-yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 (car regex-search-ring-yank-pointer)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (car regex-search-ring))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (if search-ring-yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 (car search-ring-yank-pointer)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (car search-ring)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 "")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 (mapconcat 'text-char-description
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 isearch-string ""))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 ;; If already have what to search for, repeat it.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 (or isearch-success
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 (goto-char (if isearch-forward (point-min) (point-max)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (setq isearch-wrapped t))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 ;; C-s in reverse or C-r in forward, change direction.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 (setq isearch-forward (not isearch-forward)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (setq isearch-success t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 (or (equal isearch-string "")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 ;; If repeating a search that found
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 ;; an empty string, ensure we advance.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 (if (equal (match-end 0) (match-beginning 0))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 (forward-char (if isearch-forward 1 -1)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 (isearch-search)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 (isearch-push-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 (defun isearch-repeat-forward ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 "Repeat incremental search forwards."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 (isearch-repeat 'forward))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 (defun isearch-repeat-backward ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 "Repeat incremental search backwards."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 (isearch-repeat 'backward))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 (defun isearch-toggle-regexp ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 "Toggle regexp searching on or off."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 ;; The status stack is left unchanged.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 (setq isearch-regexp (not isearch-regexp))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 (defun isearch-delete-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 "Discard last input item and move point back.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 If no previous match was done, just beep."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 (if (null (cdr isearch-cmds))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 (ding)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 (isearch-pop-state))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 (defun isearch-yank (chunk)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 ;; Helper for isearch-yank-word and isearch-yank-line
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 (let ((word (save-excursion
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 (and (not isearch-forward) isearch-other-end
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 (goto-char isearch-other-end))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 (buffer-substring
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 (point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 (save-excursion
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 (cond
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 ((eq chunk 'word)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 (forward-word 1))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 ((eq chunk 'line)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 (end-of-line)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 (point))))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 (if isearch-regexp (setq word (regexp-quote word)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 (setq isearch-string (concat isearch-string word)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 (concat isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 (mapconcat 'text-char-description
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 word ""))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 ;; Don't move cursor in reverse search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 isearch-yank-flag t))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 (isearch-search-and-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 (defun isearch-yank-word ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 "Pull next word from buffer into search string."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 (isearch-yank 'word))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 (defun isearch-yank-line ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 "Pull rest of line from buffer into search string."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 (isearch-yank 'line))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 (defun isearch-search-and-update ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 ;; Do the search and update the display.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 (if (and (not isearch-success)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 ;; unsuccessful regexp search may become
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 ;; successful by addition of characters which
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 ;; make isearch-string valid
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 (not isearch-regexp))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 ;; In reverse search, adding stuff at
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 ;; the end may cause zero or many more chars to be
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 ;; matched, in the string following point.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 ;; Allow all those possibilities without moving point as
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694 ;; long as the match does not extend past search origin.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 (if (and (not isearch-forward) (not isearch-adjusted)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 (condition-case ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 (looking-at (if isearch-regexp isearch-string
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 (regexp-quote isearch-string)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 (error nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 (or isearch-yank-flag
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 (<= (match-end 0)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 (min isearch-opoint isearch-barrier))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 (setq isearch-success t
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 isearch-invalid-regexp nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 isearch-other-end (match-end 0))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 ;; Not regexp, not reverse, or no match at point.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 (if (and isearch-other-end (not isearch-adjusted))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 (goto-char (if isearch-forward isearch-other-end
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 (min isearch-opoint
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 isearch-barrier
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 (1+ isearch-other-end)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 (isearch-search)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 ))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 (isearch-push-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 (if isearch-op-fun (funcall isearch-op-fun))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 ;; *, ?, and | chars can make a regexp more liberal.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 ;; They can make a regexp match sooner
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 ;; or make it succeed instead of failing.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 ;; So go back to place last successful search started
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 ;; or to the last ^S/^R (barrier), whichever is nearer.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 (defun isearch-*-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 "Handle * and ? specially in regexps."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 (setq isearch-adjusted t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 (let ((cs (nth (if isearch-forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 5 ; isearch-other-end
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 2) ; saved (point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 (car (cdr isearch-cmds)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 ;; (car isearch-cmds) is after last search;
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 ;; (car (cdr isearch-cmds)) is from before it.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 (setq cs (or cs isearch-barrier))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 (goto-char
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
740 (if isearch-forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 (max cs isearch-barrier)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742 (min cs isearch-barrier))))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 (isearch-process-search-char last-command-char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 (defun isearch-|-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 "If in regexp search, jump to the barrier."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 (setq isearch-adjusted t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 (goto-char isearch-barrier)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
754 (isearch-process-search-char last-command-char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
755
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 (defun isearch-other-control-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 "Any other control char => unread it and exit the search normally.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 But only if `search-exit-option' is non-nil."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 (if search-exit-option
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 (setq unread-command-char last-command-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 (isearch-done))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 ;; otherwise
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 (isearch-search-and-update)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
768
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 (defun isearch-other-meta-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 "Any other meta char => exit the search normally and reexecute the whole key.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 But only if `search-exit-option' is non-nil."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 ;; This will probably work in place of isearch-other-control-char too,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 ;; but here we use unwind-protect and command-execute since it is
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 ;; a multi-char key we would want to unread.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 (if search-exit-option
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 (unwind-protect
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 (isearch-done) ;; this exits recursive edit
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 ;; Reexecute the key.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 (command-execute (this-command-keys)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 ;; otherwise
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783 (isearch-search-and-update)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 (defun isearch-quote-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 "Quote special characters for incremental search."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 (isearch-process-search-char (read-quoted-char (isearch-message t))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 (defun isearch-return-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 "Convert return into newline for incremental search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 Obsolete."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 (isearch-process-search-char ?\n))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799 (defun isearch-printing-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 "Any other printing character => add it to the search string and search."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 (isearch-process-search-char last-command-char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 (defun isearch-upper-case-char ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 "Any upper case char => turn off case fold search for remainder of search."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 ;; This feature only applies to interactively entered chars,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 ;; but not yanked chars, repeat default searches, or search ring searches.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 ;; Support for these should be easy to add.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
810 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 (if search-caps-disable-folding
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 (setq isearch-case-fold-search nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 (isearch-printing-char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815 (defun isearch-whitespace-chars ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
816 "Match all whitespace chars, if in regexp mode."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 (if (and isearch-regexp search-whitespace-regexp)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 (isearch-process-search-string search-whitespace-regexp " ")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 (isearch-other-meta-char)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 (defun isearch-process-search-char (char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 ;; Append the char to the search string, update the message and re-search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 (isearch-process-search-string (char-to-string char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 (text-char-description char)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 (defun isearch-process-search-string (string message)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829 (setq isearch-string (concat isearch-string string)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 isearch-message (concat isearch-message message))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831 (isearch-search-and-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834 ;;===========================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 ;; Search Ring
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 (defun isearch-ring-adjust (advance)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 ;; helper for isearch-ring-advance and isearch-ring-retreat
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 (if (cdr isearch-cmds)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 (isearch-pop-state))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 (let* ((ring (if isearch-regexp regex-search-ring search-ring))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842 (length (length ring))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843 (yank-pointer-name (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844 'regex-search-ring-yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 'search-ring-yank-pointer))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 (yank-pointer (eval yank-pointer-name)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847 (if (zerop length)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 (set yank-pointer-name
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850 (setq yank-pointer
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 (nthcdr (% (+ (- length (length yank-pointer))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 (if advance (1- length) 1))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 length) ring)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 (setq isearch-string (car yank-pointer)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 isearch-message (mapconcat 'text-char-description
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 isearch-string ""))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 (isearch-push-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 (isearch-search)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 (isearch-update))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 (defun isearch-ring-advance ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 "Advance to the next search string in the ring."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 (isearch-ring-adjust 'advance))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 (defun isearch-ring-retreat ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 "Retreat to the previous search string in the ring."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 (interactive)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 (isearch-ring-adjust nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 ;;;=============================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 ;; Window-local variables
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 ;; (not used yet - and maybe never)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876 (defvar window-local-variable-alist nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
877 "An alist of windows associated with window local variables and values.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
878 The cdr of each item is another alist of variables and values.")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
879
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 (defvar last-local-window nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 (defvar last-window-local-vars nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 (defun kill-window-local-variables ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 "Remove the old variable list, if any."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 (setq window-local-variable-alist
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 (delq window-local-variable-alist
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 (assq (selected-window)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 window-local-variable-alist))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 ;; Assume that window-local variables are not buffer-local
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 ;; so we can delay storing until absolutely necessary.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 (defun store-window-local-variables (&rest vars-and-vals)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 "Store the window local variables for selected window."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895 (setq last-local-window (selected-window))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 (setq last-window-local-vars vars-and-vals))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 (defun fetch-window-local-variables ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 "Fetch the window local variables for selected window.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
901 Does nothing if the last store was for the same window."
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902 (if (not (eq (selected-window) last-local-window))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 (progn
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 ;; First store the previous values.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 (setq window-local-variable-alist
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 (cons (cons last-local-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 last-window-local-vars)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 (delq window-local-variable-alist
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 (assq last-local-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 window-local-variable-alist))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 ;; Now fetch the values for the selected-window.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 (setq last-local-window (selected-window))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 (setq last-window-local-vars
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 (cdr (assq last-local-window window-local-variable-alist)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 (let ((vars-and-vals last-window-local-vars))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 (while vars-and-vals
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 (set (car vars-and-vals) (car (cdr vars-and-vals)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 (setq vars-and-vals (cdr (cdr vars-and-vals))))))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 ;;;==============================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 ;; The search status stack (and isearch window-local variables, not used).
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 (defun isearch-top-state ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 ;; (fetch-window-local-variables)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 (let ((cmd (car isearch-cmds)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 (setq isearch-string (car cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 isearch-message (car (cdr cmd))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930 isearch-success (nth 3 cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
931 isearch-forward (nth 4 cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
932 isearch-other-end (nth 5 cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 isearch-invalid-regexp (nth 6 cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 isearch-wrapped (nth 7 cmd)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 isearch-barrier (nth 8 cmd))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 (goto-char (car (cdr (cdr cmd))))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
937
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938 (defun isearch-pop-state ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 ;; (fetch-window-local-variables)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940 (setq isearch-cmds (cdr isearch-cmds))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941 (isearch-top-state)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942 )
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
943
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 (defun isearch-push-state ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 (setq isearch-cmds
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 (cons (list isearch-string isearch-message (point)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 isearch-success isearch-forward isearch-other-end
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948 isearch-invalid-regexp isearch-wrapped isearch-barrier)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
949 isearch-cmds)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951 (defun isearch-store-variables ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 (store-window-local-variables
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 'isearch-cmds isearch-cmds
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954 'isearch-regexp isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955 'isearch-adjusted isearch-adjusted
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 'isearch-slow-terminal-mode isearch-slow-terminal-mode
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 'isearch-small-window isearch-small-window
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 'isearch-found-point isearch-found-point
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 'isearch-found-start isearch-found-start
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960 'isearch-opoint isearch-opoint
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 'isearch-window-configuration isearch-window-configuration
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962 'isearch-old-local-map isearch-old-local-map
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 ))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 ;;;==================================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967 ;; Message string
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 (defun isearch-message (&optional c-q-hack ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970 ;; Generate and print the message string.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 (let ((cursor-in-echo-area ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
972 (m (concat
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973 (isearch-message-prefix c-q-hack ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 (isearch-message-suffix c-q-hack ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 )))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
977 (if c-q-hack m (message "%s" m))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
979 (defun isearch-message-prefix (&optional c-q-hack ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
980 ;; If about to search, and previous search regexp was invalid,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
981 ;; check that it still is. If it is valid now,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
982 ;; let the message we display while searching say that it is valid.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
983 (and isearch-invalid-regexp ellipsis
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
984 (condition-case ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
985 (progn (re-search-forward isearch-string (point) t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 (setq isearch-invalid-regexp nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
987 (error nil)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988 ;; If currently failing, display no ellipsis.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
989 (or isearch-success (setq ellipsis nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
990 (let ((m (concat (if isearch-success "" "failing ")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
991 (if isearch-wrapped "wrapped ")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
992 (if isearch-regexp "regexp " "")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
993 "I-search"
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
994 (if isearch-forward ": " " backward: ")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
995 )))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
996 (aset m 0 (upcase (aref m 0)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 m))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
999
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1000 (defun isearch-message-suffix (&optional c-q-hack ellipsis)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1001 (concat (if c-q-hack "^Q" "")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1002 (if isearch-invalid-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1003 (concat " [" isearch-invalid-regexp "]")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1004 "")))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1005
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1006
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007 ;;;========================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1008 ;;; Searching
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1009
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1010 (defun isearch-search ()
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011 ;; Do the search with the current search string.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1012 (isearch-message nil t)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1013 (condition-case lossage
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1014 (let ((inhibit-quit nil)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1015 (case-fold-search isearch-case-fold-search))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016 (if isearch-regexp (setq isearch-invalid-regexp nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1017 (setq isearch-success
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1018 (funcall
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1019 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1020 (if isearch-forward 're-search-forward 're-search-backward)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1021 (if isearch-forward 'search-forward 'search-backward))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1022 isearch-string nil t))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1023 (if isearch-success
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1024 (setq isearch-other-end
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1025 (if isearch-forward (match-beginning 0) (match-end 0)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1026
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1027 (quit (setq unread-command-char ?\C-g)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1028 (setq isearch-success nil))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1029
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1030 (invalid-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1031 (setq isearch-invalid-regexp (car (cdr lossage)))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032 (if (string-match
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 isearch-invalid-regexp)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035 (setq isearch-invalid-regexp "incomplete input"))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 (if isearch-success
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1038 nil
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1039 ;; Ding if failed this time after succeeding last time.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1040 (and (nth 3 (car isearch-cmds))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1041 (ding))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1042 (goto-char (nth 2 (car isearch-cmds)))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1043
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1044 ;;;=================================================
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1045 ;; This is called from incremental-search
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046 ;; if the first input character is the exit character.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1047
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1048 ;; We store the search string in `isearch-string'
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1049 ;; which has been bound already by `isearch-search'
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1050 ;; so that, when we exit, it is copied into `search-last-string'.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1051
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1052 (defun nonincremental-search (forward regexp)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053 ;; This may be broken. Anyway, it could be replaced by the
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 ;; isearch-edit-string command instead.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1055 (setq isearch-forward forward
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 isearch-regexp regexp)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1057 (let (char function
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 inhibit-quit
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1059 (cursor-in-echo-area t))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1060 ;; Prompt assuming not word search,
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1061 (setq isearch-message
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1062
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1063 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1064
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1065 (if isearch-forward "Regexp search: "
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1066 "Regexp search backward: ")
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1067 (if isearch-forward "Search: " "Search backward: ")))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1068 (message "%s" isearch-message)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1069 ;; Read 1 char and switch to word search if it is ^W.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1070 (setq char (read-char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1071 (if (eq char search-yank-word-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1072 (setq isearch-message (if isearch-forward "Word search: "
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1073
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1074 "Word search backward: "))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1075 ;; Otherwise let that 1 char be part of the search string.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1076 (setq unread-command-char char))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1077 (setq function
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1078 (if (eq char search-yank-word-char)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 (if isearch-forward 'word-search-forward 'word-search-backward)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1080 (if isearch-regexp
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081 (if isearch-forward 're-search-forward 're-search-backward)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1082 (if isearch-forward 'search-forward 'search-backward))))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1083 ;; Read the search string with corrected prompt.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1084 (setq isearch-string (read-string isearch-message isearch-string))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1085 ;; Empty means use default.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1086 (if (= 0 (length isearch-string))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1087 (setq isearch-string search-last-string)
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1088 ;; Set last search string now so it is set even if we fail.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1089 (setq search-last-string isearch-string))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1090 ;; Since we used the minibuffer, we should be available for redo.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1091 (setq command-history
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1092
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1093 (cons (list function isearch-string) command-history))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1094 ;; Go ahead and search.
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1095 (let ((case-fold-search isearch-case-fold-search))
75e4ec1e938f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1096 (funcall function isearch-string))))