428
|
1 ;;; replace.el --- search and replace commands for XEmacs.
|
|
2
|
1476
|
3 ;; Copyright (C) 1985-7, 1992, 1994, 1997, 2003 Free Software Foundation, Inc.
|
428
|
4
|
|
5 ;; Maintainer: XEmacs Development Team
|
|
6 ;; Keywords: dumped, matching
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: FSF 19.34 [Partially].
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file is dumped with XEmacs.
|
|
30
|
|
31 ;; This package supplies the string and regular-expression replace functions
|
|
32 ;; documented in the XEmacs Reference Manual.
|
|
33
|
|
34 ;; All the gettext calls are for XEmacs I18N3 message catalog support.
|
|
35 ;; (This is hopelessly broken and we should remove it. -sb)
|
|
36
|
|
37 ;;; Code:
|
|
38
|
|
39 (defvar case-replace t "\
|
|
40 *Non-nil means `query-replace' should preserve case in replacements.
|
|
41 What this means is that `query-replace' will change the case of the
|
|
42 replacement text so that it matches the text that was replaced.
|
|
43 If this variable is nil, the replacement text will be inserted
|
|
44 exactly as it was specified by the user, irrespective of the case
|
|
45 of the text that was replaced.
|
|
46
|
|
47 Note that this flag has no effect if `case-fold-search' is nil,
|
|
48 or if the replacement text has any uppercase letters in it.")
|
|
49
|
|
50 (defvar query-replace-history nil)
|
|
51
|
|
52 (defvar query-replace-interactive nil
|
|
53 "Non-nil means `query-replace' uses the last search string.
|
|
54 That becomes the \"string to replace\".")
|
|
55
|
|
56 (defvar replace-search-function
|
|
57 (lambda (str limit)
|
|
58 (search-forward str limit t))
|
444
|
59 "Function used by perform-replace to search forward for a string. It will be
|
428
|
60 called with two arguments: the string to search for and a limit bounding the
|
|
61 search.")
|
|
62
|
|
63 (defvar replace-re-search-function
|
|
64 (lambda (regexp limit)
|
|
65 (re-search-forward regexp limit t))
|
|
66 "Function used by perform-replace to search forward for a regular
|
|
67 expression. It will be called with two arguments: the regexp to search for and
|
|
68 a limit bounding the search.")
|
|
69
|
|
70 (defun query-replace-read-args (string regexp-flag)
|
|
71 (let (from to)
|
|
72 (if query-replace-interactive
|
|
73 (setq from (car (if regexp-flag regexp-search-ring search-ring)))
|
|
74 (setq from (read-from-minibuffer (format "%s: " (gettext string))
|
|
75 nil nil nil
|
|
76 'query-replace-history)))
|
|
77 (setq to (read-from-minibuffer (format "%s %s with: " (gettext string)
|
|
78 from)
|
|
79 nil nil nil
|
|
80 'query-replace-history))
|
|
81 (list from to current-prefix-arg)))
|
|
82
|
|
83 ;; As per suggestion from Per Abrahamsen, limit replacement to the region
|
|
84 ;; if the region is active.
|
|
85 (defun query-replace (from-string to-string &optional delimited)
|
|
86 "Replace some occurrences of FROM-STRING with TO-STRING.
|
|
87 As each match is found, the user must type a character saying
|
|
88 what to do with it. For directions, type \\[help-command] at that time.
|
|
89
|
|
90 If `query-replace-interactive' is non-nil, the last incremental search
|
|
91 string is used as FROM-STRING--you don't have to specify it with the
|
|
92 minibuffer.
|
|
93
|
|
94 Preserves case in each replacement if `case-replace' and `case-fold-search'
|
|
95 are non-nil and FROM-STRING has no uppercase letters.
|
|
96 \(Preserving case means that if the string matched is all caps, or capitalized,
|
|
97 then its replacement is upcased or capitalized.)
|
|
98
|
|
99 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
|
|
100 only matches surrounded by word boundaries.
|
|
101
|
|
102 To customize possible responses, change the \"bindings\" in `query-replace-map'."
|
|
103 (interactive (query-replace-read-args "Query replace" nil))
|
|
104 (perform-replace from-string to-string t nil delimited))
|
|
105
|
|
106 (defun query-replace-regexp (regexp to-string &optional delimited)
|
|
107 "Replace some things after point matching REGEXP with TO-STRING.
|
|
108 As each match is found, the user must type a character saying
|
|
109 what to do with it. For directions, type \\[help-command] at that time.
|
|
110
|
|
111 If `query-replace-interactive' is non-nil, the last incremental search
|
|
112 regexp is used as REGEXP--you don't have to specify it with the
|
|
113 minibuffer.
|
|
114
|
|
115 Preserves case in each replacement if `case-replace' and `case-fold-search'
|
|
116 are non-nil and REGEXP has no uppercase letters.
|
|
117 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
|
|
118 only matches surrounded by word boundaries.
|
|
119 In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
|
|
120 and `\\=\\N' (where N is a digit) stands for
|
|
121 whatever what matched the Nth `\\(...\\)' in REGEXP."
|
|
122 (interactive (query-replace-read-args "Query replace regexp" t))
|
|
123 (perform-replace regexp to-string t t delimited))
|
|
124
|
|
125 ;;#### Not patently useful
|
|
126 (defun map-query-replace-regexp (regexp to-strings &optional arg)
|
|
127 "Replace some matches for REGEXP with various strings, in rotation.
|
|
128 The second argument TO-STRINGS contains the replacement strings, separated
|
|
129 by spaces. This command works like `query-replace-regexp' except
|
|
130 that each successive replacement uses the next successive replacement string,
|
|
131 wrapping around from the last such string to the first.
|
|
132
|
|
133 Non-interactively, TO-STRINGS may be a list of replacement strings.
|
|
134
|
|
135 If `query-replace-interactive' is non-nil, the last incremental search
|
|
136 regexp is used as REGEXP--you don't have to specify it with the minibuffer.
|
|
137
|
|
138 A prefix argument N says to use each replacement string N times
|
|
139 before rotating to the next."
|
|
140 (interactive
|
|
141 (let (from to)
|
|
142 (setq from (if query-replace-interactive
|
|
143 (car regexp-search-ring)
|
|
144 (read-from-minibuffer "Map query replace (regexp): "
|
|
145 nil nil nil
|
|
146 'query-replace-history)))
|
|
147 (setq to (read-from-minibuffer
|
|
148 (format "Query replace %s with (space-separated strings): "
|
|
149 from)
|
|
150 nil nil nil
|
|
151 'query-replace-history))
|
|
152 (list from to current-prefix-arg)))
|
|
153 (let (replacements)
|
|
154 (if (listp to-strings)
|
|
155 (setq replacements to-strings)
|
|
156 (while (/= (length to-strings) 0)
|
|
157 (if (string-match " " to-strings)
|
|
158 (setq replacements
|
|
159 (append replacements
|
|
160 (list (substring to-strings 0
|
|
161 (string-match " " to-strings))))
|
|
162 to-strings (substring to-strings
|
|
163 (1+ (string-match " " to-strings))))
|
|
164 (setq replacements (append replacements (list to-strings))
|
|
165 to-strings ""))))
|
|
166 (perform-replace regexp replacements t t nil arg)))
|
|
167
|
|
168 (defun replace-string (from-string to-string &optional delimited)
|
|
169 "Replace occurrences of FROM-STRING with TO-STRING.
|
|
170 Preserve case in each match if `case-replace' and `case-fold-search'
|
|
171 are non-nil and FROM-STRING has no uppercase letters.
|
|
172 \(Preserving case means that if the string matched is all caps, or capitalized,
|
|
173 then its replacement is upcased or capitalized.)
|
|
174
|
|
175 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
|
|
176 only matches surrounded by word boundaries.
|
|
177
|
|
178 If `query-replace-interactive' is non-nil, the last incremental search
|
|
179 string is used as FROM-STRING--you don't have to specify it with the
|
|
180 minibuffer.
|
|
181
|
|
182 This function is usually the wrong thing to use in a Lisp program.
|
|
183 What you probably want is a loop like this:
|
|
184 (while (search-forward FROM-STRING nil t)
|
|
185 (replace-match TO-STRING nil t))
|
|
186 which will run faster and will not set the mark or print anything."
|
|
187 (interactive (query-replace-read-args "Replace string" nil))
|
|
188 (perform-replace from-string to-string nil nil delimited))
|
|
189
|
|
190 (defun replace-regexp (regexp to-string &optional delimited)
|
|
191 "Replace things after point matching REGEXP with TO-STRING.
|
|
192 Preserve case in each match if `case-replace' and `case-fold-search'
|
|
193 are non-nil and REGEXP has no uppercase letters.
|
|
194 \(Preserving case means that if the string matched is all caps, or capitalized,
|
|
195 then its replacement is upcased or capitalized.)
|
|
196
|
|
197 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
|
|
198 only matches surrounded by word boundaries.
|
|
199 In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
|
|
200 and `\\=\\N' (where N is a digit) stands for
|
|
201 whatever what matched the Nth `\\(...\\)' in REGEXP.
|
|
202
|
|
203 If `query-replace-interactive' is non-nil, the last incremental search
|
|
204 regexp is used as REGEXP--you don't have to specify it with the minibuffer.
|
|
205
|
|
206 This function is usually the wrong thing to use in a Lisp program.
|
|
207 What you probably want is a loop like this:
|
|
208 (while (re-search-forward REGEXP nil t)
|
|
209 (replace-match TO-STRING nil nil))
|
|
210 which will run faster and will not set the mark or print anything."
|
|
211 (interactive (query-replace-read-args "Replace regexp" t))
|
|
212 (perform-replace regexp to-string nil t delimited))
|
|
213
|
|
214
|
1069
|
215
|
|
216 ;; gse wonders: Is there a better place for this to go? Might other packages
|
|
217 ;; want to use it?
|
428
|
218 (defvar regexp-history nil
|
|
219 "History list for some commands that read regular expressions.")
|
|
220
|
1069
|
221 (defun operate-on-non-matching-lines (regexp delete kill &optional beg end)
|
|
222 "Internal function used by delete-non-matching-lines,
|
|
223 kill-non-matching-lines, and copy-matching-lines.
|
|
224
|
|
225 REGEXP is a regular expression to *not* match when performing
|
|
226 operations.
|
|
227
|
|
228 If DELETE is non-nil, the lines of text are deleted. It doesn't make
|
|
229 sense to set this to nil if KILL is nil -- nothing will happen.
|
|
230
|
|
231 If KILL is non-nil, the lines of text are stored in the kill ring (as
|
|
232 one block of text).
|
|
233
|
|
234 BEG and END, if non-nil, specify the start and end locations to work
|
|
235 within. If these are nil, point and point-max are used.
|
|
236
|
|
237 A match split across lines preserves all the lines it lies in.
|
|
238 Applies to all lines after point.
|
|
239
|
|
240 Returns the number of lines matched."
|
|
241 (with-search-caps-disable-folding regexp t
|
|
242 (save-excursion
|
|
243 ;; Move to a beginning point if specified.
|
|
244 (when beg (goto-char beg))
|
|
245 ;; Always start on the beginning of a line.
|
|
246 (or (bolp) (forward-line 1))
|
|
247
|
|
248 (let ((matched-text nil)
|
|
249 (curmatch-start (point))
|
2610
|
250 (limit (copy-marker (point-max)))
|
|
251 (matched-text-buffer (generate-new-buffer " *matched-text*"))
|
|
252 lines-matched)
|
1069
|
253 ;; Limit search if limits were specified.
|
|
254 (when end (setq limit (copy-marker end)))
|
|
255
|
|
256 ;; Search. Stop if we are at end of buffer or outside the
|
|
257 ;; limit.
|
|
258 (while (not (or
|
|
259 (eobp)
|
|
260 (and limit (>= (point) limit))))
|
|
261 ;; curmatch-start is first char not preserved by previous match.
|
|
262 (if (not (re-search-forward regexp limit 'move))
|
|
263 (let ((curmatch-end limit))
|
2610
|
264 (append-to-buffer matched-text-buffer curmatch-start curmatch-end)
|
1069
|
265 (if delete (delete-region curmatch-start curmatch-end)))
|
|
266 (let ((curmatch-end (save-excursion (goto-char (match-beginning 0))
|
2610
|
267 (beginning-of-line)
|
|
268 (point))))
|
1069
|
269 ;; Now curmatch-end is first char preserved by the new match.
|
|
270 (if (< curmatch-start curmatch-end)
|
|
271 (progn
|
2610
|
272 (append-to-buffer matched-text-buffer curmatch-start curmatch-end)
|
1069
|
273 (if delete (delete-region curmatch-start curmatch-end))))))
|
|
274 (setq curmatch-start (save-excursion (forward-line 1)
|
2610
|
275 (point)))
|
1069
|
276 ;; If the match was empty, avoid matching again at same place.
|
|
277 (and (not (eobp)) (= (match-beginning 0) (match-end 0))
|
|
278 (forward-char 1)))
|
|
279
|
|
280 ;; If any lines were matched and KILL is non-nil, insert the
|
|
281 ;; matched lines into the kill ring.
|
2610
|
282 (setq matched-text (buffer-string matched-text-buffer))
|
1069
|
283 (if (and matched-text kill) (kill-new matched-text))
|
|
284
|
|
285 ;; Return the number of matched lines.
|
2610
|
286 (setq lines-matched
|
|
287 (with-current-buffer matched-text-buffer
|
|
288 (count-lines (point-min) (point-max))))
|
|
289 (kill-buffer matched-text-buffer)
|
|
290 lines-matched))))
|
1069
|
291
|
428
|
292 (define-function 'keep-lines 'delete-non-matching-lines)
|
|
293 (defun delete-non-matching-lines (regexp)
|
1069
|
294 "Delete lines that do not match REGEXP, from point to the end of the
|
|
295 buffer (or within the region, if it is active)."
|
428
|
296 (interactive (list (read-from-minibuffer
|
|
297 "Keep lines (containing match for regexp): "
|
|
298 nil nil nil 'regexp-history)))
|
1069
|
299 (let ((beg nil)
|
|
300 (end nil)
|
|
301 (count nil))
|
|
302 (when (region-active-p)
|
|
303 (setq beg (region-beginning))
|
|
304 (setq end (region-end)))
|
|
305 (setq count (operate-on-non-matching-lines regexp t nil beg end))
|
1476
|
306 (when (interactive-p)
|
|
307 (message "%i lines deleted" count))))
|
1069
|
308
|
|
309 (defun kill-non-matching-lines (regexp)
|
|
310 "Delete the lines that do not match REGEXP, from point to the end of
|
|
311 the buffer (or within the region, if it is active). The deleted lines
|
|
312 are placed in the kill ring as one block of text."
|
|
313 (interactive (list (read-from-minibuffer
|
|
314 "Kill non-matching lines (regexp): "
|
|
315 nil nil nil 'regexp-history)))
|
|
316 (let ((beg nil)
|
|
317 (end nil)
|
|
318 (count nil))
|
|
319 (when (region-active-p)
|
|
320 (setq beg (region-beginning))
|
|
321 (setq end (region-end)))
|
|
322 (setq count (operate-on-non-matching-lines regexp t t beg end))
|
1476
|
323 (when (interactive-p)
|
|
324 (message "%i lines killed" count))))
|
1069
|
325
|
|
326 (defun copy-non-matching-lines (regexp)
|
|
327 "Find all lines that do not match REGEXP from point to the end of the
|
|
328 buffer (or within the region, if it is active), and place them in the
|
|
329 kill ring as one block of text."
|
|
330 (interactive (list (read-from-minibuffer
|
|
331 "Copy non-matching lines (regexp): "
|
|
332 nil nil nil 'regexp-history)))
|
|
333 (let ((beg nil)
|
|
334 (end nil)
|
|
335 (count nil))
|
|
336 (when (region-active-p)
|
|
337 (setq beg (region-beginning))
|
|
338 (setq end (region-end)))
|
|
339 (setq count (operate-on-non-matching-lines regexp nil t beg end))
|
1476
|
340 (when (interactive-p)
|
|
341 (message "%i lines copied" count))))
|
1069
|
342
|
|
343 (defun operate-on-matching-lines (regexp delete kill &optional beg end)
|
|
344 "Internal function used by delete-matching-lines, kill-matching-lines,
|
|
345 and copy-matching-lines.
|
|
346
|
|
347 If DELETE is non-nil, the lines of text are deleted. It doesn't make
|
|
348 sense to set this to nil if KILL is nil -- nothing will happen.
|
|
349
|
|
350 If KILL is non-nil, the lines of text are stored in the kill ring (as
|
|
351 one block of text).
|
|
352
|
|
353 BEG and END, if non-nil, specify the start and end locations to work
|
|
354 within. If these are nil, point and point-max are used.
|
|
355
|
|
356 If a match is split across lines, all the lines it lies in are deleted.
|
|
357 Applies to lines after point.
|
|
358 Returns the number of lines matched."
|
|
359 (with-search-caps-disable-folding regexp t
|
428
|
360 (save-excursion
|
1069
|
361 (let ((matched-text nil)
|
|
362 (curmatch-start nil)
|
|
363 (curmatch-end nil)
|
2610
|
364 (limit nil)
|
|
365 (matched-text-buffer (generate-new-buffer " *matched-text*"))
|
|
366 lines-matched)
|
1069
|
367 ;; Limit search if limits were specified.
|
|
368 (when beg (goto-char beg))
|
|
369 (when end (setq limit (copy-marker end)))
|
|
370
|
|
371 (while (and (not (eobp))
|
|
372 (re-search-forward regexp limit t))
|
|
373 (setq curmatch-start (save-excursion (goto-char (match-beginning 0))
|
|
374 (beginning-of-line)
|
|
375 (point)))
|
|
376 (setq curmatch-end (progn (forward-line 1) (point)))
|
2610
|
377 (append-to-buffer matched-text-buffer curmatch-start curmatch-end)
|
1069
|
378 (if delete (delete-region curmatch-start curmatch-end)))
|
2610
|
379 (setq matched-text (buffer-string matched-text-buffer))
|
1069
|
380 (if (and matched-text kill) (kill-new matched-text))
|
|
381
|
|
382 ;; Return the number of matched lines.
|
2610
|
383 (setq lines-matched
|
|
384 (with-current-buffer matched-text-buffer
|
|
385 (count-lines (point-min) (point-max))))
|
|
386 (kill-buffer matched-text-buffer)
|
|
387 lines-matched))))
|
428
|
388
|
|
389 (define-function 'flush-lines 'delete-matching-lines)
|
|
390 (defun delete-matching-lines (regexp)
|
1069
|
391 "Delete the lines that match REGEXP, from point to the end of the
|
|
392 buffer (or within the region, if it is active)."
|
428
|
393 (interactive (list (read-from-minibuffer
|
|
394 "Flush lines (containing match for regexp): "
|
|
395 nil nil nil 'regexp-history)))
|
1069
|
396 (let ((beg nil)
|
|
397 (end nil)
|
|
398 (count nil))
|
|
399 (when (region-active-p)
|
|
400 (setq beg (region-beginning))
|
|
401 (setq end (region-end)))
|
|
402 (setq count (operate-on-matching-lines regexp t nil beg end))
|
1476
|
403 (when (interactive-p)
|
|
404 (message "%i lines deleted" count))))
|
1069
|
405
|
|
406 (defun kill-matching-lines (regexp)
|
|
407 "Delete the lines that match REGEXP, from point to the end of the
|
|
408 buffer (or within the region, if it is active). The deleted lines are
|
|
409 placed in the kill ring as one block of text."
|
|
410 (interactive (list (read-from-minibuffer
|
|
411 "Kill lines (containing match for regexp): "
|
|
412 nil nil nil 'regexp-history)))
|
|
413 (let ((beg nil)
|
|
414 (end nil)
|
|
415 (count nil))
|
|
416 (when (region-active-p)
|
|
417 (setq beg (region-beginning))
|
|
418 (setq end (region-end)))
|
|
419 (setq count (operate-on-matching-lines regexp t t beg end))
|
1476
|
420 (when (interactive-p)
|
|
421 (message "%i lines killed" count))))
|
1069
|
422
|
|
423 (defun copy-matching-lines (regexp)
|
|
424 "Find all lines that match REGEXP from point to the end of the
|
|
425 buffer (or within the region, if it is active), and place them in the
|
|
426 kill ring as one block of text."
|
|
427 (interactive (list (read-from-minibuffer
|
|
428 "Copy lines (containing match for regexp): "
|
|
429 nil nil nil 'regexp-history)))
|
|
430 (let ((beg nil)
|
|
431 (end nil)
|
|
432 (count nil))
|
|
433 (when (region-active-p)
|
|
434 (setq beg (region-beginning))
|
|
435 (setq end (region-end)))
|
|
436 (setq count (operate-on-matching-lines regexp nil t beg end))
|
1476
|
437 (when (interactive-p)
|
|
438 (message "%i lines copied" count))))
|
428
|
439
|
|
440 (define-function 'how-many 'count-matches)
|
|
441 (defun count-matches (regexp)
|
|
442 "Print number of matches for REGEXP following point."
|
|
443 (interactive (list (read-from-minibuffer
|
|
444 "How many matches for (regexp): "
|
|
445 nil nil nil 'regexp-history)))
|
|
446 (with-interactive-search-caps-disable-folding regexp t
|
|
447 (let ((count 0) opoint)
|
|
448 (save-excursion
|
|
449 (while (and (not (eobp))
|
|
450 (progn (setq opoint (point))
|
|
451 (re-search-forward regexp nil t)))
|
|
452 (if (= opoint (point))
|
|
453 (forward-char 1)
|
|
454 (setq count (1+ count))))
|
|
455 (message "%d occurrences" count)))))
|
|
456
|
|
457
|
|
458 (defvar occur-mode-map ())
|
|
459 (if occur-mode-map
|
|
460 ()
|
|
461 (setq occur-mode-map (make-sparse-keymap))
|
|
462 (set-keymap-name occur-mode-map 'occur-mode-map) ; XEmacs
|
|
463 (define-key occur-mode-map 'button2 'occur-mode-mouse-goto) ; XEmacs
|
|
464 (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
|
|
465 (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence))
|
|
466
|
|
467 (defvar occur-buffer nil)
|
|
468 (defvar occur-nlines nil)
|
|
469 (defvar occur-pos-list nil)
|
|
470
|
|
471 (defun occur-mode ()
|
|
472 "Major mode for output from \\[occur].
|
|
473 \\<occur-mode-map>Move point to one of the items in this buffer, then use
|
|
474 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
|
|
475 Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
|
|
476
|
|
477 \\{occur-mode-map}"
|
|
478 (kill-all-local-variables)
|
|
479 (use-local-map occur-mode-map)
|
|
480 (setq major-mode 'occur-mode)
|
|
481 (setq mode-name (gettext "Occur")) ; XEmacs
|
|
482 (make-local-variable 'occur-buffer)
|
|
483 (make-local-variable 'occur-nlines)
|
|
484 (make-local-variable 'occur-pos-list)
|
|
485 (require 'mode-motion) ; XEmacs
|
|
486 (setq mode-motion-hook 'mode-motion-highlight-line) ; XEmacs
|
|
487 (run-hooks 'occur-mode-hook))
|
|
488
|
|
489 ;; FSF Version of next function:
|
|
490 ; (let (buffer pos)
|
|
491 ; (save-excursion
|
|
492 ; (set-buffer (window-buffer (posn-window (event-end event))))
|
|
493 ; (save-excursion
|
|
494 ; (goto-char (posn-point (event-end event)))
|
|
495 ; (setq pos (occur-mode-find-occurrence))
|
|
496 ; (setq buffer occur-buffer)))
|
|
497 ; (pop-to-buffer buffer)
|
|
498 ; (goto-char (marker-position pos))))
|
|
499
|
|
500 (defun occur-mode-mouse-goto (event)
|
|
501 "Go to the occurrence highlighted by mouse.
|
444
|
502 This function should be bound to a mouse key in the `*Occur*' buffer."
|
428
|
503 (interactive "e")
|
|
504 (let ((window-save (selected-window))
|
|
505 (frame-save (selected-frame)))
|
|
506 ;; preserve the window/frame setup
|
|
507 (unwind-protect
|
|
508 (progn
|
|
509 (mouse-set-point event)
|
|
510 (occur-mode-goto-occurrence))
|
|
511 (select-frame frame-save)
|
|
512 (select-window window-save))))
|
|
513
|
|
514 ;; Called occur-mode-find-occurrence in FSF
|
|
515 (defun occur-mode-goto-occurrence ()
|
|
516 "Go to the occurrence the current line describes."
|
|
517 (interactive)
|
|
518 (if (or (null occur-buffer)
|
|
519 (null (buffer-name occur-buffer)))
|
|
520 (progn
|
|
521 (setq occur-buffer nil
|
|
522 occur-pos-list nil)
|
|
523 (error "Buffer in which occurrences were found is deleted")))
|
|
524 (let* ((line-count
|
|
525 (count-lines (point-min)
|
|
526 (save-excursion
|
|
527 (beginning-of-line)
|
|
528 (point))))
|
|
529 (occur-number (save-excursion
|
|
530 (beginning-of-line)
|
|
531 (/ (1- line-count)
|
|
532 (cond ((< occur-nlines 0)
|
|
533 (- 2 occur-nlines))
|
|
534 ((> occur-nlines 0)
|
|
535 (+ 2 (* 2 occur-nlines)))
|
|
536 (t 1)))))
|
|
537 (pos (nth occur-number occur-pos-list))
|
|
538 ;; removed t arg from Bob Weiner, 10/6/95
|
|
539 (window (get-buffer-window occur-buffer))
|
|
540 (occur-source-buffer occur-buffer))
|
|
541 (if (< line-count 1)
|
|
542 (error "No occurrence on this line"))
|
|
543 (or pos
|
|
544 (error "No occurrence on this line"))
|
|
545 ;; XEmacs: don't raise window unless it isn't visible
|
|
546 ;; allow for the possibility that the occur buffer is on another frame
|
|
547 (or (and window
|
|
548 (window-live-p window)
|
|
549 (frame-visible-p (window-frame window))
|
|
550 (set-buffer occur-source-buffer))
|
|
551 (and (pop-to-buffer occur-source-buffer)
|
|
552 (setq window (get-buffer-window occur-source-buffer))))
|
|
553 (goto-char pos)
|
|
554 (set-window-point window pos)))
|
|
555
|
|
556
|
|
557 (defvar list-matching-lines-default-context-lines 0
|
|
558 "*Default number of context lines to include around a `list-matching-lines'
|
|
559 match. A negative number means to include that many lines before the match.
|
|
560 A positive number means to include that many lines both before and after.")
|
|
561
|
|
562 ;; XEmacs addition
|
|
563 ;;; Damn you Jamie, this is utter trash.
|
|
564 (defvar list-matching-lines-whole-buffer t
|
|
565 "If t, occur operates on whole buffer, otherwise occur starts from point.
|
|
566 default is t.")
|
|
567
|
|
568 (define-function 'occur 'list-matching-lines)
|
|
569 (defun list-matching-lines (regexp &optional nlines)
|
|
570 "Show all lines in the current buffer containing a match for REGEXP.
|
|
571
|
|
572 If a match spreads across multiple lines, all those lines are shown.
|
|
573
|
448
|
574 If variable `list-matching-lines-whole-buffer' is non-nil, the entire
|
|
575 buffer is searched, otherwise search begins at point.
|
428
|
576
|
|
577 Each line is displayed with NLINES lines before and after, or -NLINES
|
|
578 before if NLINES is negative.
|
|
579 NLINES defaults to `list-matching-lines-default-context-lines'.
|
|
580 Interactively it is the prefix arg.
|
|
581
|
|
582 The lines are shown in a buffer named `*Occur*'.
|
|
583 It serves as a menu to find any of the occurrences in this buffer.
|
|
584 \\[describe-mode] in that buffer will explain how."
|
|
585 (interactive
|
|
586 ;; XEmacs change
|
|
587 (list (let* ((default (or (symbol-near-point)
|
|
588 (and regexp-history
|
|
589 (car regexp-history))))
|
|
590 (minibuffer-history-minimum-string-length 0)
|
|
591 (input
|
|
592 (if default
|
|
593 ;; rewritten for I18N3 snarfing
|
|
594 (read-from-minibuffer
|
|
595 (format "List lines matching regexp (default `%s'): "
|
456
|
596 default) nil nil nil 'regexp-history nil
|
|
597 default)
|
428
|
598 (read-from-minibuffer
|
|
599 "List lines matching regexp: "
|
|
600 nil nil nil
|
|
601 'regexp-history))))
|
|
602 (if (and (equal input "") default)
|
|
603 (progn
|
|
604 (setq input default)
|
|
605 (setcar regexp-history default)))
|
|
606 ;; clear extra entries
|
|
607 (setcdr regexp-history (delete (car regexp-history)
|
|
608 (cdr regexp-history)))
|
|
609 input)
|
|
610 current-prefix-arg))
|
|
611 (if (equal regexp "")
|
|
612 (error "Must pass non-empty regexp to `list-matching-lines'"))
|
|
613 (setq nlines (if nlines (prefix-numeric-value nlines)
|
|
614 list-matching-lines-default-context-lines))
|
|
615 (let ((first t)
|
|
616 (dir default-directory)
|
|
617 (buffer (current-buffer))
|
|
618 (linenum 1)
|
|
619 (prevpos (point-min))
|
|
620 ;; The rest of this function is very different from FSF.
|
|
621 ;; Presumably that's due to Jamie's misfeature
|
|
622 (final-context-start (make-marker)))
|
|
623 (if (not list-matching-lines-whole-buffer)
|
|
624 (save-excursion
|
|
625 (beginning-of-line)
|
|
626 (setq linenum (1+ (count-lines (point-min) (point))))
|
|
627 (setq prevpos (point))))
|
|
628 (with-output-to-temp-buffer "*Occur*"
|
|
629 (save-excursion
|
|
630 (set-buffer standard-output)
|
|
631 (setq default-directory dir)
|
|
632 ;; We will insert the number of lines, and "lines", later.
|
|
633 ;; #### Needs fixing for I18N3
|
|
634 (let ((print-escape-newlines t))
|
|
635 (insert (format " matching %s in buffer %s.\n"
|
|
636 regexp (buffer-name buffer))))
|
|
637 (occur-mode)
|
|
638 (setq occur-buffer buffer)
|
|
639 (setq occur-nlines nlines)
|
|
640 (setq occur-pos-list ()))
|
|
641 (if (eq buffer standard-output)
|
|
642 (goto-char (point-max)))
|
|
643 (with-interactive-search-caps-disable-folding regexp t
|
|
644 (save-excursion
|
|
645 (if list-matching-lines-whole-buffer
|
|
646 (beginning-of-buffer))
|
|
647 (message "Searching for %s ..." regexp)
|
|
648 ;; Find next match, but give up if prev match was at end of buffer.
|
|
649 (while (and (not (= prevpos (point-max)))
|
|
650 (re-search-forward regexp nil t))
|
|
651 (goto-char (match-beginning 0))
|
|
652 (beginning-of-line)
|
|
653 (save-match-data
|
|
654 (setq linenum (+ linenum (count-lines prevpos (point)))))
|
|
655 (setq prevpos (point))
|
|
656 (goto-char (match-end 0))
|
|
657 (let* ((start (save-excursion
|
|
658 (goto-char (match-beginning 0))
|
|
659 (forward-line (if (< nlines 0) nlines (- nlines)))
|
|
660 (point)))
|
|
661 (end (save-excursion
|
|
662 (goto-char (match-end 0))
|
|
663 (if (> nlines 0)
|
|
664 (forward-line (1+ nlines))
|
|
665 (forward-line 1))
|
|
666 (point)))
|
|
667 (tag (format "%5d" linenum))
|
|
668 (empty (make-string (length tag) ?\ ))
|
|
669 tem)
|
|
670 (save-excursion
|
|
671 (setq tem (make-marker))
|
|
672 (set-marker tem (point))
|
|
673 (set-buffer standard-output)
|
|
674 (setq occur-pos-list (cons tem occur-pos-list))
|
|
675 (or first (zerop nlines)
|
|
676 (insert "--------\n"))
|
|
677 (setq first nil)
|
|
678 (insert-buffer-substring buffer start end)
|
444
|
679 (set-marker final-context-start
|
428
|
680 (- (point) (- end (match-end 0))))
|
|
681 (backward-char (- end start))
|
|
682 (setq tem (if (< nlines 0) (- nlines) nlines))
|
|
683 (while (> tem 0)
|
|
684 (insert empty ?:)
|
|
685 (forward-line 1)
|
|
686 (setq tem (1- tem)))
|
|
687 (let ((this-linenum linenum))
|
|
688 (while (< (point) final-context-start)
|
|
689 (if (null tag)
|
|
690 (setq tag (format "%5d" this-linenum)))
|
|
691 (insert tag ?:)
|
444
|
692 ;; FSFmacs --
|
428
|
693 ;; we handle this using mode-motion-highlight-line, above.
|
|
694 ;; (put-text-property (save-excursion
|
|
695 ;; (beginning-of-line)
|
|
696 ;; (point))
|
|
697 ;; (save-excursion
|
|
698 ;; (end-of-line)
|
|
699 ;; (point))
|
|
700 ;; 'mouse-face 'highlight)
|
|
701 (forward-line 1)
|
|
702 (setq tag nil)
|
|
703 (setq this-linenum (1+ this-linenum)))
|
|
704 (while (<= (point) final-context-start)
|
|
705 (insert empty ?:)
|
|
706 (forward-line 1)
|
|
707 (setq this-linenum (1+ this-linenum))))
|
|
708 (while (< tem nlines)
|
|
709 (insert empty ?:)
|
|
710 (forward-line 1)
|
|
711 (setq tem (1+ tem)))
|
|
712 (goto-char (point-max)))
|
|
713 (forward-line 1)))
|
|
714 (set-buffer standard-output)
|
|
715 ;; Put positions in increasing order to go with buffer.
|
|
716 (setq occur-pos-list (nreverse occur-pos-list))
|
|
717 (goto-char (point-min))
|
|
718 (if (= (length occur-pos-list) 1)
|
|
719 (insert "1 line")
|
|
720 (insert (format "%d lines" (length occur-pos-list))))
|
|
721 (if (interactive-p)
|
|
722 (message "%d matching lines." (length occur-pos-list))))))))
|
|
723
|
|
724 ;; It would be nice to use \\[...], but there is no reasonable way
|
|
725 ;; to make that display both SPC and Y.
|
|
726 (defconst query-replace-help
|
444
|
727 "Type Space or `y' to replace one match, Delete or `n' to skip to next,
|
428
|
728 RET or `q' to exit, Period to replace one match and exit,
|
|
729 Comma to replace but not move point immediately,
|
|
730 C-r to enter recursive edit (\\[exit-recursive-edit] to get out again),
|
|
731 C-w to delete match and recursive edit,
|
|
732 C-l to clear the frame, redisplay, and offer same replacement again,
|
|
733 ! to replace all remaining matches with no more questions,
|
|
734 ^ to move point back to previous match."
|
444
|
735
|
428
|
736 "Help message while in query-replace")
|
|
737
|
|
738 (defvar query-replace-map nil
|
|
739 "Keymap that defines the responses to questions in `query-replace'.
|
|
740 The \"bindings\" in this map are not commands; they are answers.
|
|
741 The valid answers include `act', `skip', `act-and-show',
|
|
742 `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
|
|
743 `automatic', `backup', `exit-prefix', and `help'.")
|
|
744
|
|
745 ;; Why does it seem that ever file has a different method of doing this?
|
|
746 (if query-replace-map
|
|
747 nil
|
|
748 (let ((map (make-sparse-keymap)))
|
|
749 (set-keymap-name map 'query-replace-map)
|
|
750 (define-key map " " 'act)
|
|
751 (define-key map "\d" 'skip)
|
|
752 (define-key map [delete] 'skip)
|
|
753 (define-key map [backspace] 'skip)
|
|
754 (define-key map "y" 'act)
|
|
755 (define-key map "n" 'skip)
|
|
756 (define-key map "Y" 'act)
|
|
757 (define-key map "N" 'skip)
|
|
758 (define-key map "," 'act-and-show)
|
|
759 (define-key map [escape] 'exit)
|
|
760 (define-key map "q" 'exit)
|
|
761 (define-key map [return] 'exit)
|
|
762 (define-key map "." 'act-and-exit)
|
|
763 (define-key map "\C-r" 'edit)
|
|
764 (define-key map "\C-w" 'delete-and-edit)
|
|
765 (define-key map "\C-l" 'recenter)
|
|
766 (define-key map "!" 'automatic)
|
|
767 (define-key map "^" 'backup)
|
|
768 (define-key map [(control h)] 'help) ;; XEmacs change
|
|
769 (define-key map [f1] 'help)
|
|
770 (define-key map [help] 'help)
|
|
771 (define-key map "?" 'help)
|
|
772 (define-key map "\C-g" 'quit)
|
|
773 (define-key map "\C-]" 'quit)
|
|
774 ;FSFmacs (define-key map "\e" 'exit-prefix)
|
|
775 (define-key map [escape] 'exit-prefix)
|
444
|
776
|
428
|
777 (setq query-replace-map map)))
|
|
778
|
|
779 ;; isearch-mode is dumped, so don't autoload.
|
|
780 ;(autoload 'isearch-highlight "isearch")
|
|
781
|
|
782 ;; XEmacs
|
|
783 (defun perform-replace-next-event (event)
|
442
|
784 (if search-highlight
|
428
|
785 (let ((aborted t))
|
|
786 (unwind-protect
|
|
787 (progn
|
|
788 (if (match-beginning 0)
|
|
789 (isearch-highlight (match-beginning 0) (match-end 0)))
|
|
790 (next-command-event event)
|
|
791 (setq aborted nil))
|
|
792 (isearch-dehighlight aborted)))
|
|
793 (next-command-event event)))
|
|
794
|
|
795 (defun perform-replace (from-string replacements
|
|
796 query-flag regexp-flag delimited-flag
|
|
797 &optional repeat-count map)
|
|
798 "Subroutine of `query-replace'. Its complexity handles interactive queries.
|
|
799 Don't use this in your own program unless you want to query and set the mark
|
|
800 just as `query-replace' does. Instead, write a simple loop like this:
|
|
801 (while (re-search-forward \"foo[ \t]+bar\" nil t)
|
|
802 (replace-match \"foobar\" nil nil))
|
|
803 which will run faster and probably do exactly what you want.
|
444
|
804 When searching for a match, this function uses
|
|
805 `replace-search-function' and `replace-re-search-function'."
|
428
|
806 (or map (setq map query-replace-map))
|
|
807 (let* ((event (make-event))
|
|
808 (nocasify (not (and case-fold-search case-replace
|
|
809 (string-equal from-string
|
|
810 (downcase from-string)))))
|
|
811 (literal (not regexp-flag))
|
444
|
812 (search-function (if regexp-flag
|
|
813 replace-re-search-function
|
428
|
814 replace-search-function))
|
|
815 (search-string from-string)
|
|
816 (real-match-data nil) ; the match data for the current match
|
|
817 (next-replacement nil)
|
|
818 (replacement-index 0)
|
|
819 (keep-going t)
|
|
820 (stack nil)
|
|
821 (next-rotate-count 0)
|
|
822 (replace-count 0)
|
|
823 (lastrepl nil) ;Position after last match considered.
|
|
824 ;; If non-nil, it is marker saying where in the buffer to
|
|
825 ;; stop.
|
|
826 (limit nil)
|
|
827 (match-again t)
|
|
828 ;; XEmacs addition
|
|
829 (qr-case-fold-search
|
|
830 (if (and case-fold-search search-caps-disable-folding)
|
|
831 (no-upper-case-p search-string regexp-flag)
|
|
832 case-fold-search))
|
|
833 (message
|
|
834 (if query-flag
|
|
835 (substitute-command-keys
|
|
836 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) "))))
|
|
837 ;; If the region is active, operate on region.
|
|
838 (when (region-active-p)
|
|
839 ;; Original Per Abrahamsen's code simply narrowed the region,
|
|
840 ;; thus providing a visual indication of the search boundary.
|
|
841 ;; Stallman, on the other hand, handles it like this.
|
|
842 (setq limit (copy-marker (region-end)))
|
|
843 (goto-char (region-beginning))
|
|
844 (zmacs-deactivate-region))
|
|
845 (if (stringp replacements)
|
|
846 (setq next-replacement replacements)
|
|
847 (or repeat-count (setq repeat-count 1)))
|
|
848 (if delimited-flag
|
|
849 (setq search-function replace-re-search-function
|
|
850 search-string (concat "\\b"
|
|
851 (if regexp-flag from-string
|
|
852 (regexp-quote from-string))
|
|
853 "\\b")))
|
|
854 (push-mark)
|
|
855 (undo-boundary)
|
|
856 (unwind-protect
|
|
857 ;; Loop finding occurrences that perhaps should be replaced.
|
|
858 (while (and keep-going
|
|
859 (not (eobp))
|
|
860 (or (null limit) (< (point) limit))
|
|
861 (let ((case-fold-search qr-case-fold-search))
|
|
862 (funcall search-function search-string limit))
|
|
863 ;; If the search string matches immediately after
|
|
864 ;; the previous match, but it did not match there
|
|
865 ;; before the replacement was done, ignore the match.
|
|
866 (if (or (eq lastrepl (point))
|
|
867 (and regexp-flag
|
|
868 (eq lastrepl (match-beginning 0))
|
|
869 (not match-again)))
|
|
870 (if (or (eobp)
|
|
871 (and limit (>= (point) limit)))
|
|
872 nil
|
444
|
873 ;; Don't replace the null string
|
428
|
874 ;; right after end of previous replacement.
|
|
875 (forward-char 1)
|
|
876 (let ((case-fold-search qr-case-fold-search))
|
|
877 (funcall search-function search-string limit)))
|
|
878 t))
|
|
879
|
|
880 ;; Save the data associated with the real match.
|
|
881 (setq real-match-data (match-data))
|
|
882
|
|
883 ;; Before we make the replacement, decide whether the search string
|
|
884 ;; can match again just after this match.
|
|
885 (if regexp-flag
|
444
|
886 (progn
|
428
|
887 (setq match-again (looking-at search-string))
|
|
888 ;; XEmacs addition
|
|
889 (store-match-data real-match-data)))
|
|
890 ;; If time for a change, advance to next replacement string.
|
|
891 (if (and (listp replacements)
|
|
892 (= next-rotate-count replace-count))
|
|
893 (progn
|
|
894 (setq next-rotate-count
|
|
895 (+ next-rotate-count repeat-count))
|
|
896 (setq next-replacement (nth replacement-index replacements))
|
|
897 (setq replacement-index (% (1+ replacement-index) (length replacements)))))
|
|
898 (if (not query-flag)
|
|
899 (progn
|
|
900 (store-match-data real-match-data)
|
|
901 (replace-match next-replacement nocasify literal)
|
|
902 (setq replace-count (1+ replace-count)))
|
|
903 (undo-boundary)
|
|
904 (let ((help-form
|
|
905 '(concat (format "Query replacing %s%s with %s.\n\n"
|
|
906 (if regexp-flag (gettext "regexp ") "")
|
|
907 from-string next-replacement)
|
|
908 (substitute-command-keys query-replace-help)))
|
|
909 done replaced def)
|
|
910 ;; Loop reading commands until one of them sets done,
|
|
911 ;; which means it has finished handling this occurrence.
|
|
912 (while (not done)
|
|
913 ;; Don't fill up the message log
|
|
914 ;; with a bunch of identical messages.
|
|
915 ;; XEmacs change
|
|
916 (display-message 'prompt
|
|
917 (format message from-string next-replacement))
|
|
918 (perform-replace-next-event event)
|
|
919 (setq def (lookup-key map (vector event)))
|
|
920 ;; Restore the match data while we process the command.
|
|
921 (store-match-data real-match-data)
|
|
922 (cond ((eq def 'help)
|
|
923 (with-output-to-temp-buffer (gettext "*Help*")
|
|
924 (princ (concat
|
|
925 (format "Query replacing %s%s with %s.\n\n"
|
|
926 (if regexp-flag "regexp " "")
|
|
927 from-string next-replacement)
|
|
928 (substitute-command-keys
|
|
929 query-replace-help)))
|
|
930 (save-excursion
|
|
931 (set-buffer standard-output)
|
|
932 (help-mode))))
|
|
933 ((eq def 'exit)
|
|
934 (setq keep-going nil)
|
|
935 (setq done t))
|
|
936 ((eq def 'backup)
|
|
937 (if stack
|
|
938 (let ((elt (car stack)))
|
|
939 (goto-char (car elt))
|
|
940 (setq replaced (eq t (cdr elt)))
|
|
941 (or replaced
|
|
942 (store-match-data (cdr elt)))
|
|
943 (setq stack (cdr stack)))
|
|
944 (message "No previous match")
|
|
945 (ding 'no-terminate)
|
|
946 (sit-for 1)))
|
|
947 ((eq def 'act)
|
|
948 (or replaced
|
|
949 (replace-match next-replacement nocasify literal))
|
|
950 (setq done t replaced t))
|
|
951 ((eq def 'act-and-exit)
|
|
952 (or replaced
|
|
953 (replace-match next-replacement nocasify literal))
|
|
954 (setq keep-going nil)
|
|
955 (setq done t replaced t))
|
|
956 ((eq def 'act-and-show)
|
|
957 (if (not replaced)
|
|
958 (progn
|
|
959 (replace-match next-replacement nocasify literal)
|
|
960 (store-match-data nil)
|
|
961 (setq replaced t))))
|
|
962 ((eq def 'automatic)
|
|
963 (or replaced
|
|
964 (replace-match next-replacement nocasify literal))
|
|
965 (setq done t query-flag nil replaced t))
|
|
966 ((eq def 'skip)
|
|
967 (setq done t))
|
|
968 ((eq def 'recenter)
|
|
969 (recenter nil))
|
|
970 ((eq def 'edit)
|
|
971 (store-match-data
|
|
972 (prog1 (match-data)
|
|
973 (save-excursion (recursive-edit))))
|
|
974 ;; Before we make the replacement,
|
|
975 ;; decide whether the search string
|
|
976 ;; can match again just after this match.
|
|
977 (if regexp-flag
|
|
978 (setq match-again (looking-at search-string))))
|
|
979 ((eq def 'delete-and-edit)
|
|
980 (delete-region (match-beginning 0) (match-end 0))
|
|
981 (store-match-data (prog1 (match-data)
|
|
982 (save-excursion (recursive-edit))))
|
|
983 (setq replaced t))
|
|
984 ;; Note: we do not need to treat `exit-prefix'
|
|
985 ;; specially here, since we reread
|
|
986 ;; any unrecognized character.
|
|
987 (t
|
|
988 (setq this-command 'mode-exited)
|
|
989 (setq keep-going nil)
|
|
990 (setq unread-command-events
|
|
991 (cons event unread-command-events))
|
|
992 (setq done t))))
|
|
993 ;; Record previous position for ^ when we move on.
|
|
994 ;; Change markers to numbers in the match data
|
|
995 ;; since lots of markers slow down editing.
|
|
996 (setq stack
|
|
997 (cons (cons (point)
|
|
998 (or replaced
|
|
999 (match-data t)))
|
|
1000 stack))
|
|
1001 (if replaced (setq replace-count (1+ replace-count)))))
|
|
1002 (setq lastrepl (point)))
|
|
1003 ;; Useless in XEmacs. We handle (de)highlighting through
|
|
1004 ;; perform-replace-next-event.
|
|
1005 ;(replace-dehighlight)
|
|
1006 )
|
|
1007 (or unread-command-events
|
|
1008 (message "Replaced %d occurrence%s"
|
|
1009 replace-count
|
|
1010 (if (= replace-count 1) "" "s")))
|
|
1011 (and keep-going stack)))
|
|
1012
|
|
1013 ;; FSFmacs code: someone should port it.
|
|
1014
|
|
1015 ;(defvar query-replace-highlight nil
|
|
1016 ; "*Non-nil means to highlight words during query replacement.")
|
|
1017
|
|
1018 ;(defvar replace-overlay nil)
|
|
1019
|
|
1020 ;(defun replace-dehighlight ()
|
|
1021 ; (and replace-overlay
|
|
1022 ; (progn
|
|
1023 ; (delete-overlay replace-overlay)
|
|
1024 ; (setq replace-overlay nil))))
|
|
1025
|
|
1026 ;(defun replace-highlight (start end)
|
|
1027 ; (and query-replace-highlight
|
|
1028 ; (progn
|
|
1029 ; (or replace-overlay
|
|
1030 ; (progn
|
|
1031 ; (setq replace-overlay (make-overlay start end))
|
|
1032 ; (overlay-put replace-overlay 'face
|
|
1033 ; (if (internal-find-face 'query-replace)
|
|
1034 ; 'query-replace 'region))))
|
|
1035 ; (move-overlay replace-overlay start end (current-buffer)))))
|
|
1036
|
|
1037 ;;; replace.el ends here
|