Commit f601efb0 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(keep-lines-read-args): Use `copy-marker'.

(how-many): Save excursion properly.
(occur-mode): Use define-derived-mode.
(perform-replace): Use with-current-buffer.
parent 7c5312b2
...@@ -304,7 +304,7 @@ Otherwise, START is the current point, and END is `point-max-marker'." ...@@ -304,7 +304,7 @@ Otherwise, START is the current point, and END is `point-max-marker'."
start end) start end)
(if (and transient-mark-mode mark-active) (if (and transient-mark-mode mark-active)
(setq start (region-beginning) (setq start (region-beginning)
end (save-excursion (goto-char (region-end)) (point-marker))) end (copy-marker (region-end)))
(setq start (point) (setq start (point)
end (point-max-marker))) end (point-max-marker)))
(list regexp start end))) (list regexp start end)))
...@@ -390,33 +390,33 @@ In Transient Mark mode, if the mark is active, operate on the contents ...@@ -390,33 +390,33 @@ In Transient Mark mode, if the mark is active, operate on the contents
of the region. Otherwise, operate from point to the end of the buffer." of the region. Otherwise, operate from point to the end of the buffer."
(interactive (interactive
(keep-lines-read-args "How many matches for (regexp): ")) (keep-lines-read-args "How many matches for (regexp): "))
(if rstart (save-excursion
(goto-char (min rstart rend)) (if rstart
(setq rstart (point) rend (point-max-marker))) (goto-char (min rstart rend))
(let ((count 0) (setq rstart (point) rend (point-max-marker)))
opoint (let ((count 0)
(case-fold-search (and case-fold-search opoint
(isearch-no-upper-case-p regexp t)))) (case-fold-search (and case-fold-search
(save-excursion (isearch-no-upper-case-p regexp t))))
(while (and (< (point) rend) (while (and (< (point) rend)
(progn (setq opoint (point)) (progn (setq opoint (point))
(re-search-forward regexp rend t))) (re-search-forward regexp rend t)))
(if (= opoint (point)) (if (= opoint (point))
(forward-char 1) (forward-char 1)
(setq count (1+ count)))) (setq count (1+ count))))
(message "%d occurrences" count)))) (message "%d occurrences" count))))
(defvar occur-mode-map ()) (defvar occur-mode-map
(if occur-mode-map (let ((map (make-sparse-keymap)))
() (define-key map [mouse-2] 'occur-mode-mouse-goto)
(setq occur-mode-map (make-sparse-keymap)) (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence)
(define-key occur-mode-map [mouse-2] 'occur-mode-mouse-goto) (define-key map "\C-m" 'occur-mode-goto-occurrence)
(define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence) (define-key map "\M-n" 'occur-next)
(define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence) (define-key map "\M-p" 'occur-prev)
(define-key occur-mode-map "\M-n" 'occur-next) (define-key map "g" 'revert-buffer)
(define-key occur-mode-map "\M-p" 'occur-prev) map)
(define-key occur-mode-map "g" 'revert-buffer)) "Keymap for `occur-mode'.")
(defvar occur-buffer nil (defvar occur-buffer nil
...@@ -431,23 +431,17 @@ of the region. Otherwise, operate from point to the end of the buffer." ...@@ -431,23 +431,17 @@ of the region. Otherwise, operate from point to the end of the buffer."
(put 'occur-mode 'mode-class 'special) (put 'occur-mode 'mode-class 'special)
(defun occur-mode () (define-derived-mode occur-mode nil "Occur"
"Major mode for output from \\[occur]. "Major mode for output from \\[occur].
\\<occur-mode-map>Move point to one of the items in this buffer, then use \\<occur-mode-map>Move point to one of the items in this buffer, then use
\\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to. \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it. Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
\\{occur-mode-map}" \\{occur-mode-map}"
(kill-all-local-variables) (set (make-local-variable 'revert-buffer-function) 'occur-revert-function)
(use-local-map occur-mode-map)
(setq major-mode 'occur-mode)
(setq mode-name "Occur")
(make-local-variable 'revert-buffer-function)
(setq revert-buffer-function 'occur-revert-function)
(make-local-variable 'occur-buffer) (make-local-variable 'occur-buffer)
(make-local-variable 'occur-nlines) (make-local-variable 'occur-nlines)
(make-local-variable 'occur-command-arguments) (make-local-variable 'occur-command-arguments))
(run-hooks 'occur-mode-hook))
(defun occur-revert-function (ignore1 ignore2) (defun occur-revert-function (ignore1 ignore2)
"Handle revert-buffer for *Occur* buffers." "Handle revert-buffer for *Occur* buffers."
...@@ -1018,8 +1012,7 @@ which will run faster and probably do exactly what you want." ...@@ -1018,8 +1012,7 @@ which will run faster and probably do exactly what you want."
next-replacement ".\n\n" next-replacement ".\n\n"
(substitute-command-keys (substitute-command-keys
query-replace-help))) query-replace-help)))
(save-excursion (with-current-buffer standard-output
(set-buffer standard-output)
(help-mode)))) (help-mode))))
((eq def 'exit) ((eq def 'exit)
(setq keep-going nil) (setq keep-going nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment