annotate lisp/isearch.el @ 809:8a0066235d56

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