aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorStefan Monnier2001-05-20 16:10:39 +0000
committerStefan Monnier2001-05-20 16:10:39 +0000
commitf601efb0f675df775a97da4df651eb7088790430 (patch)
tree30037b2c77d9cd52548c6d8ff98e652a07d6f4db /lisp/replace.el
parent7c5312b237c5291d4cb6cad114a99d8b20697c82 (diff)
downloademacs-f601efb0f675df775a97da4df651eb7088790430.tar.gz
emacs-f601efb0f675df775a97da4df651eb7088790430.zip
(keep-lines-read-args): Use `copy-marker'.
(how-many): Save excursion properly. (occur-mode): Use define-derived-mode. (perform-replace): Use with-current-buffer.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el67
1 files changed, 30 insertions, 37 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 6ece7d2b01c..e97fe709c45 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -304,7 +304,7 @@ Otherwise, START is the current point, and END is `point-max-marker'."
304 start end) 304 start end)
305 (if (and transient-mark-mode mark-active) 305 (if (and transient-mark-mode mark-active)
306 (setq start (region-beginning) 306 (setq start (region-beginning)
307 end (save-excursion (goto-char (region-end)) (point-marker))) 307 end (copy-marker (region-end)))
308 (setq start (point) 308 (setq start (point)
309 end (point-max-marker))) 309 end (point-max-marker)))
310 (list regexp start end))) 310 (list regexp start end)))
@@ -390,33 +390,33 @@ In Transient Mark mode, if the mark is active, operate on the contents
390of the region. Otherwise, operate from point to the end of the buffer." 390of the region. Otherwise, operate from point to the end of the buffer."
391 (interactive 391 (interactive
392 (keep-lines-read-args "How many matches for (regexp): ")) 392 (keep-lines-read-args "How many matches for (regexp): "))
393 (if rstart 393 (save-excursion
394 (goto-char (min rstart rend)) 394 (if rstart
395 (setq rstart (point) rend (point-max-marker))) 395 (goto-char (min rstart rend))
396 (let ((count 0) 396 (setq rstart (point) rend (point-max-marker)))
397 opoint 397 (let ((count 0)
398 (case-fold-search (and case-fold-search 398 opoint
399 (isearch-no-upper-case-p regexp t)))) 399 (case-fold-search (and case-fold-search
400 (save-excursion 400 (isearch-no-upper-case-p regexp t))))
401 (while (and (< (point) rend) 401 (while (and (< (point) rend)
402 (progn (setq opoint (point)) 402 (progn (setq opoint (point))
403 (re-search-forward regexp rend t))) 403 (re-search-forward regexp rend t)))
404 (if (= opoint (point)) 404 (if (= opoint (point))
405 (forward-char 1) 405 (forward-char 1)
406 (setq count (1+ count)))) 406 (setq count (1+ count))))
407 (message "%d occurrences" count)))) 407 (message "%d occurrences" count))))
408 408
409 409
410(defvar occur-mode-map ()) 410(defvar occur-mode-map
411(if occur-mode-map 411 (let ((map (make-sparse-keymap)))
412 () 412 (define-key map [mouse-2] 'occur-mode-mouse-goto)
413 (setq occur-mode-map (make-sparse-keymap)) 413 (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence)
414 (define-key occur-mode-map [mouse-2] 'occur-mode-mouse-goto) 414 (define-key map "\C-m" 'occur-mode-goto-occurrence)
415 (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence) 415 (define-key map "\M-n" 'occur-next)
416 (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence) 416 (define-key map "\M-p" 'occur-prev)
417 (define-key occur-mode-map "\M-n" 'occur-next) 417 (define-key map "g" 'revert-buffer)
418 (define-key occur-mode-map "\M-p" 'occur-prev) 418 map)
419 (define-key occur-mode-map "g" 'revert-buffer)) 419 "Keymap for `occur-mode'.")
420 420
421 421
422(defvar occur-buffer nil 422(defvar occur-buffer nil
@@ -431,23 +431,17 @@ of the region. Otherwise, operate from point to the end of the buffer."
431 431
432(put 'occur-mode 'mode-class 'special) 432(put 'occur-mode 'mode-class 'special)
433 433
434(defun occur-mode () 434(define-derived-mode occur-mode nil "Occur"
435 "Major mode for output from \\[occur]. 435 "Major mode for output from \\[occur].
436\\<occur-mode-map>Move point to one of the items in this buffer, then use 436\\<occur-mode-map>Move point to one of the items in this buffer, then use
437\\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to. 437\\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
438Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it. 438Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
439 439
440\\{occur-mode-map}" 440\\{occur-mode-map}"
441 (kill-all-local-variables) 441 (set (make-local-variable 'revert-buffer-function) 'occur-revert-function)
442 (use-local-map occur-mode-map)
443 (setq major-mode 'occur-mode)
444 (setq mode-name "Occur")
445 (make-local-variable 'revert-buffer-function)
446 (setq revert-buffer-function 'occur-revert-function)
447 (make-local-variable 'occur-buffer) 442 (make-local-variable 'occur-buffer)
448 (make-local-variable 'occur-nlines) 443 (make-local-variable 'occur-nlines)
449 (make-local-variable 'occur-command-arguments) 444 (make-local-variable 'occur-command-arguments))
450 (run-hooks 'occur-mode-hook))
451 445
452(defun occur-revert-function (ignore1 ignore2) 446(defun occur-revert-function (ignore1 ignore2)
453 "Handle revert-buffer for *Occur* buffers." 447 "Handle revert-buffer for *Occur* buffers."
@@ -1018,8 +1012,7 @@ which will run faster and probably do exactly what you want."
1018 next-replacement ".\n\n" 1012 next-replacement ".\n\n"
1019 (substitute-command-keys 1013 (substitute-command-keys
1020 query-replace-help))) 1014 query-replace-help)))
1021 (save-excursion 1015 (with-current-buffer standard-output
1022 (set-buffer standard-output)
1023 (help-mode)))) 1016 (help-mode))))
1024 ((eq def 'exit) 1017 ((eq def 'exit)
1025 (setq keep-going nil) 1018 (setq keep-going nil)