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))
+ − 250 (limit (copy-marker (point-max))))
+ − 251 ;; Limit search if limits were specified.
+ − 252 (when end (setq limit (copy-marker end)))
+ − 253
+ − 254 ;; Search. Stop if we are at end of buffer or outside the
+ − 255 ;; limit.
+ − 256 (while (not (or
+ − 257 (eobp)
+ − 258 (and limit (>= (point) limit))))
+ − 259 ;; curmatch-start is first char not preserved by previous match.
+ − 260 (if (not (re-search-forward regexp limit 'move))
+ − 261 (let ((curmatch-end limit))
+ − 262 (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end)))
+ − 263 (if delete (delete-region curmatch-start curmatch-end)))
+ − 264 (let ((curmatch-end (save-excursion (goto-char (match-beginning 0))
+ − 265 (beginning-of-line)
+ − 266 (point))))
+ − 267 ;; Now curmatch-end is first char preserved by the new match.
+ − 268 (if (< curmatch-start curmatch-end)
+ − 269 (progn
+ − 270 (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end)))
+ − 271 (if delete (delete-region curmatch-start curmatch-end))))))
+ − 272 (setq curmatch-start (save-excursion (forward-line 1)
+ − 273 (point)))
+ − 274 ;; If the match was empty, avoid matching again at same place.
+ − 275 (and (not (eobp)) (= (match-beginning 0) (match-end 0))
+ − 276 (forward-char 1)))
+ − 277
+ − 278 ;; If any lines were matched and KILL is non-nil, insert the
+ − 279 ;; matched lines into the kill ring.
+ − 280 (if (and matched-text kill) (kill-new matched-text))
+ − 281
+ − 282 ;; Return the number of matched lines.
+ − 283 (with-temp-buffer
+ − 284 ;; Use concat to make a string even if matched-text is nil.
+ − 285 (insert (concat matched-text))
+ − 286 (count-lines (point-min) (point-max)))
+ − 287 ))))
+ − 288
428
+ − 289 (define-function 'keep-lines 'delete-non-matching-lines)
+ − 290 (defun delete-non-matching-lines (regexp)
1069
+ − 291 "Delete lines that do not match REGEXP, from point to the end of the
+ − 292 buffer (or within the region, if it is active)."
428
+ − 293 (interactive (list (read-from-minibuffer
+ − 294 "Keep lines (containing match for regexp): "
+ − 295 nil nil nil 'regexp-history)))
1069
+ − 296 (let ((beg nil)
+ − 297 (end nil)
+ − 298 (count nil))
+ − 299 (when (region-active-p)
+ − 300 (setq beg (region-beginning))
+ − 301 (setq end (region-end)))
+ − 302 (setq count (operate-on-non-matching-lines regexp t nil beg end))
1476
+ − 303 (when (interactive-p)
+ − 304 (message "%i lines deleted" count))))
1069
+ − 305
+ − 306 (defun kill-non-matching-lines (regexp)
+ − 307 "Delete the lines that do not match REGEXP, from point to the end of
+ − 308 the buffer (or within the region, if it is active). The deleted lines
+ − 309 are placed in the kill ring as one block of text."
+ − 310 (interactive (list (read-from-minibuffer
+ − 311 "Kill non-matching lines (regexp): "
+ − 312 nil nil nil 'regexp-history)))
+ − 313 (let ((beg nil)
+ − 314 (end nil)
+ − 315 (count nil))
+ − 316 (when (region-active-p)
+ − 317 (setq beg (region-beginning))
+ − 318 (setq end (region-end)))
+ − 319 (setq count (operate-on-non-matching-lines regexp t t beg end))
1476
+ − 320 (when (interactive-p)
+ − 321 (message "%i lines killed" count))))
1069
+ − 322
+ − 323 (defun copy-non-matching-lines (regexp)
+ − 324 "Find all lines that do not match REGEXP from point to the end of the
+ − 325 buffer (or within the region, if it is active), and place them in the
+ − 326 kill ring as one block of text."
+ − 327 (interactive (list (read-from-minibuffer
+ − 328 "Copy non-matching lines (regexp): "
+ − 329 nil nil nil 'regexp-history)))
+ − 330 (let ((beg nil)
+ − 331 (end nil)
+ − 332 (count nil))
+ − 333 (when (region-active-p)
+ − 334 (setq beg (region-beginning))
+ − 335 (setq end (region-end)))
+ − 336 (setq count (operate-on-non-matching-lines regexp nil t beg end))
1476
+ − 337 (when (interactive-p)
+ − 338 (message "%i lines copied" count))))
1069
+ − 339
+ − 340 (defun operate-on-matching-lines (regexp delete kill &optional beg end)
+ − 341 "Internal function used by delete-matching-lines, kill-matching-lines,
+ − 342 and copy-matching-lines.
+ − 343
+ − 344 If DELETE is non-nil, the lines of text are deleted. It doesn't make
+ − 345 sense to set this to nil if KILL is nil -- nothing will happen.
+ − 346
+ − 347 If KILL is non-nil, the lines of text are stored in the kill ring (as
+ − 348 one block of text).
+ − 349
+ − 350 BEG and END, if non-nil, specify the start and end locations to work
+ − 351 within. If these are nil, point and point-max are used.
+ − 352
+ − 353 If a match is split across lines, all the lines it lies in are deleted.
+ − 354 Applies to lines after point.
+ − 355 Returns the number of lines matched."
+ − 356 (with-search-caps-disable-folding regexp t
428
+ − 357 (save-excursion
1069
+ − 358 (let ((matched-text nil)
+ − 359 (curmatch-start nil)
+ − 360 (curmatch-end nil)
+ − 361 (limit nil))
+ − 362
+ − 363 ;; Limit search if limits were specified.
+ − 364 (when beg (goto-char beg))
+ − 365 (when end (setq limit (copy-marker end)))
+ − 366
+ − 367 (while (and (not (eobp))
+ − 368 (re-search-forward regexp limit t))
+ − 369 (setq curmatch-start (save-excursion (goto-char (match-beginning 0))
+ − 370 (beginning-of-line)
+ − 371 (point)))
+ − 372 (setq curmatch-end (progn (forward-line 1) (point)))
+ − 373 (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end)))
+ − 374 (if delete (delete-region curmatch-start curmatch-end)))
+ − 375
+ − 376 (if (and matched-text kill) (kill-new matched-text))
+ − 377
+ − 378 ;; Return the number of matched lines.
+ − 379 (with-temp-buffer
+ − 380 ;; Use concat to make a string even if matched-text is nil.
+ − 381 (insert (concat matched-text))
+ − 382 (count-lines (point-min) (point-max)))
+ − 383 ))))
428
+ − 384
+ − 385 (define-function 'flush-lines 'delete-matching-lines)
+ − 386 (defun delete-matching-lines (regexp)
1069
+ − 387 "Delete the lines that match REGEXP, from point to the end of the
+ − 388 buffer (or within the region, if it is active)."
428
+ − 389 (interactive (list (read-from-minibuffer
+ − 390 "Flush lines (containing match for regexp): "
+ − 391 nil nil nil 'regexp-history)))
1069
+ − 392 (let ((beg nil)
+ − 393 (end nil)
+ − 394 (count nil))
+ − 395 (when (region-active-p)
+ − 396 (setq beg (region-beginning))
+ − 397 (setq end (region-end)))
+ − 398 (setq count (operate-on-matching-lines regexp t nil beg end))
1476
+ − 399 (when (interactive-p)
+ − 400 (message "%i lines deleted" count))))
1069
+ − 401
+ − 402 (defun kill-matching-lines (regexp)
+ − 403 "Delete the lines that match REGEXP, from point to the end of the
+ − 404 buffer (or within the region, if it is active). The deleted lines are
+ − 405 placed in the kill ring as one block of text."
+ − 406 (interactive (list (read-from-minibuffer
+ − 407 "Kill lines (containing match for regexp): "
+ − 408 nil nil nil 'regexp-history)))
+ − 409 (let ((beg nil)
+ − 410 (end nil)
+ − 411 (count nil))
+ − 412 (when (region-active-p)
+ − 413 (setq beg (region-beginning))
+ − 414 (setq end (region-end)))
+ − 415 (setq count (operate-on-matching-lines regexp t t beg end))
1476
+ − 416 (when (interactive-p)
+ − 417 (message "%i lines killed" count))))
1069
+ − 418
+ − 419 (defun copy-matching-lines (regexp)
+ − 420 "Find all lines that match REGEXP from point to the end of the
+ − 421 buffer (or within the region, if it is active), and place them in the
+ − 422 kill ring as one block of text."
+ − 423 (interactive (list (read-from-minibuffer
+ − 424 "Copy lines (containing match for regexp): "
+ − 425 nil nil nil 'regexp-history)))
+ − 426 (let ((beg nil)
+ − 427 (end nil)
+ − 428 (count nil))
+ − 429 (when (region-active-p)
+ − 430 (setq beg (region-beginning))
+ − 431 (setq end (region-end)))
+ − 432 (setq count (operate-on-matching-lines regexp nil t beg end))
1476
+ − 433 (when (interactive-p)
+ − 434 (message "%i lines copied" count))))
428
+ − 435
+ − 436 (define-function 'how-many 'count-matches)
+ − 437 (defun count-matches (regexp)
+ − 438 "Print number of matches for REGEXP following point."
+ − 439 (interactive (list (read-from-minibuffer
+ − 440 "How many matches for (regexp): "
+ − 441 nil nil nil 'regexp-history)))
+ − 442 (with-interactive-search-caps-disable-folding regexp t
+ − 443 (let ((count 0) opoint)
+ − 444 (save-excursion
+ − 445 (while (and (not (eobp))
+ − 446 (progn (setq opoint (point))
+ − 447 (re-search-forward regexp nil t)))
+ − 448 (if (= opoint (point))
+ − 449 (forward-char 1)
+ − 450 (setq count (1+ count))))
+ − 451 (message "%d occurrences" count)))))
+ − 452
+ − 453
+ − 454 (defvar occur-mode-map ())
+ − 455 (if occur-mode-map
+ − 456 ()
+ − 457 (setq occur-mode-map (make-sparse-keymap))
+ − 458 (set-keymap-name occur-mode-map 'occur-mode-map) ; XEmacs
+ − 459 (define-key occur-mode-map 'button2 'occur-mode-mouse-goto) ; XEmacs
+ − 460 (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
+ − 461 (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence))
+ − 462
+ − 463 (defvar occur-buffer nil)
+ − 464 (defvar occur-nlines nil)
+ − 465 (defvar occur-pos-list nil)
+ − 466
+ − 467 (defun occur-mode ()
+ − 468 "Major mode for output from \\[occur].
+ − 469 \\<occur-mode-map>Move point to one of the items in this buffer, then use
+ − 470 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
+ − 471 Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
+ − 472
+ − 473 \\{occur-mode-map}"
+ − 474 (kill-all-local-variables)
+ − 475 (use-local-map occur-mode-map)
+ − 476 (setq major-mode 'occur-mode)
+ − 477 (setq mode-name (gettext "Occur")) ; XEmacs
+ − 478 (make-local-variable 'occur-buffer)
+ − 479 (make-local-variable 'occur-nlines)
+ − 480 (make-local-variable 'occur-pos-list)
+ − 481 (require 'mode-motion) ; XEmacs
+ − 482 (setq mode-motion-hook 'mode-motion-highlight-line) ; XEmacs
+ − 483 (run-hooks 'occur-mode-hook))
+ − 484
+ − 485 ;; FSF Version of next function:
+ − 486 ; (let (buffer pos)
+ − 487 ; (save-excursion
+ − 488 ; (set-buffer (window-buffer (posn-window (event-end event))))
+ − 489 ; (save-excursion
+ − 490 ; (goto-char (posn-point (event-end event)))
+ − 491 ; (setq pos (occur-mode-find-occurrence))
+ − 492 ; (setq buffer occur-buffer)))
+ − 493 ; (pop-to-buffer buffer)
+ − 494 ; (goto-char (marker-position pos))))
+ − 495
+ − 496 (defun occur-mode-mouse-goto (event)
+ − 497 "Go to the occurrence highlighted by mouse.
444
+ − 498 This function should be bound to a mouse key in the `*Occur*' buffer."
428
+ − 499 (interactive "e")
+ − 500 (let ((window-save (selected-window))
+ − 501 (frame-save (selected-frame)))
+ − 502 ;; preserve the window/frame setup
+ − 503 (unwind-protect
+ − 504 (progn
+ − 505 (mouse-set-point event)
+ − 506 (occur-mode-goto-occurrence))
+ − 507 (select-frame frame-save)
+ − 508 (select-window window-save))))
+ − 509
+ − 510 ;; Called occur-mode-find-occurrence in FSF
+ − 511 (defun occur-mode-goto-occurrence ()
+ − 512 "Go to the occurrence the current line describes."
+ − 513 (interactive)
+ − 514 (if (or (null occur-buffer)
+ − 515 (null (buffer-name occur-buffer)))
+ − 516 (progn
+ − 517 (setq occur-buffer nil
+ − 518 occur-pos-list nil)
+ − 519 (error "Buffer in which occurrences were found is deleted")))
+ − 520 (let* ((line-count
+ − 521 (count-lines (point-min)
+ − 522 (save-excursion
+ − 523 (beginning-of-line)
+ − 524 (point))))
+ − 525 (occur-number (save-excursion
+ − 526 (beginning-of-line)
+ − 527 (/ (1- line-count)
+ − 528 (cond ((< occur-nlines 0)
+ − 529 (- 2 occur-nlines))
+ − 530 ((> occur-nlines 0)
+ − 531 (+ 2 (* 2 occur-nlines)))
+ − 532 (t 1)))))
+ − 533 (pos (nth occur-number occur-pos-list))
+ − 534 ;; removed t arg from Bob Weiner, 10/6/95
+ − 535 (window (get-buffer-window occur-buffer))
+ − 536 (occur-source-buffer occur-buffer))
+ − 537 (if (< line-count 1)
+ − 538 (error "No occurrence on this line"))
+ − 539 (or pos
+ − 540 (error "No occurrence on this line"))
+ − 541 ;; XEmacs: don't raise window unless it isn't visible
+ − 542 ;; allow for the possibility that the occur buffer is on another frame
+ − 543 (or (and window
+ − 544 (window-live-p window)
+ − 545 (frame-visible-p (window-frame window))
+ − 546 (set-buffer occur-source-buffer))
+ − 547 (and (pop-to-buffer occur-source-buffer)
+ − 548 (setq window (get-buffer-window occur-source-buffer))))
+ − 549 (goto-char pos)
+ − 550 (set-window-point window pos)))
+ − 551
+ − 552
+ − 553 (defvar list-matching-lines-default-context-lines 0
+ − 554 "*Default number of context lines to include around a `list-matching-lines'
+ − 555 match. A negative number means to include that many lines before the match.
+ − 556 A positive number means to include that many lines both before and after.")
+ − 557
+ − 558 ;; XEmacs addition
+ − 559 ;;; Damn you Jamie, this is utter trash.
+ − 560 (defvar list-matching-lines-whole-buffer t
+ − 561 "If t, occur operates on whole buffer, otherwise occur starts from point.
+ − 562 default is t.")
+ − 563
+ − 564 (define-function 'occur 'list-matching-lines)
+ − 565 (defun list-matching-lines (regexp &optional nlines)
+ − 566 "Show all lines in the current buffer containing a match for REGEXP.
+ − 567
+ − 568 If a match spreads across multiple lines, all those lines are shown.
+ − 569
448
+ − 570 If variable `list-matching-lines-whole-buffer' is non-nil, the entire
+ − 571 buffer is searched, otherwise search begins at point.
428
+ − 572
+ − 573 Each line is displayed with NLINES lines before and after, or -NLINES
+ − 574 before if NLINES is negative.
+ − 575 NLINES defaults to `list-matching-lines-default-context-lines'.
+ − 576 Interactively it is the prefix arg.
+ − 577
+ − 578 The lines are shown in a buffer named `*Occur*'.
+ − 579 It serves as a menu to find any of the occurrences in this buffer.
+ − 580 \\[describe-mode] in that buffer will explain how."
+ − 581 (interactive
+ − 582 ;; XEmacs change
+ − 583 (list (let* ((default (or (symbol-near-point)
+ − 584 (and regexp-history
+ − 585 (car regexp-history))))
+ − 586 (minibuffer-history-minimum-string-length 0)
+ − 587 (input
+ − 588 (if default
+ − 589 ;; rewritten for I18N3 snarfing
+ − 590 (read-from-minibuffer
+ − 591 (format "List lines matching regexp (default `%s'): "
456
+ − 592 default) nil nil nil 'regexp-history nil
+ − 593 default)
428
+ − 594 (read-from-minibuffer
+ − 595 "List lines matching regexp: "
+ − 596 nil nil nil
+ − 597 'regexp-history))))
+ − 598 (if (and (equal input "") default)
+ − 599 (progn
+ − 600 (setq input default)
+ − 601 (setcar regexp-history default)))
+ − 602 ;; clear extra entries
+ − 603 (setcdr regexp-history (delete (car regexp-history)
+ − 604 (cdr regexp-history)))
+ − 605 input)
+ − 606 current-prefix-arg))
+ − 607 (if (equal regexp "")
+ − 608 (error "Must pass non-empty regexp to `list-matching-lines'"))
+ − 609 (setq nlines (if nlines (prefix-numeric-value nlines)
+ − 610 list-matching-lines-default-context-lines))
+ − 611 (let ((first t)
+ − 612 (dir default-directory)
+ − 613 (buffer (current-buffer))
+ − 614 (linenum 1)
+ − 615 (prevpos (point-min))
+ − 616 ;; The rest of this function is very different from FSF.
+ − 617 ;; Presumably that's due to Jamie's misfeature
+ − 618 (final-context-start (make-marker)))
+ − 619 (if (not list-matching-lines-whole-buffer)
+ − 620 (save-excursion
+ − 621 (beginning-of-line)
+ − 622 (setq linenum (1+ (count-lines (point-min) (point))))
+ − 623 (setq prevpos (point))))
+ − 624 (with-output-to-temp-buffer "*Occur*"
+ − 625 (save-excursion
+ − 626 (set-buffer standard-output)
+ − 627 (setq default-directory dir)
+ − 628 ;; We will insert the number of lines, and "lines", later.
+ − 629 ;; #### Needs fixing for I18N3
+ − 630 (let ((print-escape-newlines t))
+ − 631 (insert (format " matching %s in buffer %s.\n"
+ − 632 regexp (buffer-name buffer))))
+ − 633 (occur-mode)
+ − 634 (setq occur-buffer buffer)
+ − 635 (setq occur-nlines nlines)
+ − 636 (setq occur-pos-list ()))
+ − 637 (if (eq buffer standard-output)
+ − 638 (goto-char (point-max)))
+ − 639 (with-interactive-search-caps-disable-folding regexp t
+ − 640 (save-excursion
+ − 641 (if list-matching-lines-whole-buffer
+ − 642 (beginning-of-buffer))
+ − 643 (message "Searching for %s ..." regexp)
+ − 644 ;; Find next match, but give up if prev match was at end of buffer.
+ − 645 (while (and (not (= prevpos (point-max)))
+ − 646 (re-search-forward regexp nil t))
+ − 647 (goto-char (match-beginning 0))
+ − 648 (beginning-of-line)
+ − 649 (save-match-data
+ − 650 (setq linenum (+ linenum (count-lines prevpos (point)))))
+ − 651 (setq prevpos (point))
+ − 652 (goto-char (match-end 0))
+ − 653 (let* ((start (save-excursion
+ − 654 (goto-char (match-beginning 0))
+ − 655 (forward-line (if (< nlines 0) nlines (- nlines)))
+ − 656 (point)))
+ − 657 (end (save-excursion
+ − 658 (goto-char (match-end 0))
+ − 659 (if (> nlines 0)
+ − 660 (forward-line (1+ nlines))
+ − 661 (forward-line 1))
+ − 662 (point)))
+ − 663 (tag (format "%5d" linenum))
+ − 664 (empty (make-string (length tag) ?\ ))
+ − 665 tem)
+ − 666 (save-excursion
+ − 667 (setq tem (make-marker))
+ − 668 (set-marker tem (point))
+ − 669 (set-buffer standard-output)
+ − 670 (setq occur-pos-list (cons tem occur-pos-list))
+ − 671 (or first (zerop nlines)
+ − 672 (insert "--------\n"))
+ − 673 (setq first nil)
+ − 674 (insert-buffer-substring buffer start end)
444
+ − 675 (set-marker final-context-start
428
+ − 676 (- (point) (- end (match-end 0))))
+ − 677 (backward-char (- end start))
+ − 678 (setq tem (if (< nlines 0) (- nlines) nlines))
+ − 679 (while (> tem 0)
+ − 680 (insert empty ?:)
+ − 681 (forward-line 1)
+ − 682 (setq tem (1- tem)))
+ − 683 (let ((this-linenum linenum))
+ − 684 (while (< (point) final-context-start)
+ − 685 (if (null tag)
+ − 686 (setq tag (format "%5d" this-linenum)))
+ − 687 (insert tag ?:)
444
+ − 688 ;; FSFmacs --
428
+ − 689 ;; we handle this using mode-motion-highlight-line, above.
+ − 690 ;; (put-text-property (save-excursion
+ − 691 ;; (beginning-of-line)
+ − 692 ;; (point))
+ − 693 ;; (save-excursion
+ − 694 ;; (end-of-line)
+ − 695 ;; (point))
+ − 696 ;; 'mouse-face 'highlight)
+ − 697 (forward-line 1)
+ − 698 (setq tag nil)
+ − 699 (setq this-linenum (1+ this-linenum)))
+ − 700 (while (<= (point) final-context-start)
+ − 701 (insert empty ?:)
+ − 702 (forward-line 1)
+ − 703 (setq this-linenum (1+ this-linenum))))
+ − 704 (while (< tem nlines)
+ − 705 (insert empty ?:)
+ − 706 (forward-line 1)
+ − 707 (setq tem (1+ tem)))
+ − 708 (goto-char (point-max)))
+ − 709 (forward-line 1)))
+ − 710 (set-buffer standard-output)
+ − 711 ;; Put positions in increasing order to go with buffer.
+ − 712 (setq occur-pos-list (nreverse occur-pos-list))
+ − 713 (goto-char (point-min))
+ − 714 (if (= (length occur-pos-list) 1)
+ − 715 (insert "1 line")
+ − 716 (insert (format "%d lines" (length occur-pos-list))))
+ − 717 (if (interactive-p)
+ − 718 (message "%d matching lines." (length occur-pos-list))))))))
+ − 719
+ − 720 ;; It would be nice to use \\[...], but there is no reasonable way
+ − 721 ;; to make that display both SPC and Y.
+ − 722 (defconst query-replace-help
444
+ − 723 "Type Space or `y' to replace one match, Delete or `n' to skip to next,
428
+ − 724 RET or `q' to exit, Period to replace one match and exit,
+ − 725 Comma to replace but not move point immediately,
+ − 726 C-r to enter recursive edit (\\[exit-recursive-edit] to get out again),
+ − 727 C-w to delete match and recursive edit,
+ − 728 C-l to clear the frame, redisplay, and offer same replacement again,
+ − 729 ! to replace all remaining matches with no more questions,
+ − 730 ^ to move point back to previous match."
444
+ − 731
428
+ − 732 "Help message while in query-replace")
+ − 733
+ − 734 (defvar query-replace-map nil
+ − 735 "Keymap that defines the responses to questions in `query-replace'.
+ − 736 The \"bindings\" in this map are not commands; they are answers.
+ − 737 The valid answers include `act', `skip', `act-and-show',
+ − 738 `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
+ − 739 `automatic', `backup', `exit-prefix', and `help'.")
+ − 740
+ − 741 ;; Why does it seem that ever file has a different method of doing this?
+ − 742 (if query-replace-map
+ − 743 nil
+ − 744 (let ((map (make-sparse-keymap)))
+ − 745 (set-keymap-name map 'query-replace-map)
+ − 746 (define-key map " " 'act)
+ − 747 (define-key map "\d" 'skip)
+ − 748 (define-key map [delete] 'skip)
+ − 749 (define-key map [backspace] 'skip)
+ − 750 (define-key map "y" 'act)
+ − 751 (define-key map "n" 'skip)
+ − 752 (define-key map "Y" 'act)
+ − 753 (define-key map "N" 'skip)
+ − 754 (define-key map "," 'act-and-show)
+ − 755 (define-key map [escape] 'exit)
+ − 756 (define-key map "q" 'exit)
+ − 757 (define-key map [return] 'exit)
+ − 758 (define-key map "." 'act-and-exit)
+ − 759 (define-key map "\C-r" 'edit)
+ − 760 (define-key map "\C-w" 'delete-and-edit)
+ − 761 (define-key map "\C-l" 'recenter)
+ − 762 (define-key map "!" 'automatic)
+ − 763 (define-key map "^" 'backup)
+ − 764 (define-key map [(control h)] 'help) ;; XEmacs change
+ − 765 (define-key map [f1] 'help)
+ − 766 (define-key map [help] 'help)
+ − 767 (define-key map "?" 'help)
+ − 768 (define-key map "\C-g" 'quit)
+ − 769 (define-key map "\C-]" 'quit)
+ − 770 ;FSFmacs (define-key map "\e" 'exit-prefix)
+ − 771 (define-key map [escape] 'exit-prefix)
444
+ − 772
428
+ − 773 (setq query-replace-map map)))
+ − 774
+ − 775 ;; isearch-mode is dumped, so don't autoload.
+ − 776 ;(autoload 'isearch-highlight "isearch")
+ − 777
+ − 778 ;; XEmacs
+ − 779 (defun perform-replace-next-event (event)
442
+ − 780 (if search-highlight
428
+ − 781 (let ((aborted t))
+ − 782 (unwind-protect
+ − 783 (progn
+ − 784 (if (match-beginning 0)
+ − 785 (isearch-highlight (match-beginning 0) (match-end 0)))
+ − 786 (next-command-event event)
+ − 787 (setq aborted nil))
+ − 788 (isearch-dehighlight aborted)))
+ − 789 (next-command-event event)))
+ − 790
+ − 791 (defun perform-replace (from-string replacements
+ − 792 query-flag regexp-flag delimited-flag
+ − 793 &optional repeat-count map)
+ − 794 "Subroutine of `query-replace'. Its complexity handles interactive queries.
+ − 795 Don't use this in your own program unless you want to query and set the mark
+ − 796 just as `query-replace' does. Instead, write a simple loop like this:
+ − 797 (while (re-search-forward \"foo[ \t]+bar\" nil t)
+ − 798 (replace-match \"foobar\" nil nil))
+ − 799 which will run faster and probably do exactly what you want.
444
+ − 800 When searching for a match, this function uses
+ − 801 `replace-search-function' and `replace-re-search-function'."
428
+ − 802 (or map (setq map query-replace-map))
+ − 803 (let* ((event (make-event))
+ − 804 (nocasify (not (and case-fold-search case-replace
+ − 805 (string-equal from-string
+ − 806 (downcase from-string)))))
+ − 807 (literal (not regexp-flag))
444
+ − 808 (search-function (if regexp-flag
+ − 809 replace-re-search-function
428
+ − 810 replace-search-function))
+ − 811 (search-string from-string)
+ − 812 (real-match-data nil) ; the match data for the current match
+ − 813 (next-replacement nil)
+ − 814 (replacement-index 0)
+ − 815 (keep-going t)
+ − 816 (stack nil)
+ − 817 (next-rotate-count 0)
+ − 818 (replace-count 0)
+ − 819 (lastrepl nil) ;Position after last match considered.
+ − 820 ;; If non-nil, it is marker saying where in the buffer to
+ − 821 ;; stop.
+ − 822 (limit nil)
+ − 823 (match-again t)
+ − 824 ;; XEmacs addition
+ − 825 (qr-case-fold-search
+ − 826 (if (and case-fold-search search-caps-disable-folding)
+ − 827 (no-upper-case-p search-string regexp-flag)
+ − 828 case-fold-search))
+ − 829 (message
+ − 830 (if query-flag
+ − 831 (substitute-command-keys
+ − 832 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) "))))
+ − 833 ;; If the region is active, operate on region.
+ − 834 (when (region-active-p)
+ − 835 ;; Original Per Abrahamsen's code simply narrowed the region,
+ − 836 ;; thus providing a visual indication of the search boundary.
+ − 837 ;; Stallman, on the other hand, handles it like this.
+ − 838 (setq limit (copy-marker (region-end)))
+ − 839 (goto-char (region-beginning))
+ − 840 (zmacs-deactivate-region))
+ − 841 (if (stringp replacements)
+ − 842 (setq next-replacement replacements)
+ − 843 (or repeat-count (setq repeat-count 1)))
+ − 844 (if delimited-flag
+ − 845 (setq search-function replace-re-search-function
+ − 846 search-string (concat "\\b"
+ − 847 (if regexp-flag from-string
+ − 848 (regexp-quote from-string))
+ − 849 "\\b")))
+ − 850 (push-mark)
+ − 851 (undo-boundary)
+ − 852 (unwind-protect
+ − 853 ;; Loop finding occurrences that perhaps should be replaced.
+ − 854 (while (and keep-going
+ − 855 (not (eobp))
+ − 856 (or (null limit) (< (point) limit))
+ − 857 (let ((case-fold-search qr-case-fold-search))
+ − 858 (funcall search-function search-string limit))
+ − 859 ;; If the search string matches immediately after
+ − 860 ;; the previous match, but it did not match there
+ − 861 ;; before the replacement was done, ignore the match.
+ − 862 (if (or (eq lastrepl (point))
+ − 863 (and regexp-flag
+ − 864 (eq lastrepl (match-beginning 0))
+ − 865 (not match-again)))
+ − 866 (if (or (eobp)
+ − 867 (and limit (>= (point) limit)))
+ − 868 nil
444
+ − 869 ;; Don't replace the null string
428
+ − 870 ;; right after end of previous replacement.
+ − 871 (forward-char 1)
+ − 872 (let ((case-fold-search qr-case-fold-search))
+ − 873 (funcall search-function search-string limit)))
+ − 874 t))
+ − 875
+ − 876 ;; Save the data associated with the real match.
+ − 877 (setq real-match-data (match-data))
+ − 878
+ − 879 ;; Before we make the replacement, decide whether the search string
+ − 880 ;; can match again just after this match.
+ − 881 (if regexp-flag
444
+ − 882 (progn
428
+ − 883 (setq match-again (looking-at search-string))
+ − 884 ;; XEmacs addition
+ − 885 (store-match-data real-match-data)))
+ − 886 ;; If time for a change, advance to next replacement string.
+ − 887 (if (and (listp replacements)
+ − 888 (= next-rotate-count replace-count))
+ − 889 (progn
+ − 890 (setq next-rotate-count
+ − 891 (+ next-rotate-count repeat-count))
+ − 892 (setq next-replacement (nth replacement-index replacements))
+ − 893 (setq replacement-index (% (1+ replacement-index) (length replacements)))))
+ − 894 (if (not query-flag)
+ − 895 (progn
+ − 896 (store-match-data real-match-data)
+ − 897 (replace-match next-replacement nocasify literal)
+ − 898 (setq replace-count (1+ replace-count)))
+ − 899 (undo-boundary)
+ − 900 (let ((help-form
+ − 901 '(concat (format "Query replacing %s%s with %s.\n\n"
+ − 902 (if regexp-flag (gettext "regexp ") "")
+ − 903 from-string next-replacement)
+ − 904 (substitute-command-keys query-replace-help)))
+ − 905 done replaced def)
+ − 906 ;; Loop reading commands until one of them sets done,
+ − 907 ;; which means it has finished handling this occurrence.
+ − 908 (while (not done)
+ − 909 ;; Don't fill up the message log
+ − 910 ;; with a bunch of identical messages.
+ − 911 ;; XEmacs change
+ − 912 (display-message 'prompt
+ − 913 (format message from-string next-replacement))
+ − 914 (perform-replace-next-event event)
+ − 915 (setq def (lookup-key map (vector event)))
+ − 916 ;; Restore the match data while we process the command.
+ − 917 (store-match-data real-match-data)
+ − 918 (cond ((eq def 'help)
+ − 919 (with-output-to-temp-buffer (gettext "*Help*")
+ − 920 (princ (concat
+ − 921 (format "Query replacing %s%s with %s.\n\n"
+ − 922 (if regexp-flag "regexp " "")
+ − 923 from-string next-replacement)
+ − 924 (substitute-command-keys
+ − 925 query-replace-help)))
+ − 926 (save-excursion
+ − 927 (set-buffer standard-output)
+ − 928 (help-mode))))
+ − 929 ((eq def 'exit)
+ − 930 (setq keep-going nil)
+ − 931 (setq done t))
+ − 932 ((eq def 'backup)
+ − 933 (if stack
+ − 934 (let ((elt (car stack)))
+ − 935 (goto-char (car elt))
+ − 936 (setq replaced (eq t (cdr elt)))
+ − 937 (or replaced
+ − 938 (store-match-data (cdr elt)))
+ − 939 (setq stack (cdr stack)))
+ − 940 (message "No previous match")
+ − 941 (ding 'no-terminate)
+ − 942 (sit-for 1)))
+ − 943 ((eq def 'act)
+ − 944 (or replaced
+ − 945 (replace-match next-replacement nocasify literal))
+ − 946 (setq done t replaced t))
+ − 947 ((eq def 'act-and-exit)
+ − 948 (or replaced
+ − 949 (replace-match next-replacement nocasify literal))
+ − 950 (setq keep-going nil)
+ − 951 (setq done t replaced t))
+ − 952 ((eq def 'act-and-show)
+ − 953 (if (not replaced)
+ − 954 (progn
+ − 955 (replace-match next-replacement nocasify literal)
+ − 956 (store-match-data nil)
+ − 957 (setq replaced t))))
+ − 958 ((eq def 'automatic)
+ − 959 (or replaced
+ − 960 (replace-match next-replacement nocasify literal))
+ − 961 (setq done t query-flag nil replaced t))
+ − 962 ((eq def 'skip)
+ − 963 (setq done t))
+ − 964 ((eq def 'recenter)
+ − 965 (recenter nil))
+ − 966 ((eq def 'edit)
+ − 967 (store-match-data
+ − 968 (prog1 (match-data)
+ − 969 (save-excursion (recursive-edit))))
+ − 970 ;; Before we make the replacement,
+ − 971 ;; decide whether the search string
+ − 972 ;; can match again just after this match.
+ − 973 (if regexp-flag
+ − 974 (setq match-again (looking-at search-string))))
+ − 975 ((eq def 'delete-and-edit)
+ − 976 (delete-region (match-beginning 0) (match-end 0))
+ − 977 (store-match-data (prog1 (match-data)
+ − 978 (save-excursion (recursive-edit))))
+ − 979 (setq replaced t))
+ − 980 ;; Note: we do not need to treat `exit-prefix'
+ − 981 ;; specially here, since we reread
+ − 982 ;; any unrecognized character.
+ − 983 (t
+ − 984 (setq this-command 'mode-exited)
+ − 985 (setq keep-going nil)
+ − 986 (setq unread-command-events
+ − 987 (cons event unread-command-events))
+ − 988 (setq done t))))
+ − 989 ;; Record previous position for ^ when we move on.
+ − 990 ;; Change markers to numbers in the match data
+ − 991 ;; since lots of markers slow down editing.
+ − 992 (setq stack
+ − 993 (cons (cons (point)
+ − 994 (or replaced
+ − 995 (match-data t)))
+ − 996 stack))
+ − 997 (if replaced (setq replace-count (1+ replace-count)))))
+ − 998 (setq lastrepl (point)))
+ − 999 ;; Useless in XEmacs. We handle (de)highlighting through
+ − 1000 ;; perform-replace-next-event.
+ − 1001 ;(replace-dehighlight)
+ − 1002 )
+ − 1003 (or unread-command-events
+ − 1004 (message "Replaced %d occurrence%s"
+ − 1005 replace-count
+ − 1006 (if (= replace-count 1) "" "s")))
+ − 1007 (and keep-going stack)))
+ − 1008
+ − 1009 ;; FSFmacs code: someone should port it.
+ − 1010
+ − 1011 ;(defvar query-replace-highlight nil
+ − 1012 ; "*Non-nil means to highlight words during query replacement.")
+ − 1013
+ − 1014 ;(defvar replace-overlay nil)
+ − 1015
+ − 1016 ;(defun replace-dehighlight ()
+ − 1017 ; (and replace-overlay
+ − 1018 ; (progn
+ − 1019 ; (delete-overlay replace-overlay)
+ − 1020 ; (setq replace-overlay nil))))
+ − 1021
+ − 1022 ;(defun replace-highlight (start end)
+ − 1023 ; (and query-replace-highlight
+ − 1024 ; (progn
+ − 1025 ; (or replace-overlay
+ − 1026 ; (progn
+ − 1027 ; (setq replace-overlay (make-overlay start end))
+ − 1028 ; (overlay-put replace-overlay 'face
+ − 1029 ; (if (internal-find-face 'query-replace)
+ − 1030 ; 'query-replace 'region))))
+ − 1031 ; (move-overlay replace-overlay start end (current-buffer)))))
+ − 1032
+ − 1033 ;;; replace.el ends here