annotate lisp/isearch.el @ 765:e4093444f9f8

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