annotate lisp/prim/replace.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; replace.el --- search and replace commands for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; This package supplies the string and regular-expression replace functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; documented in the XEmacs Reference Manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar case-replace t "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 *Non-nil means `query-replace' should preserve case in replacements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 What this means is that `query-replace' will change the case of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 replacement text so that it matches the text that was replaced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 If this variable is nil, the replacement text will be inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 exactly as it was specified by the user, irrespective of the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 of the text that was replaced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Note that this flag has no effect if `case-fold-search' is nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 or if the replacement text has any uppercase letters in it.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvar query-replace-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defvar query-replace-interactive nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 "Non-nil means `query-replace' uses the last search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 That becomes the \"string to replace\".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defun query-replace-read-args (string regexp-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (let (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if query-replace-interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq from (car (if regexp-flag regexp-search-ring search-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq from (read-from-minibuffer (format "%s: " (gettext string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 'query-replace-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq to (read-from-minibuffer (format "%s %s with: " (gettext string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 'query-replace-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (list from to current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defun query-replace (from-string to-string &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "Replace some occurrences of FROM-STRING with TO-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 As each match is found, the user must type a character saying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 what to do with it. For directions, type \\[help-command] at that time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 If `query-replace-interactive' is non-nil, the last incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 string is used as FROM-STRING--you don't have to specify it with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Preserves case in each replacement if `case-replace' and `case-fold-search'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 are non-nil and FROM-STRING has no uppercase letters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 \(Preserving case means that if the string matched is all caps, or capitalized,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 then its replacement is upcased or capitalized.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 only matches surrounded by word boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 To customize possible responses, change the \"bindings\" in `query-replace-map'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (interactive (query-replace-read-args "Query replace" nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (perform-replace from-string to-string t nil arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defun query-replace-regexp (regexp to-string &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Replace some things after point matching REGEXP with TO-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 As each match is found, the user must type a character saying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 what to do with it. For directions, type \\[help-command] at that time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 If `query-replace-interactive' is non-nil, the last incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 regexp is used as REGEXP--you don't have to specify it with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Preserves case in each replacement if `case-replace' and `case-fold-search'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 are non-nil and REGEXP has no uppercase letters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 only matches surrounded by word boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 and `\\=\\N' (where N is a digit) stands for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 whatever what matched the Nth `\\(...\\)' in REGEXP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (interactive (query-replace-read-args "Query replace regexp" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (perform-replace regexp to-string t t arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;#### Not patently useful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun map-query-replace-regexp (regexp to-strings &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Replace some matches for REGEXP with various strings, in rotation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 The second argument TO-STRINGS contains the replacement strings, separated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 by spaces. This command works like `query-replace-regexp' except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 that each successive replacement uses the next successive replacement string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 wrapping around from the last such string to the first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Non-interactively, TO-STRINGS may be a list of replacement strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 If `query-replace-interactive' is non-nil, the last incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 regexp is used as REGEXP--you don't have to specify it with the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 A prefix argument N says to use each replacement string N times
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 before rotating to the next."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (let (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq from (if query-replace-interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (car regexp-search-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (read-from-minibuffer "Map query replace (regexp): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 'query-replace-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq to (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (format "Query replace %s with (space-separated strings): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 'query-replace-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (list from to current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (let (replacements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (if (listp to-strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq replacements to-strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (while (/= (length to-strings) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (if (string-match " " to-strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (setq replacements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (append replacements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (list (substring to-strings 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (string-match " " to-strings))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 to-strings (substring to-strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (1+ (string-match " " to-strings))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq replacements (append replacements (list to-strings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 to-strings ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (perform-replace regexp replacements t t nil arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defun replace-string (from-string to-string &optional delimited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "Replace occurrences of FROM-STRING with TO-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Preserve case in each match if `case-replace' and `case-fold-search'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 are non-nil and FROM-STRING has no uppercase letters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 only matches surrounded by word boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 If `query-replace-interactive' is non-nil, the last incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 string is used as FROM-STRING--you don't have to specify it with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 This function is usually the wrong thing to use in a Lisp program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 What you probably want is a loop like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (while (search-forward FROM-STRING nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (replace-match TO-STRING nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 which will run faster and will not set the mark or print anything."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (interactive (query-replace-read-args "Replace string" nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (perform-replace from-string to-string nil nil delimited))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defun replace-regexp (regexp to-string &optional delimited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "Replace things after point matching REGEXP with TO-STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Preserve case in each match if `case-replace' and `case-fold-search'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 are non-nil and REGEXP has no uppercase letters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 \(Preserving case means that if the string matched is all caps, or capitalized,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 then its replacement is upcased or capitalized.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 only matches surrounded by word boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 and `\\=\\N' (where N is a digit) stands for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 whatever what matched the Nth `\\(...\\)' in REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 If `query-replace-interactive' is non-nil, the last incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 regexp is used as REGEXP--you don't have to specify it with the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 This function is usually the wrong thing to use in a Lisp program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 What you probably want is a loop like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (while (re-search-forward REGEXP nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (replace-match TO-STRING nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 which will run faster and will not set the mark or print anything."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (interactive (query-replace-read-args "Replace regexp" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (perform-replace regexp to-string nil t delimited))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defvar regexp-history nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "History list for some commands that read regular expressions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (define-function 'keep-lines 'delete-non-matching-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defun delete-non-matching-lines (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Delete all lines except those containing matches for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 A match split across lines preserves all the lines it lies in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Applies to all lines after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (interactive (list (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "Keep lines (containing match for regexp): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 nil nil nil 'regexp-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (or (bolp) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Start is first char not preserved by previous match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (not (re-search-forward regexp nil 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (delete-region start (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (let ((end (save-excursion (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; Now end is first char preserved by the new match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (if (< start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (delete-region start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq start (save-excursion (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; If the match was empty, avoid matching again at same place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (and (not (eobp)) (= (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (forward-char 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (define-function 'flush-lines 'delete-matching-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun delete-matching-lines (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Delete lines containing matches for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 If a match is split across lines, all the lines it lies in are deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Applies to lines after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (interactive (list (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 "Flush lines (containing match for regexp): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 nil nil nil 'regexp-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (delete-region (save-excursion (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (progn (forward-line 1) (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (define-function 'how-many 'count-matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun count-matches (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Print number of matches for REGEXP following point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (interactive (list (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "How many matches for (regexp): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 nil nil nil 'regexp-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let ((count 0) opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (progn (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (re-search-forward regexp nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (message "%d occurrences" count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defvar occur-mode-map ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (if occur-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (setq occur-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (set-keymap-name occur-mode-map 'occur-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (define-key occur-mode-map 'button2 'occur-mode-mouse-goto)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defvar occur-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (defvar occur-nlines nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defvar occur-pos-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (defun occur-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "Major mode for output from \\[occur].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 \\<occur-mode-map>Move point to one of the items in this buffer, then use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 \\{occur-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (use-local-map occur-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq major-mode 'occur-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq mode-name (gettext "Occur"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (make-local-variable 'occur-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (make-local-variable 'occur-nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (make-local-variable 'occur-pos-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (require 'mode-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq mode-motion-hook 'mode-motion-highlight-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (run-hooks 'occur-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (defun occur-mode-mouse-goto (e)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
282 "Go to the occurrence highlighted by mouse.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
283 This function is only reasonable when bound to a mouse key in the occur buffer"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let ((window-save (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (frame-save (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; preserve the window/frame setup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (mouse-set-point e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (occur-mode-goto-occurrence))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (select-frame frame-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (select-window window-save))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defun occur-mode-goto-occurrence ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 "Go to the occurrence the current line describes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (if (or (null occur-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (null (buffer-name occur-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq occur-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 occur-pos-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (error "Buffer in which occurrences were found is deleted")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (let* ((line-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (count-lines (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (occur-number (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (/ (1- line-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (cond ((< occur-nlines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (- 2 occur-nlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ((> occur-nlines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (+ 2 (* 2 occur-nlines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (t 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (pos (nth occur-number occur-pos-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; removed t arg from Bob Weiner, 10/6/95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (window (get-buffer-window occur-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (occur-source-buffer occur-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (if (< line-count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (error "No occurrence on this line"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (or pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (error "No occurrence on this line"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ;; don't raise window unless it isn't visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; allow for the possibility that the occur buffer is on another frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (or (and window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (window-live-p window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (frame-visible-p (window-frame window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (set-buffer occur-source-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (and (pop-to-buffer occur-source-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq window (get-buffer-window occur-source-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (set-window-point window pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defvar list-matching-lines-default-context-lines 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 "*Default number of context lines to include around a `list-matching-lines'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 match. A negative number means to include that many lines before the match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 A positive number means to include that many lines both before and after.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;;; Damn you Jamie, this is utter trash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defvar list-matching-lines-whole-buffer t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "If t, occur operates on whole buffer, otherwise occur starts from point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 default is nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (define-function 'occur 'list-matching-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defun list-matching-lines (regexp &optional nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 "Show all lines in the current buffer containing a match for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 If a match spreads across multiple lines, all those lines are shown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 If variable `list-matching-lines-whole-buffer' is non-nil, the entire buffer is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 searched, otherwise search begins at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 Each line is displayed with NLINES lines before and after,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 or -NLINES before if NLINES is negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 NLINES defaults to `list-matching-lines-default-context-lines'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 Interactively it is the prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 The lines are shown in a buffer named `*Occur*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 It serves as a menu to find any of the occurrences in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 \\[describe-mode] in that buffer will explain how."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (list (let* ((default (or (symbol-near-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (and regexp-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (car regexp-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (minibuffer-history-minimum-string-length 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; rewritten for I18N3 snarfing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (format "List lines matching regexp (default `%s'): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 default) nil nil nil 'regexp-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 "List lines matching regexp: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 'regexp-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (and (equal input "") default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (setq input default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (setcar regexp-history default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; clear extra entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (setcdr regexp-history (delete (car regexp-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (cdr regexp-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (if (equal regexp "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (error "Must pass non-empty regexp to `list-matching-lines'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (setq nlines (if nlines (prefix-numeric-value nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 list-matching-lines-default-context-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (let ((first t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (linenum 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (prevpos (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (final-context-start (make-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (if (not list-matching-lines-whole-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq linenum (1+ (count-lines (point-min) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (setq prevpos (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (with-output-to-temp-buffer "*Occur*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (setq default-directory dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; We will insert the number of lines, and "lines", later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; #### Needs fixing for I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (let ((print-escape-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (insert (format " matching %s in buffer %s.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 regexp (buffer-name buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (occur-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (setq occur-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (setq occur-nlines nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (setq occur-pos-list ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if (eq buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if list-matching-lines-whole-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (beginning-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (message (format "Searching for %s ..." regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Find next match, but give up if prev match was at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (while (and (not (= prevpos (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq linenum (+ linenum (count-lines prevpos (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq prevpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let* ((start (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (forward-line (if (< nlines 0) nlines (- nlines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (end (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if (> nlines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (forward-line (1+ nlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (tag (format "%5d" linenum))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (empty (make-string (length tag) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq tem (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (set-marker tem (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (setq occur-pos-list (cons tem occur-pos-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (or first (zerop nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (insert "--------\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq first nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (insert-buffer-substring buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (set-marker final-context-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (- (point) (- end (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (backward-char (- end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (setq tem (if (< nlines 0) (- nlines) nlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (while (> tem 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (insert empty ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq tem (1- tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (let ((this-linenum linenum))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (while (< (point) final-context-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (if (null tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (setq tag (format "%5d" this-linenum)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (insert tag ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; FSFmacs -- we handle this using mode-motion-highlight-line, above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ; (put-text-property (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ; (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ; (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ; (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ; (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ; 'mouse-face 'highlight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq tag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (setq this-linenum (1+ this-linenum)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (while (<= (point) final-context-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (insert empty ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (setq this-linenum (1+ this-linenum))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (while (< tem nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (insert empty ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (setq tem (1+ tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; Put positions in increasing order to go with buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq occur-pos-list (nreverse occur-pos-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (= (length occur-pos-list) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (insert "1 line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (insert (format "%d lines" (length occur-pos-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (message "%d matching lines." (length occur-pos-list)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ;; It would be nice to use \\[...], but there is no reasonable way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 ;; to make that display both SPC and Y.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (defvar query-replace-help (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 "Type Space or `y' to replace one match, Delete or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 RET or `q' to exit, Period to replace one match and exit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 Comma to replace but not move point immediately,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 C-r to enter recursive edit (\\[exit-recursive-edit] to get out again),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 C-w to delete match and recursive edit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 C-l to clear the frame, redisplay, and offer same replacement again,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ! to replace all remaining matches with no more questions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ^ to move point back to previous match.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 "Help message while in query-replace")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (defvar query-replace-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Keymap that defines the responses to questions in `query-replace'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 The \"bindings\" in this map are not commands; they are answers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 The valid answers include `act', `skip', `act-and-show',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 `automatic', `backup', `exit-prefix', and `help'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (if query-replace-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (set-keymap-name map 'query-replace-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (define-key map " " 'act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (define-key map "\d" 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (define-key map [delete] 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (define-key map [backspace] 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (define-key map "y" 'act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (define-key map "n" 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (define-key map "Y" 'act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (define-key map "N" 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (define-key map "," 'act-and-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (define-key map [escape] 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (define-key map "q" 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (define-key map [return] 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (define-key map "." 'act-and-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (define-key map "\C-r" 'edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (define-key map "\C-w" 'delete-and-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (define-key map "\C-l" 'recenter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (define-key map "!" 'automatic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (define-key map "^" 'backup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (define-key map [(control h)] 'help) ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (define-key map [f1] 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (define-key map [help] 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (define-key map "?" 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (define-key map "\C-g" 'quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (define-key map "\C-]" 'quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;FSFmacs (define-key map "\e" 'exit-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (define-key map [escape] 'exit-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (setq query-replace-map map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (autoload 'isearch-highlight "isearch")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (defun perform-replace-next-event (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (if isearch-highlight
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (let ((aborted t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (isearch-highlight (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (next-command-event event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (setq aborted nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (isearch-dehighlight aborted)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (next-command-event event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (defun perform-replace (from-string replacements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 query-flag regexp-flag delimited-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 &optional repeat-count map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 "Subroutine of `query-replace'. Its complexity handles interactive queries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 Don't use this in your own program unless you want to query and set the mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 just as `query-replace' does. Instead, write a simple loop like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (while (re-search-forward \"foo[ \t]+bar\" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (replace-match \"foobar\" nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 which will run faster and probably do exactly what you want."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (or map (setq map query-replace-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (let* ((event (make-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (nocasify (not (and case-fold-search case-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (string-equal from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (downcase from-string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (literal (not regexp-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (search-function (if regexp-flag 're-search-forward 'search-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (search-string from-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (real-match-data nil) ; the match data for the current match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (next-replacement nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (replacement-index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (keep-going t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (stack nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (next-rotate-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (replace-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (lastrepl nil) ;Position after last match considered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (match-again t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;; XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (qr-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (if (and case-fold-search search-caps-disable-folding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (isearch-no-upper-case-p search-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (if query-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (if (stringp replacements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (setq next-replacement replacements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (or repeat-count (setq repeat-count 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (if delimited-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq search-function 're-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 search-string (concat "\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (if regexp-flag from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (regexp-quote from-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 "\\b")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (undo-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;; Loop finding occurrences that perhaps should be replaced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (while (and keep-going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (let ((case-fold-search qr-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (funcall search-function search-string nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ;; If the search string matches immediately after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ;; the previous match, but it did not match there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ;; before the replacement was done, ignore the match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (if (or (eq lastrepl (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (and regexp-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (eq lastrepl (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (not match-again)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;; Don't replace the null string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; right after end of previous replacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (let ((case-fold-search qr-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (funcall search-function search-string nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;; Save the data associated with the real match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq real-match-data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; Before we make the replacement, decide whether the search string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; can match again just after this match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (if regexp-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (setq match-again (looking-at search-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (store-match-data real-match-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; If time for a change, advance to next replacement string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (if (and (listp replacements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (= next-rotate-count replace-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (setq next-rotate-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (+ next-rotate-count repeat-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq next-replacement (nth replacement-index replacements))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (setq replacement-index (% (1+ replacement-index) (length replacements)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (not query-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (store-match-data real-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (replace-match next-replacement nocasify literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (setq replace-count (1+ replace-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (undo-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (let ((help-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 '(concat (format "Query replacing %s%s with %s.\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (if regexp-flag (gettext "regexp ") "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 from-string next-replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (substitute-command-keys query-replace-help)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (replaced nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; Loop reading commands until one of them sets done,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; which means it has finished handling this occurrence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ;; Don't fill up the message log
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;; with a bunch of identical messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (display-message 'prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (format message from-string next-replacement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (perform-replace-next-event event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (setq def (lookup-key map (vector event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;; Restore the match data while we process the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (store-match-data real-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (cond ((eq def 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (with-output-to-temp-buffer (gettext "*Help*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (princ (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (format "Query replacing %s%s with %s.\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (if regexp-flag "regexp " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 from-string next-replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 query-replace-help)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (help-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ((eq def 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (setq keep-going nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (setq done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ((eq def 'backup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (if stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (let ((elt (car stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (goto-char (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (setq replaced (eq t (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (or replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (store-match-data (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq stack (cdr stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (message "No previous match")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (ding 'no-terminate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (sit-for 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ((eq def 'act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (or replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (replace-match next-replacement nocasify literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (setq done t replaced t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ((eq def 'act-and-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (or replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (replace-match next-replacement nocasify literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (setq keep-going nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (setq done t replaced t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ((eq def 'act-and-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (if (not replaced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (replace-match next-replacement nocasify literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (setq replaced t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ((eq def 'automatic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (or replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (replace-match next-replacement nocasify literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq done t query-flag nil replaced t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ((eq def 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (setq done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ((eq def 'recenter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (recenter nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ((eq def 'edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (store-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (prog1 (match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (save-excursion (recursive-edit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;; Before we make the replacement,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; decide whether the search string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;; can match again just after this match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (if regexp-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (setq match-again (looking-at search-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ((eq def 'delete-and-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (store-match-data (prog1 (match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (save-excursion (recursive-edit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (setq replaced t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; Note: we do not need to treat `exit-prefix'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; specially here, since we reread
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; any unrecognized character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (setq this-command 'mode-exited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (setq keep-going nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (setq unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (cons event unread-command-events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (setq done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; Record previous position for ^ when we move on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;; Change markers to numbers in the match data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;; since lots of markers slow down editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (setq stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (cons (cons (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (or replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 #'(lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (if (markerp elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (prog1 (marker-position elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (set-marker elt nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (match-data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (if replaced (setq replace-count (1+ replace-count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq lastrepl (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (or unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (message "Replaced %d occurrence%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 replace-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (if (= replace-count 1) "" "s")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (and keep-going stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 ; FSF 19.30 original:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ; (defun match-string (num &optional string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ; "Return string of text matched by last search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ; NUM specifies which parenthesized expression in the last regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ; Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ; Zero means the entire text matched by the whole regexp or whole string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ; STRING should be given if the last search was by `string-match' on STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ; (if (match-beginning num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ; (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ; (substring string (match-beginning num) (match-end num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 ; (buffer-substring (match-beginning num) (match-end num)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 ;; #### - this could stand to be in C...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (defmacro match-string (n &optional string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 "Returns the Nth subexpression matched by the last regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 search. The second argument, STRING, must be specified if the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 regular expression search was done with `string-match'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;; #### - note that match-beginning is byte coded, so it's more efficient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;; to just call it twice than it is to let-bind its return value... --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 `(and (match-beginning ,n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ,(if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 `(substring ,string (match-beginning ,n) (match-end ,n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 `(buffer-substring (match-beginning ,n) (match-end ,n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (defmacro save-match-data (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 "Execute BODY forms, restoring the global value of the match data."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (let ((original (make-symbol "match-data")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (list 'let (list (list original '(match-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (list 'unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (list 'store-match-data original)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;;; replace.el ends here