360 |
;; Now end is first char preserved by the new match. |
;; Now end is first char preserved by the new match. |
361 |
(if (< start end) |
(if (< start end) |
362 |
(delete-region start end)))) |
(delete-region start end)))) |
363 |
|
|
364 |
(setq start (save-excursion (forward-line 1) (point))) |
(setq start (save-excursion (forward-line 1) (point))) |
365 |
;; If the match was empty, avoid matching again at same place. |
;; If the match was empty, avoid matching again at same place. |
366 |
(and (< (point) rend) |
(and (< (point) rend) |
452 |
(define-key map "\C-o" 'occur-mode-display-occurrence) |
(define-key map "\C-o" 'occur-mode-display-occurrence) |
453 |
(define-key map "\M-n" 'occur-next) |
(define-key map "\M-n" 'occur-next) |
454 |
(define-key map "\M-p" 'occur-prev) |
(define-key map "\M-p" 'occur-prev) |
455 |
|
(define-key map "r" 'occur-rename-buffer) |
456 |
|
(define-key map "c" 'clone-buffer) |
457 |
(define-key map "g" 'revert-buffer) |
(define-key map "g" 'revert-buffer) |
458 |
(define-key map "q" 'delete-window) |
(define-key map "q" 'quit-window) |
459 |
|
(define-key map "z" 'kill-this-buffer) |
460 |
map) |
map) |
461 |
"Keymap for `occur-mode'.") |
"Keymap for `occur-mode'.") |
462 |
|
|
557 |
(if (not n) (setq n 1)) |
(if (not n) (setq n 1)) |
558 |
(let ((r)) |
(let ((r)) |
559 |
(while (> n 0) |
(while (> n 0) |
560 |
|
|
561 |
(setq r (get-text-property (point) 'occur-point)) |
(setq r (get-text-property (point) 'occur-point)) |
562 |
(if r (forward-char -1)) |
(if r (forward-char -1)) |
563 |
|
|
564 |
(setq r (previous-single-property-change (point) 'occur-point)) |
(setq r (previous-single-property-change (point) 'occur-point)) |
565 |
(if r |
(if r |
566 |
(goto-char (- r 1)) |
(goto-char (- r 1)) |
567 |
(error "No earlier matches")) |
(error "No earlier matches")) |
568 |
|
|
569 |
(setq n (1- n))))) |
(setq n (1- n))))) |
570 |
|
|
571 |
(defcustom list-matching-lines-default-context-lines 0 |
(defcustom list-matching-lines-default-context-lines 0 |
626 |
(when current-prefix-arg |
(when current-prefix-arg |
627 |
(prefix-numeric-value current-prefix-arg)))) |
(prefix-numeric-value current-prefix-arg)))) |
628 |
|
|
629 |
|
(defun occur-rename-buffer (&optional unique-p) |
630 |
|
"Rename the current *Occur* buffer to *Occur: original-buffer-name*. |
631 |
|
Here `original-buffer-name' is the buffer name were occur was originally run. |
632 |
|
When given the prefix argument, the renaming will not clobber the existing |
633 |
|
buffer(s) of that name, but use `generate-new-buffer-name' instead. |
634 |
|
You can add this to `occur-mode-hook' if you always want a separate *Occur* |
635 |
|
buffer for each buffer where you invoke `occur'." |
636 |
|
(interactive "P") |
637 |
|
(with-current-buffer |
638 |
|
(if (eq major-mode 'occur-mode) (current-buffer) (get-buffer "*Occur*")) |
639 |
|
(rename-buffer (concat "*Occur: " |
640 |
|
(mapconcat #'buffer-name |
641 |
|
(car (cddr occur-revert-arguments)) "/") |
642 |
|
"*") |
643 |
|
unique-p))) |
644 |
|
|
645 |
(defun occur (regexp &optional nlines) |
(defun occur (regexp &optional nlines) |
646 |
"Show all lines in the current buffer containing a match for REGEXP. |
"Show all lines in the current buffer containing a match for REGEXP. |
647 |
|
|
967 |
(aset data 2 (if (consp next) next (aref data 3)))))) |
(aset data 2 (if (consp next) next (aref data 3)))))) |
968 |
(car (aref data 2))) |
(car (aref data 2))) |
969 |
|
|
970 |
(defun perform-replace (from-string replacements |
(defun perform-replace (from-string replacements |
971 |
query-flag regexp-flag delimited-flag |
query-flag regexp-flag delimited-flag |
972 |
&optional repeat-count map start end) |
&optional repeat-count map start end) |
973 |
"Subroutine of `query-replace'. Its complexity handles interactive queries. |
"Subroutine of `query-replace'. Its complexity handles interactive queries. |
1192 |
(if (and regexp-flag nonempty-match) |
(if (and regexp-flag nonempty-match) |
1193 |
(setq match-again (and (looking-at search-string) |
(setq match-again (and (looking-at search-string) |
1194 |
(match-data))))) |
(match-data))))) |
1195 |
|
|
1196 |
;; Edit replacement. |
;; Edit replacement. |
1197 |
((eq def 'edit-replacement) |
((eq def 'edit-replacement) |
1198 |
(setq next-replacement |
(setq next-replacement |
1201 |
(or replaced |
(or replaced |
1202 |
(replace-match next-replacement nocasify literal)) |
(replace-match next-replacement nocasify literal)) |
1203 |
(setq done t)) |
(setq done t)) |
1204 |
|
|
1205 |
((eq def 'delete-and-edit) |
((eq def 'delete-and-edit) |
1206 |
(delete-region (match-beginning 0) (match-end 0)) |
(delete-region (match-beginning 0) (match-end 0)) |
1207 |
(set-match-data |
(set-match-data |
1231 |
;; beyond the last replacement. Undo that. |
;; beyond the last replacement. Undo that. |
1232 |
(when (and regexp-flag (not match-again) (> replace-count 0)) |
(when (and regexp-flag (not match-again) (> replace-count 0)) |
1233 |
(backward-char 1)) |
(backward-char 1)) |
1234 |
|
|
1235 |
(replace-dehighlight)) |
(replace-dehighlight)) |
1236 |
(or unread-command-events |
(or unread-command-events |
1237 |
(message "Replaced %d occurrence%s" |
(message "Replaced %d occurrence%s" |