annotate lisp/prim/isearch-mode.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents 376386a54a3c
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Incremental search minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; isearch-mode|Daniel LaLiberte|liberte@cs.uiuc.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; |A minor mode replacement for isearch.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: Not synched with FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;====================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Instructions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Searching with isearch-mode.el should work just like isearch.el,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; except it is done in a temporary minor mode that terminates when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; you finish searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Semi-modal searching is supported, using a recursive edit. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; isearching is started non-interactively by calling one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; isearch commands (e.g. (isearch-forward), but not like gnus does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; it: (call-interactively 'isearch-forward)), isearch-mode does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; return until the search is completed. You should still be able
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; switch buffers, so be careful not to get things confused.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; The key bindings active within isearch-mode are defined below in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; `isearch-mode-map' which is given bindings close to the default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; characters of isearch.el for version 19. With `isearch-mode',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; however, you can bind multi-character keys and it should be easier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; to add new commands. One bug though: keys with meta-prefix cannot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; be longer than two chars. Also see minibuffer-local-isearch-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; for bindings active during `isearch-edit-string'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; The search ring and completion commands automatically put you in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; the minibuffer to edit the string. This gives you a chance to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; modify the search string before executing the search. There are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; three commands to terminate the editing: C-s and C-r exit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; minibuffer and search forward and reverse respectively, while C-m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; exits and does a nonincremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; Exiting immediately from isearch uses isearch-edit-string instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; The name of this option should probably be changed if we decide to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; keep the behavior. One difference is that isearch-edit-string does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; not support word search yet; perhaps isearch-mode should support it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; even for incremental searches, but how?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;;====================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Change History
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; Header: /import/kaplan/kaplan/liberte/Isearch/RCS/isearch-mode.el,v 1.3 92/06/29 13:10:08 liberte Exp Locker: liberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; Log: isearch-mode.el,v
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; 20-aug-92 Hacked by jwz for Lucid Emacs 19.3.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; Revision 1.3 92/06/29 13:10:08 liberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; Moved modal isearch-mode handling into isearch-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; Got rid of buffer-local isearch variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; isearch-edit-string used by ring adjustments, completion, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; nonincremental searching. C-s and C-r are additional exit commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; Renamed all regex to regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; Got rid of found-start and found-point globals.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; Generalized handling of upper-case chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; Revision 1.2 92/05/27 11:33:57 liberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; Emacs version 19 has a search ring, which is supported here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; Other fixes found in the version 19 isearch are included here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; Also see variables search-caps-disable-folding,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; search-nonincremental-instead, search-whitespace-regexp, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; commands isearch-toggle-regexp, isearch-edit-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; semi-modal isearching is supported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; Changes for 1.1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; 3/18/92 Fixed invalid-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; 3/18/92 Fixed yanking in regexps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun isearch-char-to-string (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (integerp c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (make-string 1 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (make-string 1 (event-to-character c nil nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;(defun isearch-text-char-description (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ; (isearch-char-to-string c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (define-function 'isearch-text-char-description 'text-char-description)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;;=========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; User-accessible variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defvar search-last-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Last string search for by a search command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 This does not include direct calls to the primitive search functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 and does not include searches that are aborted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defvar search-last-regexp ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "Last string searched for by a regexp search command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 This does not include direct calls to the primitive search functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 and does not include searches that are aborted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defconst search-exit-option t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Non-nil means random control characters terminate incremental search.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defvar search-slow-window-lines 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 "*Number of lines in slow search display windows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 These are the short windows used during incremental search on slow terminals.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Negative means put the slow search window at the top (normally it's at bottom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 and the value is minus the number of lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defconst search-slow-speed 1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "*Highest terminal speed at which to use \"slow\" style incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 This is the style where a one-line window is created to show the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 that the search has reached.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defvar search-caps-disable-folding t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "*If non-nil, upper case chars disable case fold searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 This does not apply to \"yanked\" strings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defvar search-nonincremental-instead t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "*If non-nil, do a nonincremental search instead if exiting immediately.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defconst search-whitespace-regexp "\\(\\s \\|[\n\r]\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "*If non-nil, regular expression to match a sequence of whitespace chars.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;;==================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; Search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar search-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "List of search string sequences.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defvar regexp-search-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "List of regular expression search string sequences.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defconst search-ring-max 16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "*Maximum length of search ring before oldest elements are thrown away.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defconst regexp-search-ring-max 16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "*Maximum length of regexp search ring before oldest elements are thrown away.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defvar search-ring-yank-pointer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "The tail of the search ring whose car is the last thing searched for.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defvar regexp-search-ring-yank-pointer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 "The tail of the regular expression search ring whose car is the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 thing searched for.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;;====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;; Define isearch-mode keymap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defvar isearch-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((map (make-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (set-keymap-name map 'isearch-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; Bind all printing characters to `isearch-printing-char'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; This isn't normally necessary, but if a printing character were
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; bound to something other than self-insert-command in global-map,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; then it would terminate the search and be executed without this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let ((i 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (str (make-string 1 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (while (< i 127)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (aset str 0 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (define-key map str 'isearch-printing-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (define-key map "\t" 'isearch-printing-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Several non-printing chars change the searching behavior.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (define-key map "\C-s" 'isearch-repeat-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (define-key map "\M-\C-s" 'isearch-repeat-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (define-key map "\C-r" 'isearch-repeat-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (define-key map "\177" 'isearch-delete-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (define-key map "\C-g" 'isearch-abort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (define-key map "\C-q" 'isearch-quote-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (define-key map "\C-m" 'isearch-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (define-key map "\C-j" 'isearch-printing-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (define-key map "\t" 'isearch-printing-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (define-key map "\C-w" 'isearch-yank-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (define-key map "\C-y" 'isearch-yank-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; Define keys for regexp chars * ? |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (define-key map "*" 'isearch-*-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (define-key map "?" 'isearch-*-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (define-key map "|" 'isearch-|-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Some bindings you may want to put in your isearch-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Suggest some alternates...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; (define-key map "\C-t" 'isearch-toggle-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; (define-key map "\C-^" 'isearch-edit-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; backspace deletes, but C-h is help.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (define-key map 'backspace 'isearch-delete-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (define-key map '(control h) 'isearch-mode-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (define-key map "\M-n" 'isearch-ring-advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (define-key map "\M-p" 'isearch-ring-retreat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (define-key map "\M- " 'isearch-whitespace-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (define-key map "\M-\t" 'isearch-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (define-key map 'button2 'isearch-yank-x-selection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Keymap for isearch-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defvar minibuffer-local-isearch-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; #### - this should also be minor-mode-ified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (set-keymap-parents map (list minibuffer-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (set-keymap-name map 'minibuffer-local-isearch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;;#### This should just arrange to use the usual Emacs minibuffer histories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (define-key map "\M-n" 'isearch-ring-advance-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (define-key map "\M-p" 'isearch-ring-retreat-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (define-key map "\M-\t" 'isearch-complete-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Keymap for editing isearch strings in the minibuffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;;;========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; Internal variables declared globally for byte-compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; These are all bound locally while editing the search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defvar isearch-forward nil) ; Searching in the forward direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (defvar isearch-regexp nil) ; Searching for a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defvar isearch-word nil) ; Searching for words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defvar isearch-cmds nil) ; Stack of search status sets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defvar isearch-string "") ; The current search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defvar isearch-message "") ; text-char-description version of isearch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defvar isearch-success t) ; Searching is currently successful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defvar isearch-barrier 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defvar isearch-buffer nil) ; the buffer we've frobbed the keymap of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defvar isearch-case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defvar isearch-adjusted nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defvar isearch-slow-terminal-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;;; If t, using a small window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defvar isearch-small-window nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defvar isearch-opoint 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;; The window configuration active at the beginning of the search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defvar isearch-window-configuration nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defvar isearch-selected-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; Flag to indicate a yank occurred, so don't move the cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (defvar isearch-yank-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;; A function to be called after each input character is processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;;; (It is not called after characters that exit the search.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;; It is only set from an optional argument to `isearch-mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defvar isearch-op-fun nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;;; Is isearch-mode in a recursive edit for modal searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defvar isearch-recursive-edit nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;; Should isearch be terminated after doing one search?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defvar isearch-nonincremental nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; New value of isearch-forward after isearch-edit-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defvar isearch-new-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defvar isearch-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 "Function(s) to call after starting up an incremental search.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defvar isearch-mode-end-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Function(s) to call after terminating an incremental search.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;;;==============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; Minor-mode-alist changes - kind of redundant with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; echo area, but if isearching in multiple windows, it can be useful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (add-minor-mode 'isearch-mode 'isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defvar isearch-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (make-variable-buffer-local 'isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;;;===============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;; Entry points to isearch-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;;; These four functions should replace those in loaddefs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;;; An alternative is to fset isearch-forward etc to isearch-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;; and look at the last command to set the options accordingly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defun isearch-forward (&optional regexp-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "Do incremental search forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 With a prefix argument, do an incremental regular expression search instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 \\<isearch-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 As you type characters, they add to the search string and are found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 The following non-printing keys are bound in `isearch-mode-map'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 Type \\[isearch-delete-char] to cancel characters from end of search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 Type \\[isearch-exit] to exit, leaving point at location found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Type LFD (C-j) to match end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Type \\[isearch-repeat-forward] to search again forward,\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 \\[isearch-repeat-backward] to search again backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 string and search for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 and search for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 Type \\[isearch-quote-char] to quote control character to search for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 Type \\[isearch-whitespace-chars] to match all whitespace chars in regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 \\[isearch-abort] while searching or when search has failed cancels input\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 back to what has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 been found successfully.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 \\[isearch-abort] when search is successful aborts and moves point to\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 starting point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 Also supported is a search ring of the previous 16 search strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 Type \\[isearch-ring-advance] to search for the next item in the search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 Type \\[isearch-ring-retreat] to search for the previous item in the search\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 Type \\[isearch-complete] to complete the search string using the search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 The above keys are bound in the isearch-mode-map. To change the keys which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 are special to isearch-mode, simply change the bindings in that map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 Other control and meta characters terminate the search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 and are then executed normally (depending on `search-exit-option').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 If this function is called non-interactively, it does not return to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 the calling function until the search is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 The bindings, more precisely:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 \\{isearch-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; Non-standard bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; Type \\[isearch-edit-string] to edit the search string in the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; Terminate editing and return to incremental searching with CR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (isearch-mode t (not (null regexp-p)) nil (not (interactive-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (defun isearch-forward-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Do incremental search forward for regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 Like ordinary incremental search except that your input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 is treated as a regexp. See \\[isearch-forward] for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (isearch-mode t t nil (not (interactive-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defun isearch-backward (&optional regexp-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 Do incremental search backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 With a prefix argument, do an incremental regular expression search instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 See \\[isearch-forward] for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (isearch-mode nil (not (null regexp-p)) nil (not (interactive-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (defun isearch-backward-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 Do incremental search backward for regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 Like ordinary incremental search except that your input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 is treated as a regexp. See \\[isearch-forward] for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (isearch-mode nil t nil (not (interactive-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (defun isearch-mode-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (describe-function 'isearch-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;;;==================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; isearch-mode only sets up incremental search for the minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; All the work is done by the isearch-mode commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "Start isearch minor mode. Called by isearch-forward, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if executing-kbd-macro (setq recursive-edit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (let ((inhibit-quit t)) ; don't leave things in an inconsistent state...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;; Initialize global vars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (setq isearch-buffer (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 isearch-forward forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 isearch-regexp regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 isearch-word word-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 isearch-op-fun op-fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 isearch-case-fold-search case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 isearch-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 isearch-message ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 isearch-cmds nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 isearch-success t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 isearch-wrapped nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 isearch-barrier (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 isearch-adjusted nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 isearch-yank-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 isearch-invalid-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 isearch-slow-terminal-mode (and (<= (device-baud-rate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 search-slow-speed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (> (window-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (* 4 search-slow-window-lines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 isearch-other-end nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 isearch-small-window nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 isearch-opoint (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 isearch-window-configuration (current-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;; #### - don't do this statically: isearch-mode must be FIRST in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; the minor-mode-map-alist -- Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 minor-mode-map-alist (cons (cons 'isearch-mode isearch-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 isearch-selected-frame (selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 isearch-mode (gettext " Isearch")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; XEmacs change: without clearing the match data, sometimes old values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;; of isearch-other-end get used. Don't ask me why...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (store-match-data nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (add-hook 'pre-command-hook 'isearch-pre-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (set-buffer-modified-p (buffer-modified-p)) ; update modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (isearch-push-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ) ; inhibit-quit is t before here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (isearch-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (run-hooks 'isearch-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; isearch-mode can be made modal (in the sense of not returning to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; the calling function until searching is completed) by entering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; a recursive-edit and exiting it when done isearching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if recursive-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (let ((isearch-recursive-edit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (recursive-edit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;;;====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; Some high level utilities. Others below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (defun isearch-update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; Called after each command to update the display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if (null unread-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if (not (input-pending-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (isearch-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (if (and isearch-slow-terminal-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (not (or isearch-small-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (pos-visible-in-window-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (let ((found-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq isearch-small-window t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (move-to-window-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (let ((window-min-height 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (split-window nil (if (< search-slow-window-lines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (1+ (- search-slow-window-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (- (window-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (1+ search-slow-window-lines)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (if (< search-slow-window-lines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (progn (vertical-motion (- 1 search-slow-window-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (set-window-start (next-window) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (set-window-hscroll (next-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (window-hscroll))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (set-window-hscroll (selected-window) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (other-window 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (goto-char found-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (if isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (if (< isearch-other-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (isearch-highlight isearch-other-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (isearch-highlight (point) isearch-other-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (if (extentp isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (isearch-dehighlight nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq ;; quit-flag nil not for isearch-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 isearch-adjusted nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 isearch-yank-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (defun isearch-done ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;; Called by all commands that terminate isearch-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (let ((inhibit-quit t)) ; danger danger!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (if (and isearch-buffer (buffer-live-p isearch-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;; Some loser process filter might have switched the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;; window's buffer, so be sure to set these variables back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;; in the buffer we frobbed them in. But only if the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; is still alive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (set-buffer isearch-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (setq minor-mode-map-alist (delq (assoc 'isearch-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; Use remove-hook instead of just setting it to our saved value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; in case some process filter has created a buffer and modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; the pre-command-hook in that buffer... yeah, this is obscure,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; and yeah, I was getting screwed by it. -jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (set-keymap-parents isearch-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (setq isearch-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (set-buffer-modified-p (buffer-modified-p));; update modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (isearch-dehighlight t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; it's not critical that this be inside inhibit-quit, but leaving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; things in small-window-mode would be bad.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let ((found-start (window-start (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (found-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (cond ((eq (selected-frame) isearch-selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (set-window-configuration isearch-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (if isearch-small-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (goto-char found-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; Exiting the save-window-excursion clobbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; window-start; restore it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (set-window-start (selected-window) found-start t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;; If there was movement, mark the starting position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; Maybe should test difference between and set mark iff > threshold.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (if (and (buffer-live-p isearch-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (/= (point isearch-buffer) isearch-opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (push-mark isearch-opoint t nil isearch-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (or executing-kbd-macro (> (minibuffer-depth) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (message "Mark saved where search started"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (setq isearch-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ) ; inhibit-quit is t before here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (if (> (length isearch-string) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; Update the ring data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (if (not (setq regexp-search-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (member isearch-string regexp-search-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (setq regexp-search-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (cons isearch-string regexp-search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 regexp-search-ring-yank-pointer regexp-search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (if (> (length regexp-search-ring) regexp-search-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (if (not (setq search-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; really need equal test instead of eq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (member isearch-string search-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (setq search-ring (cons isearch-string search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 search-ring-yank-pointer search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (if (> (length search-ring) search-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (run-hooks 'isearch-mode-end-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if isearch-recursive-edit (exit-recursive-edit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;;;====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; Commands active while inside of the isearch minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (defun isearch-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 "Exit search normally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 However, if this is the first command after starting incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 search and `search-nonincremental-instead' is non-nil, do an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 incremental search via `isearch-edit-string'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (if (and search-nonincremental-instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (= 0 (length isearch-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (let ((isearch-nonincremental t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (isearch-edit-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (isearch-done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (defun isearch-edit-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 "Edit the search string in the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 The following additional command keys are active while editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 \\<minibuffer-local-isearch-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 \\[exit-minibuffer] to exit editing and resume incremental searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 \\[isearch-backward-exit-minibuffer] to resume isearching backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 \\[isearch-ring-advance-edit] to replace the search string with the next\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 item in the search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 \\[isearch-ring-retreat-edit] to replace the search string with the next\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 item in the search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 \\[isearch-complete-edit] to complete the search string from the search ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ;; Editing doesnt back up the search point. Should it?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (let ((minibuffer-local-map minibuffer-local-isearch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 isearch-nonincremental ; should search nonincrementally?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 isearch-new-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 isearch-new-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (isearch-new-forward isearch-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;; Locally bind all isearch global variables to protect them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; from recursive isearching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (isearch-string isearch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (isearch-message isearch-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (isearch-forward isearch-forward) ; set by commands below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (isearch-forward isearch-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (isearch-regexp isearch-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (isearch-word isearch-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (isearch-op-fun isearch-op-fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (isearch-cmds isearch-cmds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (isearch-success isearch-success)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (isearch-wrapped isearch-wrapped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (isearch-barrier isearch-barrier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (isearch-adjusted isearch-adjusted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (isearch-yank-flag isearch-yank-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (isearch-invalid-regexp isearch-invalid-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (isearch-other-end isearch-other-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (isearch-opoint isearch-opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (isearch-small-window isearch-small-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (isearch-recursive-edit isearch-recursive-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (isearch-window-configuration (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (isearch-selected-frame (selected-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; Actually terminate isearching until editing is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;; This is so that the user can do anything without failure,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; like switch buffers and start another isearch, and return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ;; (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (isearch-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;;#### What does this mean? There is no such condition!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; (exit nil)) ; was recursive editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (let ((prompt (isearch-message-prefix nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; If the first character the user types when we prompt them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ;; for a string is the yank-word character, then go into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;; word-search mode. Otherwise unread that character and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; read a string the normal way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (let ((cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (message "%s" prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq event (next-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (if (eq 'isearch-yank-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (lookup-key isearch-mode-map (vector event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq isearch-word t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (setq unread-command-event event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (setq isearch-new-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; (if (fboundp 'gmhist-old-read-from-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; ;; Eschew gmhist crockery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; (gmhist-old-read-from-minibuffer prompt isearch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 prompt isearch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 't ;does its own history (but shouldn't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;; ;; The search-rings aren't exactly minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 ;; ;; histories, but they are close enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 ;; (cons 'regexp-search-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; (- (length regexp-search-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; (length regexp-search-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;; (cons 'search-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ;; (- (length search-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;; (length search-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 isearch-new-message (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 'isearch-text-char-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 isearch-new-string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; Always resume isearching by restarting it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (isearch-mode isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 isearch-op-fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 isearch-recursive-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 isearch-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;; Copy new values in outer locals to isearch globals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (setq isearch-string isearch-new-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 isearch-message isearch-new-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 isearch-forward isearch-new-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;; Empty isearch-string means use default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (if (= 0 (length isearch-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (setq isearch-string (if isearch-regexp search-last-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 search-last-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 ;; Set last search string now so it is set even if we fail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (if search-last-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (setq search-last-regexp isearch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (setq search-last-string isearch-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; Reinvoke the pending search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (isearch-push-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (isearch-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (isearch-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (if isearch-nonincremental (isearch-done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (quit ; handle abort-recursive-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (isearch-abort) ;; outside of let to restore outside global values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (defun isearch-nonincremental-exit-minibuffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (setq isearch-nonincremental t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (defun isearch-forward-exit-minibuffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (setq isearch-new-forward t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (defun isearch-reverse-exit-minibuffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (setq isearch-new-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (defun isearch-abort ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 "Quit incremental search mode if searching is successful, signalling quit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 Otherwise, revert to previous successful search and continue searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 Use `isearch-exit' to quit without signalling."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; (ding) signal instead below, if quiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (discard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (if isearch-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;; If search is successful, move back to starting point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; and really do quit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (progn (goto-char isearch-opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (isearch-done) ; exit isearch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (signal 'quit '(isearch))) ; and pass on quit signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; If search is failing, rub out until it is once more successful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (while (not isearch-success) (isearch-pop-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (isearch-update)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (defun isearch-repeat (direction)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;; Utility for isearch-repeat-forward and -backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if (eq isearch-forward (eq direction 'forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; C-s in forward or C-r in reverse.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (if (equal isearch-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; If search string is empty, use last one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (setq isearch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (or (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (if regexp-search-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (car regexp-search-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (car regexp-search-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (if search-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (car search-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (car search-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (mapconcat 'isearch-text-char-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 isearch-string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; If already have what to search for, repeat it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (or isearch-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (goto-char (if isearch-forward (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (setq isearch-wrapped t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ;; C-s in reverse or C-r in forward, change direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (setq isearch-forward (not isearch-forward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (setq isearch-success t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (or (equal isearch-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;; If repeating a search that found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;; an empty string, ensure we advance.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (if (equal (match-end 0) (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (if (if isearch-forward (eobp) (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;; nowhere to advance to, so fail (and wrap next time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (setq isearch-success nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (and executing-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (not defining-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (isearch-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (ding nil 'isearch-failed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (forward-char (if isearch-forward 1 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (isearch-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (isearch-search)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (isearch-push-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (defun isearch-repeat-forward ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 "Repeat incremental search forwards."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (isearch-repeat 'forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (defun isearch-repeat-backward ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 "Repeat incremental search backwards."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (isearch-repeat 'backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (defun isearch-toggle-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 "Toggle regexp searching on or off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;; The status stack is left unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (setq isearch-regexp (not isearch-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (if isearch-regexp (setq isearch-word nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (defun isearch-toggle-case-fold ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 "Toggle case folding in searching on or off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (setq isearch-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (if isearch-case-fold-search nil 'yes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (message "%s%s [case %ssensitive]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (isearch-message-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (if isearch-case-fold-search "in" ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (setq isearch-adjusted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (defun isearch-delete-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 "Discard last input item and move point back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 If no previous match was done, just beep."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (if (null (cdr isearch-cmds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (ding nil 'isearch-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (isearch-pop-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (defun isearch-yank (chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 ;; Helper for isearch-yank-word and isearch-yank-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (let ((word (if (stringp chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 chunk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (and (not isearch-forward) isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (goto-char isearch-other-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (funcall chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;; if configured so that typing upper-case characters turns off case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;; folding, then downcase the string so that yanking an upper-case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;; word doesn't mess with case-foldedness.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (if (and search-caps-disable-folding isearch-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (setq word (downcase word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (if isearch-regexp (setq word (regexp-quote word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (setq isearch-string (concat isearch-string word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (concat isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (mapconcat 'isearch-text-char-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 word ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ;; Don't move cursor in reverse search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 isearch-yank-flag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (isearch-search-and-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (defun isearch-yank-word ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 "Pull next word from buffer into search string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (isearch-yank (function (lambda () (forward-word 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (defun isearch-yank-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 "Pull rest of line from buffer into search string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (isearch-yank 'end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (defun isearch-yank-sexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 "Pull next expression from buffer into search string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (isearch-yank 'forward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (defun isearch-yank-x-selection ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 "Pull the current X selection into the search string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (isearch-yank (x-get-selection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (defun isearch-yank-x-clipboard ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 "Pull the current X clipboard selection into the search string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (isearch-yank (x-get-clipboard)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (defun isearch-search-and-update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; Do the search and update the display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (if (and (not isearch-success)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; unsuccessful regexp search may become
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;; successful by addition of characters which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;; make isearch-string valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (not isearch-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;; In reverse search, adding stuff at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;; the end may cause zero or many more chars to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; matched, in the string following point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; Allow all those possibilities without moving point as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;; long as the match does not extend past search origin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (if (and (not isearch-forward) (not isearch-adjusted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (looking-at (if isearch-regexp isearch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (regexp-quote isearch-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (or isearch-yank-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (<= (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (min isearch-opoint isearch-barrier))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (setq isearch-success t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 isearch-invalid-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 isearch-other-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;; Not regexp, not reverse, or no match at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (if (and isearch-other-end (not isearch-adjusted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (goto-char (if isearch-forward isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (min isearch-opoint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 isearch-barrier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (1+ isearch-other-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (isearch-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (isearch-push-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (if isearch-op-fun (funcall isearch-op-fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;; *, ?, and | chars can make a regexp more liberal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;; They can make a regexp match sooner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; or make it succeed instead of failing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 ;; So go back to place last successful search started
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;; or to the last ^S/^R (barrier), whichever is nearer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (defun isearch-*-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 "Handle * and ? specially in regexps."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (setq isearch-adjusted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (let ((cs (nth (if isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 5 ; isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 2) ; saved (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (car (cdr isearch-cmds)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ;; (car isearch-cmds) is after last search;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; (car (cdr isearch-cmds)) is from before it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (setq cs (or cs isearch-barrier))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (if isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (max cs isearch-barrier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (min cs isearch-barrier))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (isearch-process-search-char last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (defun isearch-|-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 "If in regexp search, jump to the barrier."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (setq isearch-adjusted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (goto-char isearch-barrier)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (isearch-process-search-char last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun isearch-quote-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 "Quote special characters for incremental search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (isearch-process-search-char (read-quoted-char (isearch-message t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (defun isearch-return-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 "Convert return into newline for incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 Obsolete."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (isearch-process-search-char ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (defun isearch-printing-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 "Any other printing character => add it to the search string and search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (isearch-process-search-char last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (defun isearch-whitespace-chars ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 "Match all whitespace chars, if in regexp mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (if (and isearch-regexp search-whitespace-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (isearch-process-search-string search-whitespace-regexp " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (isearch-process-search-char ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ; (if isearch-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ; nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ; (setq isearch-word t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 ; (goto-char isearch-other-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 ; (isearch-process-search-char ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (defun isearch-process-search-char (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 ;; Append the char to the search string, update the message and re-search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (isearch-process-search-string (isearch-char-to-string char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (isearch-text-char-description char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (defun isearch-process-search-string (string message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (setq isearch-string (concat isearch-string string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 isearch-message (concat isearch-message message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (isearch-search-and-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ;;===========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;; Search Ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (defvar search-ring-update nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 "*Non-nil if advancing or retreating in the search ring should cause search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 Default nil means edit the string from the search ring first.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (defun isearch-ring-adjust1 (advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; Helper for isearch-ring-adjust
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (length (length ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (yank-pointer-name (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 'regexp-search-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 'search-ring-yank-pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (yank-pointer (eval yank-pointer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (if (zerop length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (set yank-pointer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (setq yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (nthcdr (% (+ (- length (length yank-pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (if advance (1- length) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 length) ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (setq isearch-string (car yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 isearch-message (mapconcat 'isearch-text-char-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 isearch-string "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (defun isearch-ring-adjust (advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; Helper for isearch-ring-advance and isearch-ring-retreat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (if (cdr isearch-cmds) ;; is there more than one thing on stack?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (isearch-pop-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (isearch-ring-adjust1 advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (isearch-push-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (if search-ring-update
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (isearch-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (isearch-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (isearch-edit-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (defun isearch-ring-advance ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 "Advance to the next search string in the ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; This could be more general to handle a prefix arg, but who would use it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (isearch-ring-adjust 'advance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (defun isearch-ring-retreat ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 "Retreat to the previous search string in the ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (isearch-ring-adjust nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (defun isearch-ring-adjust-edit (advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 "Use the next or previous search string in the ring while in minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (isearch-ring-adjust1 advance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (insert isearch-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (defun isearch-ring-advance-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (isearch-ring-adjust-edit 'advance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (defun isearch-ring-retreat-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 "Retreat to the previous search string in the ring while in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (isearch-ring-adjust-edit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (defun isearch-complete1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;; Helper for isearch-complete and isearch-complete-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;; Return t if completion OK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (alist (mapcar (function (lambda (string) (list string))) ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (completion-ignore-case case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (completion (try-completion isearch-string alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ((eq completion t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;; isearch-string stays the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ((or completion ; not nil, must be a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (= 0 (length isearch-string))) ; shouldnt have to say this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (if (equal completion isearch-string) ;; no extension?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (if completion-auto-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (with-output-to-temp-buffer "*Isearch completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (display-completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (all-completions isearch-string alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (setq isearch-string completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (temp-minibuffer-message "No completion")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (defun isearch-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 "Complete the search string from the strings on the search ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 The completed string is then editable in the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 If there is no completion possible, say so and continue searching."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (if (isearch-complete1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (isearch-edit-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 ;; else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (isearch-update)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (defun isearch-complete-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 "Same as `isearch-complete' except in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (setq isearch-string (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (if (isearch-complete1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (insert isearch-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;;;==============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ;; The search status stack (and isearch window-local variables, not used).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (defun isearch-top-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; (fetch-window-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (let ((cmd (car isearch-cmds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (setq isearch-string (car cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 isearch-message (car (cdr cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 isearch-success (nth 3 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 isearch-forward (nth 4 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 isearch-other-end (nth 5 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 isearch-invalid-regexp (nth 6 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 isearch-wrapped (nth 7 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 isearch-barrier (nth 8 cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (goto-char (car (cdr (cdr cmd))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (defun isearch-pop-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 ;; (fetch-window-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (setq isearch-cmds (cdr isearch-cmds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (isearch-top-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (defun isearch-push-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (setq isearch-cmds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (cons (list isearch-string isearch-message (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 isearch-success isearch-forward isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 isearch-invalid-regexp isearch-wrapped isearch-barrier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 isearch-cmds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;;;==================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; Message string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (defun isearch-message (&optional c-q-hack ellipsis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 ;; Generate and print the message string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (let ((cursor-in-echo-area ellipsis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (m (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (isearch-message-prefix c-q-hack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (isearch-message-suffix c-q-hack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (if c-q-hack m (message "%s" m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defun isearch-message-prefix (&optional c-q-hack nonincremental)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 ;; If about to search, and previous search regexp was invalid,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;; check that it still is. If it is valid now,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; let the message we display while searching say that it is valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (and isearch-invalid-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (progn (re-search-forward isearch-string (point) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (setq isearch-invalid-regexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 ;; #### - Yo! Emacs assembles strings all over the place, they can't all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;; be internationalized in the manner proposed below... Add an explicit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;; call to `gettext' and have the string snarfer pluck the english
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; strings out of the comment below. XEmacs is on a purespace diet! -Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (let ((m (concat (if isearch-success nil "failing ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (if isearch-wrapped "wrapped ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (if isearch-word "word ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (if isearch-regexp "regexp ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (if nonincremental "search" "I-search")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (if isearch-forward nil " backward")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ": "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (aset m 0 (upcase (aref m 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (gettext m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (defun isearch-message-suffix (&optional c-q-hack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (concat (if c-q-hack "^Q" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (if isearch-invalid-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (concat " [" isearch-invalid-regexp "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 ;;;;; #### - yuck...this is soooo lame. Is this really worth 4k of purespace???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 ;;;(let ((i (logior (if isearch-success 32 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;;; (if isearch-wrapped 16 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;;; (if isearch-word 8 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ;;; (if isearch-regexp 4 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;;; (if nonincremental 2 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ;;; (if isearch-forward 1 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ;;; (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 ;;; ((= i 63) (gettext "Wrapped word regexp search: ")) ; 111111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;;; ((= i 62) (gettext "Wrapped word regexp search backward: ")) ; 111110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;;; ((= i 61) (gettext "Wrapped word regexp I-search: ")) ; 111101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;;; ((= i 60) (gettext "Wrapped word regexp I-search backward: ")) ; 111100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 ;;; ((= i 59) (gettext "Wrapped word search: ")) ; 111011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 ;;; ((= i 58) (gettext "Wrapped word search backward: ")) ; 111010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 ;;; ((= i 57) (gettext "Wrapped word I-search: ")) ; 111001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ;;; ((= i 56) (gettext "Wrapped word I-search backward: ")) ; 111000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ;;; ((= i 55) (gettext "Wrapped regexp search: ")) ; 110111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;;; ((= i 54) (gettext "Wrapped regexp search backward: ")) ; 110110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;;; ((= i 53) (gettext "Wrapped regexp I-search: ")) ; 110101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;;; ((= i 52) (gettext "Wrapped regexp I-search backward: ")) ; 110100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 ;;; ((= i 51) (gettext "Wrapped search: ")) ; 110011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;;; ((= i 50) (gettext "Wrapped search backward: ")) ; 110010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 ;;; ((= i 49) (gettext "Wrapped I-search: ")) ; 110001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ;;; ((= i 48) (gettext "Wrapped I-search backward: ")) ; 110000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;;; ((= i 47) (gettext "Word regexp search: ")) ; 101111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ;;; ((= i 46) (gettext "Word regexp search backward: ")) ; 101110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 ;;; ((= i 45) (gettext "Word regexp I-search: ")) ; 101101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ;;; ((= i 44) (gettext "Word regexp I-search backward: ")) ; 101100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ;;; ((= i 43) (gettext "Word search: ")) ; 101011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 ;;; ((= i 42) (gettext "Word search backward: ")) ; 101010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 ;;; ((= i 41) (gettext "Word I-search: ")) ; 101001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 ;;; ((= i 40) (gettext "Word I-search backward: ")) ; 101000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ;;; ((= i 39) (gettext "Regexp search: ")) ; 100111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ;;; ((= i 38) (gettext "Regexp search backward: ")) ; 100110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 ;;; ((= i 37) (gettext "Regexp I-search: ")) ; 100101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 ;;; ((= i 36) (gettext "Regexp I-search backward: ")) ; 100100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 ;;; ((= i 35) (gettext "Search: ")) ; 100011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 ;;; ((= i 34) (gettext "Search backward: ")) ; 100010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ;;; ((= i 33) (gettext "I-search: ")) ; 100001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 ;;; ((= i 32) (gettext "I-search backward: ")) ; 100000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 ;;; ((= i 31) (gettext "Failing wrapped word regexp search: ")) ; 011111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 ;;; ((= i 30) (gettext "Failing wrapped word regexp search backward: ")) ; 011110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ;;; ((= i 29) (gettext "Failing wrapped word regexp I-search: ")) ; 011101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ;;; ((= i 28) (gettext "Failing wrapped word regexp I-search backward: ")) ; 011100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ;;; ((= i 27) (gettext "Failing wrapped word search: ")) ; 011011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 ;;; ((= i 26) (gettext "Failing wrapped word search backward: ")) ; 011010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ;;; ((= i 25) (gettext "Failing wrapped word I-search: ")) ; 011001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;;; ((= i 24) (gettext "Failing wrapped word I-search backward: ")) ; 011000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;;; ((= i 23) (gettext "Failing wrapped regexp search: ")) ; 010111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ;;; ((= i 22) (gettext "Failing wrapped regexp search backward: ")) ; 010110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;;; ((= i 21) (gettext "Failing wrapped regexp I-search: ")) ; 010101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 ;;; ((= i 20) (gettext "Failing wrapped regexp I-search backward: ")) ; 010100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 ;;; ((= i 19) (gettext "Failing wrapped search: ")) ; 010011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;;; ((= i 18) (gettext "Failing wrapped search backward: ")) ; 010010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 ;;; ((= i 17) (gettext "Failing wrapped I-search: ")) ; 010001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 ;;; ((= i 16) (gettext "Failing wrapped I-search backward: ")) ; 010000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 ;;; ((= i 15) (gettext "Failing word regexp search: ")) ; 001111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 ;;; ((= i 14) (gettext "Failing word regexp search backward: ")) ; 001110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 ;;; ((= i 13) (gettext "Failing word regexp I-search: ")) ; 001101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ;;; ((= i 12) (gettext "Failing word regexp I-search backward: ")) ; 001100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 ;;; ((= i 11) (gettext "Failing word search: ")) ; 001011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;;; ((= i 10) (gettext "Failing word search backward: ")) ; 001010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ;;; ((= i 9) (gettext "Failing word I-search: ")) ; 001001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 ;;; ((= i 8) (gettext "Failing word I-search backward: ")) ; 001000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 ;;; ((= i 7) (gettext "Failing regexp search: ")) ; 000111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 ;;; ((= i 6) (gettext "Failing regexp search backward: ")) ; 000110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 ;;; ((= i 5) (gettext "Failing regexp I-search: ")) ; 000101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 ;;; ((= i 4) (gettext "Failing regexp I-search backward: ")) ; 000100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ;;; ((= i 3) (gettext "Failing search: ")) ; 000011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ;;; ((= i 2) (gettext "Failing search backward: ")) ; 000010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ;;; ((= i 1) (gettext "Failing I-search: ")) ; 000001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ;;; ((= i 0) (gettext "Failing I-search backward: ")) ; 000000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 ;;; (t (error "Something's rotten")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 ;;;========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ;;; Exiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (put 'isearch-printing-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (put 'isearch-return-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (put 'isearch-repeat-forward 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (put 'isearch-repeat-backward 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (put 'isearch-delete-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (put 'isearch-abort 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (put 'isearch-quote-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (put 'isearch-exit 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (put 'isearch-printing-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (put 'isearch-printing-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (put 'isearch-yank-word 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (put 'isearch-yank-line 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (put 'isearch-yank-sexp 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (put 'isearch-*-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (put 'isearch-*-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (put 'isearch-|-char 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (put 'isearch-toggle-regexp 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (put 'isearch-toggle-case-fold 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (put 'isearch-edit-string 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (put 'isearch-mode-help 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (put 'isearch-ring-advance 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (put 'isearch-ring-retreat 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (put 'isearch-ring-advance-edit 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (put 'isearch-ring-retreat-edit 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (put 'isearch-whitespace-chars 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (put 'isearch-complete 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (put 'isearch-complete-edit 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (put 'isearch-edit-string 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (put 'isearch-toggle-regexp 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (put 'isearch-forward-exit-minibuffer 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (put 'isearch-reverse-exit-minibuffer 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (put 'isearch-nonincremental-exit-minibuffer 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (put 'isearch-yank-x-selection 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (put 'isearch-yank-x-clipboard 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; scrolling the scrollbar should not terminate isearch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 ;; vertical scrollbar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (put 'scrollbar-line-up 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (put 'scrollbar-line-down 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (put 'scrollbar-page-up 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (put 'scrollbar-page-down 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (put 'scrollbar-to-top 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (put 'scrollbar-to-bottom 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (put 'scrollbar-vertical-drag 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 ;; horizontal scrollbar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (put 'scrollbar-char-left 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (put 'scrollbar-char-right 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (put 'scrollbar-page-left 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (put 'scrollbar-page-right 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (put 'scrollbar-to-left 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (put 'scrollbar-to-right 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (put 'scrollbar-horizontal-drag 'isearch-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (defun isearch-pre-command-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ;; For use as the value of `pre-command-hook' when isearch-mode is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 ;; If the command about to be executed is not one of the isearch commands,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 ;; then isearch-mode is turned off before that command is executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 ;; If the command about to be executed is self-insert-command, or is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 ;; keyboard macro of a single key sequence which is bound to self-insert-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 ;; command, then we add those chars to the search ring instead of inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; them in the buffer. In this way, the set of self-searching characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ;; need not be exhaustively enumerated, but is derived from other maps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (cond ((not (eq (current-buffer) isearch-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 ;; If the buffer (likely meaning "frame") has changed, bail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ;; This can also happen if a proc filter has popped up another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 ;; buffer, which is arguably a bad thing for it to have done,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ;; but the way in which isearch would have hosed you in that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 ;; case is unarguably even worse. -jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (isearch-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (isearch-maybe-frob-keyboard-macros)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (if (and this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (symbolp this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (get this-command 'isearch-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 nil ; then continue.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (isearch-done)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (defun isearch-maybe-frob-keyboard-macros ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 ;; If the command about to be executed is `self-insert-command' then change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 ;; the command to `isearch-printing-char' instead, meaning add the last-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; typed character to the search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 ;; If `this-command' is a string or a vector (that is, a keyboard macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 ;; and it contains only one command, which is bound to self-insert-command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ;; then do the same thing as for self-inserting commands: arrange for that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;; character to be added to the search string. If we didn't do this, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 ;; typing a compose sequence (a la x-compose.el) would terminate the search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 ;; and insert the character, instead of searching for that character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 ;; We should continue doing this, since it's pretty much the behavior one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 ;; would expect, but it will stop being so necessary once key-translation-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ;; map exists and is used by x-compose.el and things like it, since the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 ;; translation will have been done before we see the keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (cond ((eq this-command 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (setq this-command 'isearch-printing-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ((and (or (stringp this-command) (vectorp this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (eq (key-binding this-command) 'self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (setq last-command-event (character-to-event (aref this-command 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 last-command-char (and (stringp this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (aref this-command 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 this-command 'isearch-printing-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ;;;========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 ;;; Highlighting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (defvar isearch-highlight t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 "*Whether isearch and query-replace should highlight the text which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 currently matches the search-string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (defvar isearch-extent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; this face is initialized by x-faces.el since isearch is preloaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 ;; this face is now created in initialize-faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 ;;(make-face 'isearch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (defun isearch-make-extent (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (let ((x (make-extent begin end (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 ;; make the isearch extent always take prescedence over any mouse-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ;; highlighted extents we may be passing through, since isearch, being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ;; modal, is more interesting (there's nothing they could do with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 ;; mouse-highlighted extent while in the midst of a search anyway).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (set-extent-priority x (1+ mouse-highlight-priority))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (set-extent-face x 'isearch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (setq isearch-extent x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (defun isearch-highlight (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (if (null isearch-highlight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 ;; make sure isearch-extent is in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (cond ((not (extentp isearch-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (isearch-make-extent begin end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 ((not (eq (extent-object isearch-extent) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (delete-extent isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (isearch-make-extent begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (set-extent-endpoints isearch-extent begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (defun isearch-dehighlight (totally)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (if (and isearch-highlight isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (if totally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (if (extentp isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (delete-extent isearch-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (setq isearch-extent nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (if (extentp isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (detach-extent isearch-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (setq isearch-extent nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ;;;========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 ;;; Searching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (defun isearch-search ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 ;; Do the search with the current search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (isearch-message nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (if (and isearch-case-fold-search search-caps-disable-folding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (setq isearch-case-fold-search (isearch-no-upper-case-p isearch-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (setq isearch-mode (if case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (if isearch-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 " Isearch" ;As God Intended Mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 " ISeARch") ;Warn about evil case via StuDLYcAps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 "Isearch"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ; (if isearch-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 ; " isearch" ;Presumably case-sensitive losers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 ; ;will notice this 1-char difference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 ; " Isearch") ;Weenie mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (condition-case lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (let ((inhibit-quit nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (case-fold-search isearch-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (if isearch-regexp (setq isearch-invalid-regexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (setq isearch-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (cond (isearch-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (if isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 'word-search-forward 'word-search-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (if isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 're-search-forward 're-search-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (if isearch-forward 'search-forward 'search-backward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 isearch-string nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (if isearch-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (setq isearch-other-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (if isearch-forward (match-beginning 0) (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (quit (setq unread-command-event (character-to-event (quit-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (setq isearch-success nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (invalid-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (setq isearch-invalid-regexp (car (cdr lossage)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 isearch-invalid-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (setq isearch-invalid-regexp (gettext "incomplete input")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (if isearch-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 ;; If we're being run inside a keyboard macro, then the call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ;; ding will signal an error (to terminate the macro). We must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 ;; turn off isearch-mode first, so that we aren't still in isearch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 ;; mode after the macro exits. Note that isearch-recursive-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 ;; must not be true if a keyboard macro is executing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (if (and executing-kbd-macro (not defining-kbd-macro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (isearch-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (ding nil 'isearch-failed)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 ;; Ding if failed this time after succeeding last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (and (nth 3 (car isearch-cmds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (ding nil 'isearch-failed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (goto-char (nth 2 (car isearch-cmds)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 ;;;=================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 ;; This is called from incremental-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 ;; if the first input character is the exit character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 ;; We store the search string in `isearch-string'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 ;; which has been bound already by `isearch-search'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 ;; so that, when we exit, it is copied into `search-last-string'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 ;(defun nonincremental-search (forward regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ; ;; This may be broken. Anyway, it is replaced by the isearch-edit-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 ; ;; Missing features: word search option, command history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ; (setq isearch-forward forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 ; isearch-regexp regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ; (let (char function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ; inhibit-quit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 ; (cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 ; ;; Prompt assuming not word search,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 ; (setq isearch-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 ; (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 ; (if isearch-forward "Regexp search: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 ; "Regexp search backward: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 ; (if isearch-forward "Search: " "Search backward: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 ; (message "%s" isearch-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ; ;; Read 1 char and switch to word search if it is ^W.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 ; (setq char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 ; (if (eq char search-yank-word-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 ; (setq isearch-message (if isearch-forward "Word search: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 ; "Word search backward: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 ; ;; Otherwise let that 1 char be part of the search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ; (setq unread-command-event (character-to-event char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ; (setq function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 ; (if (eq char search-yank-word-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 ; (if isearch-forward 'word-search-forward 'word-search-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 ; (if isearch-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 ; (if isearch-forward 're-search-forward 're-search-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 ; (if isearch-forward 'search-forward 'search-backward))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 ; ;; Read the search string with corrected prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 ; (setq isearch-string (read-string isearch-message isearch-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 ; ;; Empty means use default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 ; (if (= 0 (length isearch-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 ; (setq isearch-string search-last-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 ; ;; Set last search string now so it is set even if we fail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 ; (setq search-last-string isearch-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 ; ;; Since we used the minibuffer, we should be available for redo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 ; (setq command-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ; (cons (list function isearch-string) command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ; ;; Go ahead and search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 ; (if search-caps-disable-folding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ; (setq isearch-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 ; (isearch-no-upper-case-p isearch-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 ; (let ((case-fold-search isearch-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 ; (funcall function isearch-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (defun isearch-no-upper-case-p (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 "Return t if there are no upper case chars in string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 But upper case chars preceeded by \\ do not count since they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 have special meaning in a regexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 ;; this incorrectly returns t for "\\\\A"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string))))