annotate lisp/isearch-mode.el @ 5583:10f179710250

Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq. src/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * fns.c (remassoc_no_quit): * fns.c (remrassq_no_quit): * fns.c (syms_of_fns): * fontcolor-tty.c (Fregister_tty_color): * fontcolor-tty.c (Funregister_tty_color): * fontcolor-tty.c (Ffind_tty_color): * lisp.h: Remove Fremassq, Fremrassq, Fremassoc, Fremrassoc, they're XEmacs-specific functions and Lisp callers should use (delete* ... :key #'car) anyway. Keep the non-Lisp-visible _no_quit versions, calling FdeleteX from C with the appropriate arguments is ungainly. lisp/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * obsolete.el: * obsolete.el (assq-delete-all): * packages.el (package-provide): * packages.el (package-suppress): * mule/cyrillic.el ("Cyrillic-KOI8"): * mule/cyrillic.el (koi8-u): * mule/general-late.el (posix-charset-to-coding-system-hash): * mule/latin.el: * mule/latin.el (for): * cl-extra.el: * cl-extra.el (cl-extra): * loadup.el (load-history): Change any uses of #'remassq, #'remassoc and friends to calling #'delete* with an appropriate key argument. Provide compatibility implementations, mark them obsolete. man/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * lispref/lists.texi (Association Lists): Don't document #'remassoc, #'remassq and friends in detail; they're XEmacs-specific and (delete* ... :key #'car) is preferable.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 09 Oct 2011 12:55:51 +0100
parents ac37a5f7e5be
children b7ae5f44b950
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; isearch-mode.el --- Incremental search minor mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992,93,94,95,96,97,98,1999 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
12 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
13 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
14 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
19 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4063
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 20.4.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; Instructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; Searching with isearch-mode.el should work just like isearch.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; [the one from Emacs 18], except it is done in a temporary minor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; mode that terminates when you finish searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; isearch-mode behaves modally and does not return until the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; is completed. It uses a recursive-edit to behave this way. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; that case, you should still be able switch buffers, so be careful
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; not to get things confused.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; The key bindings active within isearch-mode are defined below in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; `isearch-mode-map' which is given bindings close to the default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; characters of the original isearch.el. With `isearch-mode',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; however, you can bind multi-character keys and it should be easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; to add new commands. One bug though: keys with meta-prefix cannot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;; be longer than two chars. Also see minibuffer-local-isearch-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; for bindings active during `isearch-edit-string'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;; The search ring and completion commands automatically put you in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;; the minibuffer to edit the string. This gives you a chance to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;; modify the search string before executing the search. There are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; three commands to terminate the editing: C-s and C-r exit the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;; minibuffer and search forward and reverse respectively, while C-m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;; exits and does a nonincremental search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;; Exiting immediately from isearch uses isearch-edit-string instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;; The name of this option should probably be changed if we decide to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;; keep the behavior. No point in forcing nonincremental search until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;; the last possible moment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;; TODO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;; - Integrate generalized command history to isearch-edit-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;; - Think about incorporating query-replace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;; - Hooks and options for failed search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;;; Change Log:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;; Changes before those recorded in ChangeLog:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;; 20-aug-92 Hacked by jwz for Lucid Emacs 19.3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ;; Revision 1.3 92/06/29 13:10:08 liberte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;; Moved modal isearch-mode handling into isearch-mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;; Got rid of buffer-local isearch variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ;; isearch-edit-string used by ring adjustments, completion, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ;; nonincremental searching. C-s and C-r are additional exit commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 ;; Renamed all regex to regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;; Got rid of found-start and found-point globals.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;; Generalized handling of upper-case chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;; Revision 1.2 92/05/27 11:33:57 liberte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ;; Emacs version 19 has a search ring, which is supported here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;; Other fixes found in the version 19 isearch are included here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;; Also see variables search-caps-disable-folding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;; search-nonincremental-instead, search-whitespace-regexp, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;; commands isearch-toggle-regexp, isearch-edit-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;; semi-modal isearching is supported.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;; Changes for 1.1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;; 3/18/92 Fixed invalid-regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;; 3/18/92 Fixed yanking in regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;;;=========================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;;; User-accessible variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (defgroup isearch nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 "Incremental search minor mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 :prefix "search-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 :group 'matching)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (defcustom search-exit-option t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 "*Non-nil means random control characters terminate incremental search."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 (defcustom search-slow-window-lines 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 "*Number of lines in slow search display windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 These are the short windows used during incremental search on slow terminals.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 Negative means put the slow search window at the top (normally it's at bottom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 and the value is minus the number of lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 (defcustom search-slow-speed 1200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 "*Highest terminal speed at which to use \"slow\" style incremental search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 This is the style where a one-line window is created to show the line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 that the search has reached."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ;; We have `search-caps-disable-folding'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ;(defcustom search-upper-case 'not-yanks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ; "*If non-nil, upper case chars disable case fold searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;That is, upper and lower case chars must match exactly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;This applies no matter where the chars come from, but does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;apply to chars in regexps that are prefixed with `\\'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ;If this value is `not-yanks', yanked text is always downcased."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ; :type '(choice (const :tag "off" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ; (const not-yanks)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 ; (other :tag "on" t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ; :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (defcustom search-nonincremental-instead t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 "*If non-nil, do a nonincremental search instead if exiting immediately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 Actually, `isearch-edit-string' is called to let you enter the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 string, and RET terminates editing and does a nonincremental search."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ;; FSF default is "\\s-+", but I think our default is better so I'm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ;; leaving it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (defcustom search-whitespace-regexp "\\(\\s-\\|[\n\r]\\)+"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 "*If non-nil, regular expression to match a sequence of whitespace chars."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (defcustom search-highlight t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 "*Whether incremental search and query-replace should highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 the text that currently matches the search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 ;; I think the name `search-highlight' makes more sense, both because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;; of consistency with other search-* variables above, and because it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; also applies to query-replace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (define-obsolete-variable-alias 'isearch-highlight 'search-highlight)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (defcustom search-invisible 'open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 "If t incremental search can match hidden text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 nil means don't match invisible text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 If the value is `open', if the text matched is made invisible by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 an overlay having an `invisible' property and that overlay has a property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 `isearch-open-invisible', then incremental search will show the contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 \(This applies when using `outline.el' and `hideshow.el'.)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 :type '(choice (const :tag "Match hidden text" t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (const :tag "Open overlays" open)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (const :tag "Don't match hidden text" nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (defcustom isearch-hide-immediately t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 "If non-nil, re-hide an invisible match right away.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 This variable makes a difference when `search-invisible' is set to `open'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 It means that after search makes some invisible text visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 to show the match, it makes the text invisible again when the match moves.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
181 Ordinarily the text becomes invisible again at the end of the search."
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
182 :type 'boolean
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (defvar isearch-mode-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 "Function(s) to call after starting up an incremental search.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (defvar isearch-mode-end-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 "Function(s) to call after terminating an incremental search.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ;;;==================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;;; Search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (defvar search-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 "List of search string sequences.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (defvar regexp-search-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 "List of regular expression search string sequences.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (defcustom search-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 "*Maximum length of search ring before oldest elements are thrown away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (defcustom regexp-search-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 "*Maximum length of regexp search ring before oldest elements are thrown away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;; The important difference between pre-20.4-merge yank-pointers and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 ;; current code is that the yank pointers positions used to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 ;; preserved across the isearch sessions. I changed this because I
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 ;; think the FSF code is closer to how the feature is supposed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 ;; behave (read: to minibuffer histories.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (defvar search-ring-yank-pointer nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 "Index in `search-ring' of last string reused.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 nil if none yet.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (defvar regexp-search-ring-yank-pointer nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 "Index in `regexp-search-ring' of last string reused.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 nil if none yet.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (defcustom search-ring-update nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 "*Non-nil if advancing or retreating in the search ring should cause search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 Default nil means edit the string from the search ring first."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
710
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
226 (defcustom isearch-mode-line-string " Isearch"
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
227 "*String to display in the modeline when `isearch-mode' is active.
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
228 Set this to nil if you don't want a modeline indicator."
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
229 :type '(choice string
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
230 (const :tag "none" nil))
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
231 :group 'isearch)
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
232
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;;;====================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ;;; Define isearch-mode keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (defvar isearch-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (let ((map (make-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (set-keymap-name map 'isearch-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
5371
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
240 ;; Bind ASCII printing characters to `isearch-printing-char'. This
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
241 ;; isn't normally necessary, but if a printing character were bound to
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
242 ;; something other than self-insert-command in global-map, then it would
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
243 ;; terminate the search and be executed without this.
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
244
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
245 ;; This is also relevant when other modes (notably dired and gnus) call
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
246 ;; `suppress-keymap' on their major mode maps; this means that
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
247 ;; `isearch-maybe-frob-keyboard-macros' won't pick up that the command
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
248 ;; that would normally be executed is `self-insert-command' and do its
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
249 ;; thing of transforming that to `isearch-printing-char'. This is less
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
250 ;; of an issue for the non-ASCII characters, because they rarely have
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
251 ;; specific bindings in major modes.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (let ((i 32)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (str (make-string 1 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (while (< i 127)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (aset str 0 i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (define-key map str 'isearch-printing-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (setq i (1+ i))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 ;; Here FSF sets up various kludges to handle local bindings with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 ;; meta char prefix keys. We don't need isearch-other-meta-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 ;; because we handle things differently (via pre-command-hook).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ;; Several non-printing chars change the searching behavior.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (define-key map "\C-s" 'isearch-repeat-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (define-key map "\M-\C-s" 'isearch-repeat-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (define-key map "\C-r" 'isearch-repeat-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (define-key map "\C-g" 'isearch-abort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 710
diff changeset
270 (define-key map [(meta escape)] 'isearch-cancel)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (define-key map "\C-q" 'isearch-quote-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (define-key map "\C-m" 'isearch-exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (define-key map "\C-j" 'isearch-printing-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (define-key map "\t" 'isearch-printing-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 ;; I prefer our default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 ;(define-key map " " 'isearch-whitespace-chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (define-key map "\M- " 'isearch-whitespace-chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (define-key map "\C-w" 'isearch-yank-word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (define-key map "\C-y" 'isearch-yank-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (define-key map "\M-y" 'isearch-yank-kill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 ;; Define keys for regexp chars * ? |.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 ;; Nothing special for + because it matches at least once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (define-key map "*" 'isearch-*-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (define-key map "?" 'isearch-*-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (define-key map "|" 'isearch-|-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; delete and backspace delete backward, f1 is help, and C-h can be either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (define-key map 'delete 'isearch-delete-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (define-key map 'backspace 'isearch-delete-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (define-key map '(control h) 'isearch-help-or-delete-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (define-key map 'f1 'isearch-mode-help)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (define-key map 'help 'isearch-mode-help)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (define-key map "\M-n" 'isearch-ring-advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (define-key map "\M-p" 'isearch-ring-retreat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (define-key map "\M-\t" 'isearch-complete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 ;; I find this binding somewhat unintuitive, because it doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 ;; work if the mouse pointer is over the echo area -- it has to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ;; over the search window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (define-key map 'button2 'isearch-yank-selection)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 "Keymap for isearch-mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ;; Some bindings you may want to put in your isearch-mode-hook.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 ;; Suggest some alternates...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-case-fold)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 ;; (define-key isearch-mode-map "\C-^" 'isearch-edit-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (defvar minibuffer-local-isearch-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (let ((map (make-sparse-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 ;; #### - this should also be minor-mode-ified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (set-keymap-parents map (list minibuffer-local-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (set-keymap-name map 'minibuffer-local-isearch-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;;#### This should just arrange to use the usual Emacs minibuffer histories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (define-key map "\M-n" 'isearch-ring-advance-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (define-key map "\M-p" 'isearch-ring-retreat-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (define-key map 'down 'isearch-ring-advance-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (define-key map 'up 'isearch-ring-retreat-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (define-key map "\M-\t" 'isearch-complete-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 "Keymap for editing isearch strings in the minibuffer.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 ;;;========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 ;; Internal variables declared globally for byte-compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 ;; These are all set with setq while isearching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 ;; and bound locally while editing the search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (defvar isearch-forward nil) ; Searching in the forward direction.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (defvar isearch-regexp nil) ; Searching for a regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (defvar isearch-word nil) ; Searching for words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (defvar isearch-cmds nil) ; Stack of search status sets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (defvar isearch-string "") ; The current search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (defvar isearch-message "") ; text-char-description version of isearch-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (defvar isearch-success t) ; Searching is currently successful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (defvar isearch-invalid-regexp nil) ; Regexp not well formed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (defvar isearch-within-brackets nil) ; Regexp has unclosed [.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (defvar isearch-barrier 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (defvar isearch-just-started nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (defvar isearch-buffer nil) ; the buffer we've frobbed the keymap of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (defvar isearch-case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ;; Need this for toggling case in isearch-toggle-case-fold. When this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ;; is non-nil, the case-sensitiveness of the search is set by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 ;; user, and is may no longer be dynamically changed as per
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 ;; search-caps-disable-folding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (defvar isearch-fixed-case nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (defvar isearch-adjusted nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (defvar isearch-slow-terminal-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 ;;; If t, using a small window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (defvar isearch-small-window nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (defvar isearch-opoint 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ;;; The window configuration active at the beginning of the search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (defvar isearch-window-configuration nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (defvar isearch-selected-frame nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 ;; Flag to indicate a yank occurred, so don't move the cursor.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (defvar isearch-yank-flag nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 ;;; A function to be called after each input character is processed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 ;;; (It is not called after characters that exit the search.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 ;;; It is only set from an optional argument to `isearch-mode'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (defvar isearch-op-fun nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 ;;; Is isearch-mode in a recursive edit for modal searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (defvar isearch-recursive-edit nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 ;;; Should isearch be terminated after doing one search?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (defvar isearch-nonincremental nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 ;; New value of isearch-forward after isearch-edit-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (defvar isearch-new-forward nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 ;; Accumulate here the extents unhidden during searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (defvar isearch-unhidden-extents nil) ; in FSF: isearch-opened-overlays
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 ;;;==============================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 ;; Minor-mode-alist changes - kind of redundant with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ;; echo area, but if isearching in multiple windows, it can be useful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
710
a00780ef853d [xemacs-hg @ 2001-12-22 07:20:57 by youngs]
youngs
parents: 502
diff changeset
398 (add-minor-mode 'isearch-mode 'isearch-mode-line-string)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (defvar isearch-mode nil) ;; Name of the minor mode, if non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (make-variable-buffer-local 'isearch-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 ;; We bind these in keydefs.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;(define-key global-map "\C-s" 'isearch-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 ;(define-key global-map "\C-r" 'isearch-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 ;(define-key global-map "\M-\C-s" 'isearch-forward-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 ;(define-key global-map "\M-\C-r" 'isearch-backward-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 ;;;===============================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 ;;; Entry points to isearch-mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 ;;; These four functions should replace those in loaddefs.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 ;;; and look at this-command to set the options accordingly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (defun isearch-forward (&optional regexp-p no-recursive-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 Do incremental search forward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 With a prefix argument, do an incremental regular expression search instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 \\<isearch-mode-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 As you type characters, they add to the search string and are found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 The following non-printing keys are bound in `isearch-mode-map'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 Type \\[isearch-delete-char] to cancel characters from end of search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 Type \\[isearch-exit] to exit, leaving point at location found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 Type LFD (C-j) to match end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 Type \\[isearch-repeat-forward] to search again forward,\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 \\[isearch-repeat-backward] to search again backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 Type \\[isearch-yank-word] to yank word from buffer onto end of search\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 string and search for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 and search for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 and search for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 Type \\[isearch-quote-char] to quote control character to search for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 Type \\[isearch-whitespace-chars] to match all whitespace chars in regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 \\[isearch-abort] while searching or when search has failed cancels input\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 back to what has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 been found successfully.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 \\[isearch-abort] when search is successful aborts and moves point to\
2068
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
440 starting point,
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
441 leaving the search string at the head of the search ring. Note that this
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
442 behavior differs from GNU Emacs, which forgets the current search string
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
443 on abort regardless of success or failure.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 Also supported is a search ring of the previous 16 search strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 Type \\[isearch-ring-advance] to search for the next item in the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 Type \\[isearch-ring-retreat] to search for the previous item in the search\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 Type \\[isearch-complete] to complete the search string using the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 The above keys are bound in the isearch-mode-map. To change the keys which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 are special to isearch-mode, simply change the bindings in that map.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 Other control and meta characters terminate the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 and are then executed normally (depending on `search-exit-option').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 If this function is called non-interactively, it does not return to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 the calling function until the search is done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 The bindings, more precisely:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 \\{isearch-mode-map}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 ;; Non-standard bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ;; Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 ;; Type \\[isearch-edit-string] to edit the search string in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 ;; Terminate editing and return to incremental searching with CR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (interactive "_P\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 Do incremental search forward for regular expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 With a prefix argument, do a regular string search instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 Like ordinary incremental search except that your input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 is treated as a regexp. See \\[isearch-forward] for more info."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (interactive "_P\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (defun isearch-backward (&optional regexp-p no-recursive-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 Do incremental search backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 With a prefix argument, do a regular expression search instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 See \\[isearch-forward] for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (interactive "_P\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 Do incremental search backward for regular expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 With a prefix argument, do a regular string search instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 Like ordinary incremental search except that your input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 is treated as a regexp. See \\[isearch-forward] for more info."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (interactive "_P\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 ;; The problem here is that you can't scroll the help screen; as soon
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 ;; as you press a key, it's gone. I don't know of a good way to fix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 ;; it, though. -hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (defun isearch-mode-help ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (interactive "_")
1601
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
502 (let ((config (current-window-configuration)))
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
503 (let ((w (selected-window)))
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
504 (describe-function 'isearch-forward)
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
505 (select-window w))
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
506 (isearch-update)
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
507 (setq isearch-window-configuration config)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 ;;;==================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 ;; isearch-mode only sets up incremental search for the minor mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 ;; All the work is done by the isearch-mode commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 "Start isearch minor mode. Called by `isearch-forward', etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 \\{isearch-mode-map}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (if executing-kbd-macro (setq recursive-edit nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (let ((inhibit-quit t)) ; don't leave things in an inconsistent state...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 ;; Initialize global vars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (setq isearch-buffer (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 isearch-forward forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 isearch-regexp regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 isearch-word word-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 isearch-op-fun op-fun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 isearch-case-fold-search case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 isearch-fixed-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 isearch-string ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 isearch-message ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 isearch-cmds nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 isearch-success t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 isearch-wrapped nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 isearch-barrier (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 isearch-adjusted nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 isearch-yank-flag nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 isearch-invalid-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 isearch-within-brackets nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 isearch-slow-terminal-mode (and (<= (device-baud-rate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 search-slow-speed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (> (window-height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (* 4 search-slow-window-lines)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 isearch-other-end nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 isearch-small-window nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 isearch-just-started t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 isearch-opoint (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 search-ring-yank-pointer nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 regexp-search-ring-yank-pointer nil
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
552 isearch-unhidden-extents nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 ;; #### What we really need is a buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 ;; overriding-local-map. See isearch-pre-command-hook for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 ;; more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 overriding-local-map (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (set-keymap-parents isearch-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (nconc (current-minor-mode-maps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (and (current-local-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (list (current-local-map)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 isearch-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 isearch-selected-frame (selected-frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 ;; XEmacs change: without clearing the match data, sometimes old values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 ;; of isearch-other-end get used. Don't ask me why...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (store-match-data nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (add-hook 'pre-command-hook 'isearch-pre-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (setq isearch-mode (gettext " Isearch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (redraw-modeline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (isearch-push-state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 ) ; inhibit-quit is t before here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (isearch-update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (run-hooks 'isearch-mode-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 ;; isearch-mode can be made modal (in the sense of not returning to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 ;; the calling function until searching is completed) by entering
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ;; a recursive-edit and exiting it when done isearching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (if recursive-edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (let ((isearch-recursive-edit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 isearch-success)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ;;;====================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 ;; Some high level utilities. Others below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (defun isearch-update ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 ;; Called after each command to update the display.
1601
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
597 (if isearch-window-configuration
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
598 (progn
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
599 (set-window-configuration isearch-window-configuration)
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
600 (setq isearch-window-configuration nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (if (null unread-command-events)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (if (not (input-pending-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (isearch-message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (if (and isearch-slow-terminal-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (not (or isearch-small-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (pos-visible-in-window-p))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (let ((found-point (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (setq isearch-small-window t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (move-to-window-line 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (let ((window-min-height 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (split-window nil (if (< search-slow-window-lines 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (1+ (- search-slow-window-lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (- (window-height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (1+ search-slow-window-lines)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (if (< search-slow-window-lines 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (progn (vertical-motion (- 1 search-slow-window-lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (set-window-start (next-window) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (set-window-hscroll (next-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (window-hscroll))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 (set-window-hscroll (selected-window) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 (other-window 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (goto-char found-point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 (if isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (if (< isearch-other-end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (isearch-highlight isearch-other-end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (isearch-highlight (point) isearch-other-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (isearch-dehighlight))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (setq ;; quit-flag nil not for isearch-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 isearch-adjusted nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 isearch-yank-flag nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (isearch-highlight-all-update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (defun isearch-done (&optional nopush edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 ;; Called by all commands that terminate isearch-mode.
1601
442db3c3c43b [xemacs-hg @ 2003-08-02 08:42:10 by michaels]
michaels
parents: 776
diff changeset
639 (setq isearch-window-configuration nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (let ((inhibit-quit t)) ; danger danger!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (if (and isearch-buffer (buffer-live-p isearch-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 ;; Some loser process filter might have switched the window's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ;; buffer, so be sure to set these variables back in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 ;; buffer we frobbed them in. But only if the buffer is still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 ;; alive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (with-current-buffer isearch-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (setq overriding-local-map nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 ;; Use remove-hook instead of just setting it to our saved value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;; in case some process filter has created a buffer and modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 ;; the pre-command-hook in that buffer... yeah, this is obscure,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 ;; and yeah, I was getting screwed by it. -jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (set-keymap-parents isearch-mode-map nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (setq isearch-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (redraw-modeline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (isearch-dehighlight)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (isearch-highlight-all-cleanup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (isearch-restore-invisible-extents nil nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 ;; it's not critical that this be inside inhibit-quit, but leaving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 ;; things in small-window-mode would be bad.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (let ((found-start (window-start (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 (found-point (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (cond ((eq (selected-frame) isearch-selected-frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (if isearch-small-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 (goto-char found-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 ;; Exiting the save-window-excursion clobbers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 ;; window-start; restore it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 (set-window-start (selected-window) found-start t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 ;; If there was movement, mark the starting position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 ;; Maybe should test difference between and set mark iff > threshold.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 (if (and (buffer-live-p isearch-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (/= (point isearch-buffer) isearch-opoint))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 ;; #### FSF doesn't do this if the region is active. Should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 ;; we do the same?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (push-mark isearch-opoint t nil isearch-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (or executing-kbd-macro (> (minibuffer-depth) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (display-message 'command "Mark saved where search started")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (setq isearch-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 ) ; inhibit-quit is t before here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 (if (and (> (length isearch-string) 0) (not nopush))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 ;; Update the ring data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 (isearch-update-ring isearch-string isearch-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (run-hooks 'isearch-mode-end-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (and (not edit) isearch-recursive-edit (exit-recursive-edit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (defun isearch-update-ring (string &optional regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 "Add STRING to the beginning of the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 REGEXP says which ring to use."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
695 (if regexp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (if (or (null regexp-search-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (not (string= string (car regexp-search-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (setq regexp-search-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (cons string regexp-search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (if (> (length regexp-search-ring) regexp-search-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 (if (or (null search-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 (not (string= string (car search-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (setq search-ring (cons string search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (if (> (length search-ring) search-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 ;;;====================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 ;; Commands active while inside of the isearch minor mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (defun isearch-exit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 "Exit search normally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 However, if this is the first command after starting incremental
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 search and `search-nonincremental-instead' is non-nil, do a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 nonincremental search instead via `isearch-edit-string'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (interactive)
4063
da6da82d7d79 [xemacs-hg @ 2007-07-16 13:34:27 by aidan]
aidan
parents: 2828
diff changeset
721 (if (and (or search-nonincremental-instead executing-kbd-macro)
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 4063
diff changeset
722 (eql 0 (length isearch-string)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 (let ((isearch-nonincremental t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 ;; Highlighting only gets in the way of nonincremental
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 ;; search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 (search-highlight nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (isearch-highlight-all-matches nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 (isearch-edit-string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 (isearch-done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (defun isearch-edit-string ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 "Edit the search string in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 The following additional command keys are active while editing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 \\<minibuffer-local-isearch-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 \\[exit-minibuffer] to resume incremental searching with the edited string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 \\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 \\[isearch-forward-exit-minibuffer] to resume isearching forward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 \\[isearch-complete-edit] to complete the search string using the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 \\<isearch-mode-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 If first char entered is \\[isearch-yank-word], then do word search instead."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 ;; This code is very hairy for several reasons, explained in the code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 ;; If there were a way to catch any change of buffer from the minibuffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 ;; this could be simplified greatly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 ;; Editing doesn't back up the search point. Should it?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (let ((isearch-nonincremental isearch-nonincremental)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 ;; Locally bind all isearch global variables to protect them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 ;; from recursive isearching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 ;; isearch-string -message and -forward are not bound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;; so they may be changed. Instead, save the values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (isearch-new-string isearch-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (isearch-new-message isearch-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (isearch-new-forward isearch-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 (isearch-new-word isearch-word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (isearch-regexp isearch-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (isearch-op-fun isearch-op-fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (isearch-cmds isearch-cmds)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (isearch-success isearch-success)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (isearch-wrapped isearch-wrapped)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (isearch-barrier isearch-barrier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 (isearch-adjusted isearch-adjusted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 (isearch-fixed-case isearch-fixed-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (isearch-yank-flag isearch-yank-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (isearch-invalid-regexp isearch-invalid-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (isearch-within-brackets isearch-within-brackets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 ;;; Don't bind this. We want isearch-search, below, to set it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 ;;; And the old value won't matter after that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 ;;; (isearch-other-end isearch-other-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 (isearch-opoint isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (isearch-slow-terminal-mode isearch-slow-terminal-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (isearch-small-window isearch-small-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (isearch-recursive-edit isearch-recursive-edit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 (isearch-selected-frame (selected-frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 ;; Actually terminate isearching until editing is done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 ;; This is so that the user can do anything without failure,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 ;; like switch buffers and start another isearch, and return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 ;; (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (isearch-done t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 ;;#### What does this mean? There is no such condition!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 ;; (exit nil)) ; was recursive editing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 ;; Fake the prompt message for the sake of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 ;; next-command-event below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (isearch-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 ;; If the first character the user types when we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 ;; prompt them for a string is the yank-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 ;; character, then go into word-search mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 ;; Otherwise unread that character and read a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 ;; the normal way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (let* ((cursor-in-echo-area t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (event (next-command-event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (if (eq 'isearch-yank-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (lookup-key isearch-mode-map (vector event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (setq isearch-word t;; so message-prefix is right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 isearch-new-word t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (setq unread-command-event event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 (setq isearch-new-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (read-from-minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 (isearch-message-prefix nil isearch-nonincremental)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 isearch-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 minibuffer-local-isearch-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 't ;does its own history (but shouldn't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 isearch-new-message (mapconcat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 'isearch-text-char-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 isearch-new-string "")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 ;; Always resume isearching by restarting it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (isearch-mode isearch-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 isearch-op-fun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 isearch-recursive-edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 isearch-word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 ;; Copy new values in outer locals to isearch globals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (setq isearch-string isearch-new-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 isearch-message isearch-new-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 isearch-forward isearch-new-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 isearch-word isearch-new-word))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 ;; Empty isearch-string means use default.
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 4063
diff changeset
836 (if (eql 0 (length isearch-string))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 (setq isearch-string (or (car (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 regexp-search-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 ""))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 ;; Reinvoke the pending search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (isearch-push-state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (isearch-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 (isearch-update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (if isearch-nonincremental (isearch-done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (quit ; handle abort-recursive-edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (isearch-abort) ;; outside of let to restore outside global values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (defun isearch-nonincremental-exit-minibuffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (setq isearch-nonincremental t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (exit-minibuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (defun isearch-forward-exit-minibuffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 (setq isearch-new-forward t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (exit-minibuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (defun isearch-reverse-exit-minibuffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (setq isearch-new-forward nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (exit-minibuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (defun isearch-cancel ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 "Terminate the search and go back to the starting point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (goto-char isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (isearch-done t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (signal 'quit '(isearch))) ; and pass on quit signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (defun isearch-abort ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 "Abort incremental search mode if searching is successful, signaling quit.
2068
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
876 Leave the search string at the head of the search ring. Note that this
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
877 behavior differs from GNU Emacs, which forgets the current search string
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
878 on abort regardless of success or failure. Use `isearch-cancel' to abort
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
879 and forget regardless of success or failure.
7dc50bbd7a39 [xemacs-hg @ 2004-05-10 07:04:34 by stephent]
stephent
parents: 2030
diff changeset
880
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 Otherwise, revert to previous successful search and continue searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 Use `isearch-exit' to quit without signaling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 ;; (ding) signal instead below, if quitting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (discard-input)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 (if isearch-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 ;; If search is successful, move back to starting point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 ;; and really do quit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 (progn (goto-char isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (setq isearch-success nil)
2030
488b2f76d852 [xemacs-hg @ 2004-04-19 08:54:47 by stephent]
stephent
parents: 1601
diff changeset
891 (isearch-done) ; exit and push target string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (signal 'quit '(isearch))) ; and pass on quit signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 ;; If search is failing, or has an incomplete regexp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 ;; rub out until it is once more successful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (while (or (not isearch-success) isearch-invalid-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (isearch-pop-state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (isearch-update)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (defun isearch-repeat (direction)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 ;; Utility for isearch-repeat-forward and -backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (if (eq isearch-forward (eq direction 'forward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 ;; C-s in forward or C-r in reverse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (if (equal isearch-string "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 ;; If search string is empty, use last one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (setq isearch-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (or (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (car regexp-search-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (car search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 isearch-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (mapconcat 'isearch-text-char-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 isearch-string ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 ;; If already have what to search for, repeat it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (or isearch-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (goto-char (if isearch-forward (point-min) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (setq isearch-wrapped t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 ;; C-s in reverse or C-r in forward, change direction.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (setq isearch-forward (not isearch-forward)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (setq isearch-barrier (point)) ; For subsequent \| if regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (if (equal isearch-string "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (setq isearch-success t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (if (and isearch-success (equal (match-end 0) (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (not isearch-just-started))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 ;; If repeating a search that found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 ;; an empty string, ensure we advance.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (if (if isearch-forward (eobp) (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 ;; If there's nowhere to advance to, fail (and wrap next time).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (setq isearch-success nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (and executing-kbd-macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (not defining-kbd-macro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (isearch-done))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (ding nil 'isearch-failed))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (forward-char (if isearch-forward 1 -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (isearch-search))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (isearch-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (isearch-push-state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (defun isearch-repeat-forward ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 "Repeat incremental search forwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (isearch-repeat 'forward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 (defun isearch-repeat-backward ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 "Repeat incremental search backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (isearch-repeat 'backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 (defun isearch-toggle-regexp ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 "Toggle regexp searching on or off."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 ;; The status stack is left unchanged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (setq isearch-regexp (not isearch-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (if isearch-regexp (setq isearch-word nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (defun isearch-toggle-case-fold ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 "Toggle case folding in searching on or off."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (setq isearch-case-fold-search (if isearch-case-fold-search nil 'yes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 isearch-fixed-case t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (lmessage 'progress "%s%s [case %ssensitive]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 (isearch-message-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 isearch-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (if isearch-case-fold-search "in" ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (setq isearch-adjusted t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 ;; Update the highlighting here so that it gets done before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 ;; one-second pause.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (isearch-highlight-all-update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (defun isearch-delete-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 "Discard last input item and move point back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 If no previous match was done, just beep."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (if (null (cdr isearch-cmds))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (ding nil 'isearch-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (isearch-pop-state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (defun isearch-help-or-delete-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 "Show Isearch help or delete backward in the search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 Deletes when `delete-key-deletes-forward' is t and C-h is used for deleting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (if (and delete-key-deletes-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (case (device-type)
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
994 (tty (eq (declare-boundp tty-erase-char) ?\C-h))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
995 (x (not (declare-fboundp
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
996 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (isearch-delete-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 (isearch-mode-help)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 ;; This is similar to FSF isearch-yank-string, but more general.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (defun isearch-yank (chunk)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 ;; Helper for isearch-yank-* functions. CHUNK can be a string or a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 ;; function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (let ((word (if (stringp chunk)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 chunk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 (and (not isearch-forward) isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 (goto-char isearch-other-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (funcall chunk)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (point)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 ;; if configured so that typing upper-case characters turns off case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 ;; folding, then downcase the string so that yanking an upper-case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 ;; word doesn't mess with case-foldedness.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (if (and search-caps-disable-folding isearch-case-fold-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (setq word (downcase word)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (if isearch-regexp (setq word (regexp-quote word)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (setq isearch-string (concat isearch-string word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 isearch-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (concat isearch-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (mapconcat 'isearch-text-char-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 word ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;; Don't move cursor in reverse search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 isearch-yank-flag t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (isearch-search-and-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (defun isearch-yank-word ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 "Pull next word from buffer into search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (isearch-yank (function (lambda () (forward-word 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (defun isearch-yank-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 "Pull rest of line from buffer into search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (isearch-yank 'end-of-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (defun isearch-yank-kill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 "Pull rest of line from kill ring into search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (isearch-yank (current-kill 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (defun isearch-yank-sexp ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 "Pull next expression from buffer into search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (isearch-yank 'forward-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (defun isearch-yank-selection ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 "Pull the current selection into the search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (isearch-yank (get-selection)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 (defun isearch-yank-clipboard ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 "Pull the current clipboard selection into the search string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (isearch-yank (get-clipboard)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (defun isearch-fix-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 ;; The commented-out (and ...) form implies that, once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 ;; isearch-case-fold-search becomes nil due to a capital letter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 ;; typed in, it can never be restored to the original value. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 ;; that case, it's impossible to revert a case-sensitive search back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 ;; to case-insensitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (if ;(and isearch-case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (and case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 ;; Make sure isearch-toggle-case-fold works.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (not isearch-fixed-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (setq isearch-case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (no-upper-case-p isearch-string isearch-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (setq isearch-mode (if case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (if isearch-case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 " Isearch" ;As God Intended Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 " ISeARch") ;Warn about evil case via StuDLYcAps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 " Isearch")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (defun isearch-search-and-update ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 ;; Do the search and update the display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (if (and (not isearch-success)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 ;; unsuccessful regexp search may become
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 ;; successful by addition of characters which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 ;; make isearch-string valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 (not isearch-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 ;; In reverse search, adding stuff at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 ;; the end may cause zero or many more chars to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 ;; matched, in the string following point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 ;; Allow all those possibilities without moving point as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 ;; long as the match does not extend past search origin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (if (and (not isearch-forward) (not isearch-adjusted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (isearch-fix-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (let ((case-fold-search isearch-case-fold-search))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 (looking-at (if isearch-regexp isearch-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (regexp-quote isearch-string)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (error nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (or isearch-yank-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (<= (match-end 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (min isearch-opoint isearch-barrier))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (setq isearch-success t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 isearch-invalid-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 isearch-within-brackets nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 isearch-other-end (match-end 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 ;; Not regexp, not reverse, or no match at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (if (and isearch-other-end (not isearch-adjusted))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (goto-char (if isearch-forward isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (min isearch-opoint
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 isearch-barrier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (1+ isearch-other-end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (isearch-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (isearch-push-state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 (if isearch-op-fun (funcall isearch-op-fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 ;; *, ?, and | chars can make a regexp more liberal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 ;; They can make a regexp match sooner or make it succeed instead of failing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 ;; So go back to place last successful search started
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 ;; or to the last ^S/^R (barrier), whichever is nearer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 ;; + needs no special handling because the string must match at least once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (defun isearch-*-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 "Handle * and ? specially in regexps."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (let ((idx (length isearch-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (while (and (> idx 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (eq (aref isearch-string (1- idx)) ?\\))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (setq idx (1- idx)))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 4063
diff changeset
1133 (when (eql (mod (- (length isearch-string) idx) 2) 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (setq isearch-adjusted t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 ;; Get the isearch-other-end from before the last search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 ;; We want to start from there,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 ;; so that we don't retreat farther than that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 ;; (car isearch-cmds) is after last search;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 ;; (car (cdr isearch-cmds)) is from before it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (let ((cs (nth 5 (car (cdr isearch-cmds)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 (setq cs (or cs isearch-barrier))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (goto-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (if isearch-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (max cs isearch-barrier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 (min cs isearch-barrier)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (isearch-process-search-char last-command-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (defun isearch-|-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 "If in regexp search, jump to the barrier."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (setq isearch-adjusted t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (goto-char isearch-barrier)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (isearch-process-search-char last-command-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 ;; FSF:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 ;(defalias 'isearch-other-control-char 'isearch-other-meta-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 ;(defun isearch-other-meta-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 ;...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (defun isearch-quote-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 "Quote special characters for incremental search."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 ;; #### Here FSF does some special conversion of chars in 0200-0377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 ;; range. Maybe we should do the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (isearch-process-search-char (read-quoted-char (isearch-message t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (defun isearch-return-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 "Convert return into newline for incremental search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 Obsolete."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (isearch-process-search-char ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (defun isearch-printing-char ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 "Add this ordinary printing character to the search string and search."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (let ((event last-command-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 ;; If we are called by isearch-whitespace-chars because the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 ;; context disallows whitespace search (e.g. within brackets),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 ;; replace M-SPC with a space. FSF has similar code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (and (eq this-command 'isearch-whitespace-chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (null (event-to-character event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (setq event (character-to-event ?\ )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (isearch-process-search-char event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (defun isearch-whitespace-chars ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 "Match all whitespace chars, if in regexp mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 ;; FSF docstring adds: "If you want to search for just a space, type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 ;; C-q SPC." But we don't need the addition because we have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 ;; different (better) default for the variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (if (and search-whitespace-regexp (not isearch-within-brackets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 (not isearch-invalid-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (isearch-process-search-string search-whitespace-regexp " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (isearch-printing-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 ;; This way of doing word search doesn't correctly extend current search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 ;; (setq isearch-word t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 ;; (setq isearch-adjusted t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 ;; (goto-char isearch-barrier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (isearch-printing-char))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 (defun isearch-process-search-char (char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 ;; Append the char to the search string, update the message and re-search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (isearch-process-search-string (isearch-char-to-string char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (isearch-text-char-description char)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (defun isearch-process-search-string (string message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (setq isearch-string (concat isearch-string string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 isearch-message (concat isearch-message message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 (isearch-search-and-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 ;;===========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 ;; Search Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (defun isearch-ring-adjust1 (advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 ;; Helper for isearch-ring-adjust
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (length (length ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 (yank-pointer-name (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 'regexp-search-ring-yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 'search-ring-yank-pointer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 (yank-pointer (eval yank-pointer-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 (if (zerop length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (set yank-pointer-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 (setq yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 (mod (+ (or yank-pointer 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1236 ;; XEmacs change
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1237 (if advance -1 (if yank-pointer 1 0)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 length)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (setq isearch-string (nth yank-pointer ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 isearch-message (mapconcat 'isearch-text-char-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 isearch-string "")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (defun isearch-ring-adjust (advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 ;; Helper for isearch-ring-advance and isearch-ring-retreat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 ; (if (cdr isearch-cmds) ;; is there more than one thing on stack?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 ; (isearch-pop-state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 (isearch-ring-adjust1 advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (if search-ring-update
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 (isearch-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 (isearch-update))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 (isearch-edit-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (isearch-push-state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 (defun isearch-ring-advance ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 "Advance to the next search string in the ring."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 ;; This could be more general to handle a prefix arg, but who would use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (isearch-ring-adjust 'advance))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (defun isearch-ring-retreat ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 "Retreat to the previous search string in the ring."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 (isearch-ring-adjust nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (defun isearch-ring-advance-edit (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 "Insert the next element of the search history into the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (let* ((yank-pointer-name (if isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 'regexp-search-ring-yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 'search-ring-yank-pointer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (yank-pointer (eval yank-pointer-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (ring (if isearch-regexp regexp-search-ring search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (length (length ring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (if (zerop length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (set yank-pointer-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (setq yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (mod (- (or yank-pointer 0) n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 length)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 (insert (nth yank-pointer ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (goto-char (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (defun isearch-ring-retreat-edit (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 "Inserts the previous element of the search history into the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (isearch-ring-advance-edit (- n)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 ;; Merging note: FSF comments out these functions and implements them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 ;; differently (see above), presumably because the versions below mess
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 ;; with isearch-string, while what we really want them to do is simply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 ;; to insert the correct string to the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 ;;(defun isearch-ring-adjust-edit (advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 ;; "Use the next or previous search string in the ring while in minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 ;; (isearch-ring-adjust1 advance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 ;; (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 ;; (insert isearch-string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 ;;(defun isearch-ring-advance-edit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 ;; (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 ;; (isearch-ring-adjust-edit 'advance))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 ;;(defun isearch-ring-retreat-edit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 ;; "Retreat to the previous search string in the ring while in the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 ;; (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 ;; (isearch-ring-adjust-edit nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 (defun isearch-complete1 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 ;; Helper for isearch-complete and isearch-complete-edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 ;; Return t if completion OK, nil if no completion exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (alist (mapcar (function (lambda (string) (list string))) ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (completion-ignore-case case-fold-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (completion (try-completion isearch-string alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 ((eq completion t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 ;; isearch-string stays the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 ((or completion ; not nil, must be a string
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 4063
diff changeset
1325 (eql 0 (length isearch-string))) ; shouldn't have to say this
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (if (equal completion isearch-string) ;; no extension?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 (if completion-auto-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 (with-output-to-temp-buffer "*Isearch completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 (display-completion-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (all-completions isearch-string alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (and completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (setq isearch-string completion))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (temp-minibuffer-message "No completion")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (defun isearch-complete ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 "Complete the search string from the strings on the search ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 The completed string is then editable in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 If there is no completion possible, say so and continue searching."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (if (isearch-complete1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (isearch-edit-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 ;; else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (isearch-update)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (defun isearch-complete-edit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 "Same as `isearch-complete' except in the minibuffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (setq isearch-string (buffer-string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 (if (isearch-complete1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (insert isearch-string))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 ;;;==============================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 ;; The search status stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (defun isearch-top-state ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (let ((cmd (car isearch-cmds)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 ;; #### Grr, this is so error-prone. If you add something to
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1366 ;; isearch-push-state, don't forget to update this. I thought I'd
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 ;; make a list of variables, and just do (mapcar* #'set vars
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 ;; values), but the (point) thing would spoil it, leaving to more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 ;; complication.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (setq isearch-string (car cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 isearch-message (car (cdr cmd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 isearch-success (nth 3 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 isearch-forward (nth 4 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 isearch-other-end (nth 5 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 isearch-word (nth 6 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 isearch-invalid-regexp (nth 7 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 isearch-wrapped (nth 8 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 isearch-barrier (nth 9 cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 isearch-within-brackets (nth 10 cmd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 (goto-char (car (cdr (cdr cmd))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 (defun isearch-pop-state ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (pop isearch-cmds)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 (isearch-top-state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 ;; Make sure isearch-case-fold-search gets the correct value. FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 ;; simply stores isearch-case-fold-search to isearch-cmds. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 ;; should probably do the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (isearch-fix-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 ;; Here, as well as in isearch-search we must deal with the point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 ;; landing at an invisible area which may need unhiding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (if (or (not (eq search-invisible 'open))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 (not isearch-hide-immediately))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 ;; If search-invisible is t, invisible text is just like any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 ;; other text. If it is nil, it is always skipped and we can't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 ;; land inside. In both cases, we don't need to do anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ;; Similarly, if isearch-hide-immediately is nil, needn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 ;; re-hide the area here, and neither can we land back into a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 ;; hidden one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 (when isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 ;; This will unhide the extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 (isearch-range-invisible (point) isearch-other-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 (isearch-restore-invisible-extents (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 (or isearch-other-end (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (defun isearch-push-state ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (setq isearch-cmds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 (cons (list isearch-string isearch-message (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 isearch-success isearch-forward isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 isearch-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 isearch-invalid-regexp isearch-wrapped isearch-barrier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 isearch-within-brackets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 isearch-cmds)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 ;;;==================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 ;; Message string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 (defun isearch-message (&optional c-q-hack ellipsis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 ;; Generate and print the message string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (let ((cursor-in-echo-area ellipsis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (m (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 isearch-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (isearch-message-suffix c-q-hack ellipsis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (if c-q-hack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 (display-message 'progress (format "%s" m)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 ;; If about to search, and previous search regexp was invalid,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 ;; check that it still is. If it is valid now,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 ;; let the message we display while searching say that it is valid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (and isearch-invalid-regexp ellipsis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 (progn (re-search-forward isearch-string (point) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (setq isearch-invalid-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 isearch-within-brackets nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 ;; If currently failing, display no ellipsis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 (or isearch-success (setq ellipsis nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 ;; #### - ! Emacs assembles strings all over the place, they can't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 ;; all be internationalized in the manner proposed below... Add an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 ;; explicit call to `gettext' and have the string snarfer pluck the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 ;; english strings out of the comment below. XEmacs is on a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 ;; purespace diet! -Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 ;; The comment below is dead and buried, but it can be rebuilt if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 ;; necessary. -hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 (let ((m (concat (if isearch-success nil "failing ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (if (and isearch-wrapped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (if isearch-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 (> (point) isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 (< (point) isearch-opoint)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 "overwrapped "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (if isearch-wrapped "wrapped "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 (if isearch-word "word ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (if isearch-regexp "regexp ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 (if nonincremental "search" "I-search")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (if isearch-forward nil " backward")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 ": "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (aset m 0 (upcase (aref m 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 (gettext m)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 (defun isearch-message-suffix (&optional c-q-hack ellipsis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (concat (if c-q-hack "^Q" "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 (if isearch-invalid-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 (concat " [" isearch-invalid-regexp "]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 "")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 ;;;(let ((i (logior (if isearch-success 32 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 ;;; (if isearch-wrapped 16 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 ;;; (if isearch-word 8 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 ;;; (if isearch-regexp 4 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 ;;; (if nonincremental 2 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 ;;; (if isearch-forward 1 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 ;;; (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 ;;; ((= i 63) (gettext "Wrapped word regexp search: ")) ; 111111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 ;;; ...and so on, ad nauseam...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 ;;; ((= i 0) (gettext "Failing I-search backward: ")) ; 000000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 ;;; (t (error "Something's rotten")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 ;;;========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 ;;; Exiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 (put 'isearch-printing-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 (put 'isearch-return-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 (put 'isearch-repeat-forward 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 (put 'isearch-repeat-backward 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 (put 'isearch-delete-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 (put 'isearch-help-or-delete-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (put 'isearch-cancel 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 (put 'isearch-abort 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (put 'isearch-quote-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (put 'isearch-exit 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (put 'isearch-printing-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (put 'isearch-printing-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (put 'isearch-yank-word 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (put 'isearch-yank-line 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (put 'isearch-yank-kill 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (put 'isearch-yank-sexp 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (put 'isearch-*-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (put 'isearch-*-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (put 'isearch-|-char 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 (put 'isearch-toggle-regexp 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 (put 'isearch-toggle-case-fold 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 (put 'isearch-edit-string 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (put 'isearch-mode-help 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (put 'isearch-ring-advance 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 (put 'isearch-ring-retreat 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (put 'isearch-ring-advance-edit 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (put 'isearch-ring-retreat-edit 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (put 'isearch-whitespace-chars 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (put 'isearch-complete 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 (put 'isearch-complete-edit 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (put 'isearch-edit-string 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (put 'isearch-toggle-regexp 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (put 'isearch-forward-exit-minibuffer 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (put 'isearch-reverse-exit-minibuffer 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 (put 'isearch-nonincremental-exit-minibuffer 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 (put 'isearch-yank-selection 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (put 'isearch-yank-clipboard 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 (put 'isearch-yank-x-selection 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (put 'isearch-yank-x-clipboard 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 ;; scrolling the scrollbar should not terminate isearch.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 ;; vertical scrollbar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 (put 'scrollbar-line-up 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 (put 'scrollbar-line-down 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 (put 'scrollbar-page-up 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (put 'scrollbar-page-down 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 (put 'scrollbar-to-top 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 (put 'scrollbar-to-bottom 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (put 'scrollbar-vertical-drag 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 ;; horizontal scrollbar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 (put 'scrollbar-char-left 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 (put 'scrollbar-char-right 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (put 'scrollbar-page-left 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (put 'scrollbar-page-right 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (put 'scrollbar-to-left 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (put 'scrollbar-to-right 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (put 'scrollbar-horizontal-drag 'isearch-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (defun isearch-pre-command-hook ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 ;; For use as the value of `pre-command-hook' when isearch-mode is active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 ;; If the command about to be executed is not one of the isearch commands,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 ;; then isearch-mode is turned off before that command is executed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 ;; If the command about to be executed is self-insert-command, or is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 ;; keyboard macro of a single key sequence which is bound to self-insert-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 ;; command, then we add those chars to the search ring instead of inserting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 ;; them in the buffer. In this way, the set of self-searching characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 ;; need not be exhaustively enumerated, but is derived from other maps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 (cond ((not (eq (current-buffer) isearch-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 ;; If the buffer (likely meaning "frame") has changed, bail.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 ;; This can happen if the user types something into another
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 ;; frame. It can also happen if a proc filter has popped up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 ;; another buffer, which is arguably a bad thing for it to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 ;; have done, but the way in which isearch would have hosed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 ;; you in that case is unarguably even worse. -jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 (isearch-done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 ;; `this-command' is set according to the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 ;; `overriding-local-map', set by isearch-mode. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 ;; wrong because that keymap makes sense only in isearch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 ;; buffer. To make sure the right command is called, adjust
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 ;; `this-command' to the appropriate value, now that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 ;; `isearch-done' has set `overriding-local-map' to nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 ;; FSF does similar magic in `isearch-other-meta-char', which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 ;; is horribly complex. I *hope* what we do works in all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 ;; cases.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 (setq this-command (key-binding (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (isearch-maybe-frob-keyboard-macros)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 (if (and this-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 (symbolp this-command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 (get this-command 'isearch-command))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 nil ; then continue.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 (isearch-done)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 (defun isearch-maybe-frob-keyboard-macros ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 ;; If the command about to be executed is `self-insert-command' then change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 ;; the command to `isearch-printing-char' instead, meaning add the last-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 ;; typed character to the search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 ;; If `this-command' is a string or a vector (that is, a keyboard macro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 ;; and it contains only one command, which is bound to self-insert-command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 ;; then do the same thing as for self-inserting commands: arrange for that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 ;; character to be added to the search string. If we didn't do this, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 ;; typing a compose sequence (a la x-compose.el) would terminate the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 ;; and insert the character, instead of searching for that character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 ;; We should continue doing this, since it's pretty much the behavior one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 ;; would expect, but it will stop being so necessary once key-translation-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 ;; map exists and is used by x-compose.el and things like it, since the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 ;; translation will have been done before we see the keys.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (cond ((eq this-command 'self-insert-command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (setq this-command 'isearch-printing-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 ((and (or (stringp this-command) (vectorp this-command))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 (eq (key-binding this-command) 'self-insert-command))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 (setq last-command-event (character-to-event (aref this-command 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 last-command-char (and (stringp this-command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 (aref this-command 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 this-command 'isearch-printing-char))
5371
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1618 ((and (null this-command)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1619 (eq 'key-press (event-type last-command-event))
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1620 (current-local-map)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1621 (let* ((this-command-keys (this-command-keys))
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1622 (this-command-keys (or (lookup-key function-key-map
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1623 this-command-keys)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1624 this-command-keys))
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1625 (lookup-key (lookup-key global-map this-command-keys)))
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1626 (and (eq 'self-insert-command lookup-key)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1627 ;; The feature here that a modification of
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1628 ;; last-command-event is respected is undocumented, and
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1629 ;; only applies when this-command is nil. The design
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1630 ;; isn't reat, and I welcome suggestions for a better
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1631 ;; one.
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1632 (setq last-command-event
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1633 (find-if 'key-press-event-p this-command-keys
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1634 :from-end t)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1635 last-command-char
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1636 (event-to-character last-command-event)
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1637 this-command 'isearch-printing-char)))))))
6f10ac29bf40 Be better about searching for chars typed via XIM and x-compose.el, isearch
Aidan Kehoe <kehoea@parhasard.net>
parents: 5366
diff changeset
1638
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 ;;;========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 ;;; Highlighting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 (defvar isearch-extent nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 ;; this face is initialized by faces.el since isearch is preloaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 ;(make-face 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 (defun isearch-make-extent (begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 (let ((x (make-extent begin end (current-buffer))))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1650 ;; make the isearch extent always take precedence over any mouse-
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 ;; highlighted extents we may be passing through, since isearch, being
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 ;; modal, is more interesting (there's nothing they could do with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 ;; mouse-highlighted extent while in the midst of a search anyway).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 (set-extent-priority x (+ mouse-highlight-priority 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 (set-extent-face x 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 (setq isearch-extent x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 (defun isearch-highlight (begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 (if (null search-highlight)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 ;; make sure isearch-extent is in the current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (or (and (extentp isearch-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 (extent-live-p isearch-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (isearch-make-extent begin end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (set-extent-endpoints isearch-extent begin end (current-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 ;; This used to have a TOTALLY flag that also deleted the extent. I
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 ;; don't think this is necessary any longer, as isearch-highlight can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 ;; simply move the extent to another buffer. The IGNORED argument is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 ;; for the code that calls this function with an argument. --hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (defun isearch-dehighlight (&optional ignored)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 (and search-highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 (extentp isearch-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 (extent-live-p isearch-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (detach-extent isearch-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 ;;;========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 ;;; Searching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 (defun isearch-search ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 ;; Do the search with the current search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (isearch-message nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 (isearch-fix-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 (condition-case lossage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 (let ((inhibit-quit nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 (case-fold-search isearch-case-fold-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (retry t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 (if isearch-regexp (setq isearch-invalid-regexp nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 (setq isearch-within-brackets nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (while retry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 (setq isearch-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 (funcall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (cond (isearch-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 (if isearch-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 'word-search-forward 'word-search-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (isearch-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 (if isearch-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 're-search-forward 're-search-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (if isearch-forward 'search-forward 'search-backward)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 isearch-string nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 ;; Clear RETRY unless we matched some invisible text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 ;; and we aren't supposed to do that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 (if (or (eq search-invisible t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 (not isearch-success)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 (bobp) (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 (= (match-beginning 0) (match-end 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (not (isearch-range-invisible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (match-beginning 0) (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (setq retry nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (setq isearch-just-started nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 (when isearch-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (setq isearch-other-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (if isearch-forward (match-beginning 0) (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (and isearch-hide-immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 (isearch-restore-invisible-extents (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (match-end 0)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 (quit (setq unread-command-events (nconc unread-command-events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 (character-to-event (quit-char))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 (setq isearch-success nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (invalid-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 (setq isearch-invalid-regexp (car (cdr lossage)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 isearch-invalid-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (if (string-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 isearch-invalid-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 (setq isearch-invalid-regexp (gettext "incomplete input"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 ;; stack overflow in regexp search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (setq isearch-invalid-regexp (car (cdr lossage)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 (if isearch-success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 ;; If we're being run inside a keyboard macro, then the call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 ;; ding will signal an error (to terminate the macro). We must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 ;; turn off isearch-mode first, so that we aren't still in isearch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 ;; mode after the macro exits. Note that isearch-recursive-edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 ;; must not be true if a keyboard macro is executing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 (if (and executing-kbd-macro (not defining-kbd-macro))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 (isearch-done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (ding nil 'isearch-failed)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 ;; Ding if failed this time after succeeding last time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 (and (nth 3 (car isearch-cmds))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 (ding nil 'isearch-failed))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (goto-char (nth 2 (car isearch-cmds)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 ;; Replaced with isearch-edit-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 ;(defun nonincremental-search (forward regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 ;...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (defun isearch-unhide-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 ;; Store the values for the `invisible' and `intangible'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 ;; properties, and then set them to nil. This way the text hidden
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 ;; by this extent becomes visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 (put extent 'isearch-invisible (get extent 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (put extent 'isearch-intangible (get extent 'intangible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 (put extent 'invisible nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (put extent 'intangible nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1767 (defun isearch-range-invisible (start end)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1768 "Return t if all the text from START to END is invisible.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 Before that, if search-invisible is `open', unhide the extents with an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 `isearch-open-invisible' property."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 ;; isearch-search uses this to skip the extents that are invisible,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 ;; but don't have `isearch-open-invisible' set. It is unclear
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1773 ;; what's supposed to happen if only a part of [START, END) overlaps
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 ;; the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 (let (to-be-unhidden)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 (if (map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 (lambda (extent ignored)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1778 (if (and (<= (extent-start-position extent) start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 (>= (extent-end-position extent) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 ;; All of the region is covered by the extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 (if (and (eq search-invisible 'open)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 (get extent 'isearch-open-invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (push extent to-be-unhidden)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 nil) ; keep mapping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 ;; We can't or won't unhide this extent, so we must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 ;; skip the whole match. We return from map-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 ;; immediately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 ;; Else, keep looking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 nil))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1792 nil start end nil 'all-extents-closed 'invisible)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 ;; The whole match must be skipped. Signal it by returning t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 ;; to the caller.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 ;; If any extents need to be unhidden, unhide them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 (mapc #'isearch-unhide-extent to-be-unhidden)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 ;; Will leave this assert for some time, to catch bugs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 (assert (null (intersection to-be-unhidden isearch-unhidden-extents)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 (setq isearch-unhidden-extents (nconc to-be-unhidden
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 isearch-unhidden-extents))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 (defun isearch-restore-extent (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (put extent 'invisible (get extent 'isearch-invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 (put extent 'intangible (get extent 'isearch-intangible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 (remprop extent 'isearch-invisible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 (remprop extent 'isearch-intangible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 ;; FSF calls this function `isearch-clean-overlays'.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1811 (defun isearch-restore-invisible-extents (start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 (cond
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1813 ((null start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 ;; Delete all -- this is called at the end of isearch.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 (mapc #'isearch-restore-extent isearch-unhidden-extents)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (setq isearch-unhidden-extents nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 ;; Extents that do not overlap the match area can be safely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 ;; restored to their hidden state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 (setq isearch-unhidden-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 (delete-if (lambda (extent)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1822 (unless (extent-in-region-p extent start end
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 'all-extents-closed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 (isearch-restore-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 isearch-unhidden-extents)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 (defun isearch-no-upper-case-p (string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 "Return t if there are no upper case chars in string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 But upper case chars preceded by \\ do not count since they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 have special meaning in a regexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 ;; this incorrectly returns t for "\\\\A"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 (make-obsolete 'isearch-no-upper-case-p 'no-upper-case-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 ;; Portability functions to support various Emacs versions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 (defun isearch-char-to-string (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 (if (eventp c)
2828
a25c824ed558 [xemacs-hg @ 2005-06-26 18:04:49 by aidan]
aidan
parents: 2068
diff changeset
1841 (make-string 1 (event-to-character c))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 (make-string 1 c)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 ;(defun isearch-text-char-description (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 ; (isearch-char-to-string c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 (define-function 'isearch-text-char-description 'text-char-description)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 ;; Used by etags.el and info.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 (defmacro with-caps-disable-folding (string &rest body) "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 Eval BODY with `case-fold-search' let to nil if STRING contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 uppercase letters and `search-caps-disable-folding' is t."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 `(let ((case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 (if (and case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 (isearch-no-upper-case-p ,string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 case-fold-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 ,@body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 (make-obsolete 'with-caps-disable-folding 'with-search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (put 'with-caps-disable-folding 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (put 'with-caps-disable-folding 'edebug-form-spec '(form body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 ;;;========================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 ;;; Advanced highlighting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 ;; When active, *every* visible match for the current search string is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 ;; highlighted: the current one using the normal isearch match color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 ;; and all the others using the `isearch-secondary' face. The extra
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 ;; highlighting makes it easier to anticipate where the cursor will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 ;; land each time you press C-s or C-r to repeat a pending search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 ;; Only the matches visible at any point are highlighted -- when you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 ;; move through the buffer, the highlighting is readjusted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 ;; This is based on ideas from Bob Glickstein's `ishl' package. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 ;; has been merged with XEmacs by Darryl Okahata, and then completely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 ;; rewritten by Hrvoje Niksic.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 ;; The code makes the following assumptions about the rest of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 ;; file, so be careful when modifying it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 ;; * `isearch-highlight-all-update' should get called when the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 ;; string changes, or when the search advances. This is done from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 ;; `isearch-update'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 ;; * `isearch-highlight-all-cleanup' should get called when the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 ;; is done. This is performed in `isearch-done'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 ;; * `isearch-string' is expected to contain the current search string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 ;; as entered by the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 ;; * `isearch-opoint' is expected to contain the location where the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 ;; current search began.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 ;; * the type of the current search is expected to be given by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 ;; `isearch-word' and `isearch-regexp'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 ;; * the variable `isearch-invalid-regexp' is expected to be true iff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 ;; `isearch-string' is an invalid regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 (defcustom isearch-highlight-all-matches search-highlight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 "*Non-nil means highlight all visible matches."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 ;; We can't create this face here, as isearch.el is preloaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 ;; #### Think up a better name for this!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 ;(defface isearch-secondary '((t (:foreground "red3")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 ; "Face to use for highlighting all matches."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 ; :group 'isearch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (defvar isearch-highlight-extents nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (defvar isearch-window-start nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (defvar isearch-window-end nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 ;; We compare isearch-string and isearch-case-fold-search to saved
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 ;; values for better efficiency.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (defvar isearch-highlight-last-string nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 (defvar isearch-highlight-last-case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (defvar isearch-highlight-last-regexp nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (defun isearch-delete-extents-in-range (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 ;; Delete all highlighting extents that overlap [START, END).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (setq isearch-highlight-extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 (delete-if (lambda (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (when (extent-in-region-p extent start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 (delete-extent extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 isearch-highlight-extents)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (defun isearch-highlight-all-cleanup ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 ;; Stop lazily highlighting and remove extra highlighting from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 ;; buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (mapc #'delete-extent isearch-highlight-extents)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 (setq isearch-highlight-extents nil)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1929 (setq isearch-window-end nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 isearch-highlight-last-string nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (defun isearch-highlight-all-update ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 ;; Update the highlighting if necessary. This needs to check if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 ;; search string has changed, or if the window has changed position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 ;; in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 (let ((need-start-over nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 ;; NB: we don't check for isearch-success because if the point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 ;; after the last match, the search can be unsuccessful, and yet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 ;; there are things to highlight.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (cond ((not isearch-highlight-all-matches))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 ((or (equal isearch-string "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 isearch-invalid-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 (isearch-highlight-all-cleanup))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 ((not (eq isearch-case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 isearch-highlight-last-case-fold-search))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 ;; This case is usually caused by search string being
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 ;; changed, which would be caught below, but it can also be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 ;; tripped using isearch-toggle-case-fold.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 (setq need-start-over t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 ((not (eq isearch-regexp isearch-highlight-last-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 ;; Ditto for isearch-toggle-regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 (setq need-start-over t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 ((equal isearch-string isearch-highlight-last-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 ;; The search string is the same. We need to do something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 ;; if our position has changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 ;; It would be nice if we didn't have to do this; however,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 ;; window-start doesn't support a GUARANTEE flag, so we must
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1959 ;; force redisplay to get the correct value for start and end
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 ;; of window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 ;; Check whether our location has changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 (let ((start (window-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 (end (min (window-end) (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (cond ((and (= start isearch-window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (= end isearch-window-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 ;; Our position is unchanged -- do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 ((and (> start isearch-window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (> end isearch-window-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 (<= start isearch-window-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 ;; We've migrated downward, but we overlap the old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 ;; region. Delete the old non-overlapping extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 ;; and fill in the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (isearch-delete-extents-in-range isearch-window-start start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 (isearch-highlightify-region isearch-window-end end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 (setq isearch-window-start start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 isearch-window-end end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 ((and (<= start isearch-window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 (<= end isearch-window-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 (> end isearch-window-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 ;; We've migrated upward, but we overlap the old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 ;; region. Delete the old non-overlapping extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 ;; and fill in the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 (isearch-delete-extents-in-range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 end isearch-window-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 (isearch-highlightify-region start isearch-window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 (setq isearch-window-start start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 isearch-window-end end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 ;; The regions don't overlap, or they overlap in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 ;; weird way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 (setq need-start-over t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 ;; The search string has changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 ;; If more input is pending, don't start over because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 ;; starting over forces redisplay, and that slows down
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 ;; typing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 (unless (input-pending-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 (setq need-start-over t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 (when need-start-over
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 ;; Force redisplay before removing the old extents, in order to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 ;; avoid flicker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 (isearch-highlight-all-cleanup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 (setq isearch-window-start (window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 isearch-window-end (min (window-end) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 (isearch-highlightify-region isearch-window-start isearch-window-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 (setq isearch-highlight-last-string isearch-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 isearch-highlight-last-case-fold-search isearch-case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 isearch-highlight-last-regexp isearch-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (defun isearch-highlight-advance (string forwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 ;; Search ahead for the next or previous match. This is the same as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 ;; isearch-search, but without the extra baggage. Maybe it should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 ;; be in a separate function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (let ((case-fold-search isearch-case-fold-search))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (funcall (cond (isearch-word (if forwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 'word-search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 'word-search-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 (isearch-regexp (if forwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 're-search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 're-search-backward))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 (t (if forwardp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 'search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 'search-backward)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 string nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 (defun isearch-highlightify-region (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 ;; Highlight all occurrences of isearch-string between START and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 ;; END. To do this right, we have to search forward as long as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 ;; there are matches that overlap [START, END), and then search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 ;; backward the same way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 (goto-char isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 (let ((lastpoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 (while (and (isearch-highlight-advance isearch-string t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 (/= lastpoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 (< (match-beginning 0) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 (let ((extent (make-extent (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 (set-extent-priority extent (1+ mouse-highlight-priority))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 (put extent 'face 'isearch-secondary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 (push extent isearch-highlight-extents))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 (setq lastpoint (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 (goto-char isearch-opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 (let ((lastpoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 (while (and (isearch-highlight-advance isearch-string nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 (/= lastpoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 (>= (match-end 0) start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 (let ((extent (make-extent (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 (set-extent-priority extent (1+ mouse-highlight-priority))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 (put extent 'face 'isearch-secondary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 (push extent isearch-highlight-extents))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 (setq lastpoint (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 ;;; isearch-mode.el ends here