diff options
| author | Richard M. Stallman | 1994-03-30 17:54:38 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-30 17:54:38 +0000 |
| commit | 78bead73667a9b75d333673dd283309fd507a9cb (patch) | |
| tree | 5fee363b230cc48121989b1bd794d253a3d7fb4f /lisp/replace.el | |
| parent | f98494a43df492ee02d6ade1c01a49f7be09cd11 (diff) | |
| download | emacs-78bead73667a9b75d333673dd283309fd507a9cb.tar.gz emacs-78bead73667a9b75d333673dd283309fd507a9cb.zip | |
(occur-mode-find-occurrence): New subroutine.
(occur-mode-goto-occurrence): Use that.
(occur-mode-mouse-goto): New command.
(occur-mode-map): Bind mouse-2.
(occur-mode-find-occurrence): Error if point is on first line.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index eeb0e0951db..f96e829e8ce 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -209,6 +209,7 @@ Applies to lines after point." | |||
| 209 | (if occur-mode-map | 209 | (if occur-mode-map |
| 210 | () | 210 | () |
| 211 | (setq occur-mode-map (make-sparse-keymap)) | 211 | (setq occur-mode-map (make-sparse-keymap)) |
| 212 | (define-key occur-mode-map [mouse-2] 'occur-mode-mouse-goto) | ||
| 212 | (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)) | 213 | (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)) |
| 213 | 214 | ||
| 214 | (defvar occur-buffer nil) | 215 | (defvar occur-buffer nil) |
| @@ -230,31 +231,52 @@ in the buffer that the occurrences were found in. | |||
| 230 | (make-local-variable 'occur-pos-list) | 231 | (make-local-variable 'occur-pos-list) |
| 231 | (run-hooks 'occur-mode-hook)) | 232 | (run-hooks 'occur-mode-hook)) |
| 232 | 233 | ||
| 233 | (defun occur-mode-goto-occurrence () | 234 | (defun occur-mode-mouse-goto (event) |
| 234 | "Go to the line this occurrence was found in, in the buffer it was found in." | 235 | "In Occur mode, go to the occurrence whose line you click on." |
| 235 | (interactive) | 236 | (interactive "e") |
| 237 | (let (buffer pos) | ||
| 238 | (save-excursion | ||
| 239 | (set-buffer (window-buffer (posn-window (event-end event)))) | ||
| 240 | (save-excursion | ||
| 241 | (goto-char (posn-point (event-end event))) | ||
| 242 | (setq pos (occur-mode-find-occurrence)) | ||
| 243 | (setq buffer occur-buffer))) | ||
| 244 | (pop-to-buffer buffer) | ||
| 245 | (goto-char (marker-position pos)))) | ||
| 246 | |||
| 247 | (defun occur-mode-find-occurrence () | ||
| 236 | (if (or (null occur-buffer) | 248 | (if (or (null occur-buffer) |
| 237 | (null (buffer-name occur-buffer))) | 249 | (null (buffer-name occur-buffer))) |
| 238 | (progn | 250 | (progn |
| 239 | (setq occur-buffer nil | 251 | (setq occur-buffer nil |
| 240 | occur-pos-list nil) | 252 | occur-pos-list nil) |
| 241 | (error "Buffer in which occurrences were found is deleted"))) | 253 | (error "Buffer in which occurrences were found is deleted"))) |
| 242 | (let* ((occur-number (save-excursion | 254 | (let* ((line-count |
| 255 | (count-lines (point-min) | ||
| 256 | (save-excursion | ||
| 243 | (beginning-of-line) | 257 | (beginning-of-line) |
| 244 | (/ (1- (count-lines (point-min) | 258 | (point)))) |
| 245 | (save-excursion | 259 | (occur-number (save-excursion |
| 246 | (beginning-of-line) | 260 | (beginning-of-line) |
| 247 | (point)))) | 261 | (/ (1- line-count) |
| 248 | (cond ((< occur-nlines 0) | 262 | (cond ((< occur-nlines 0) |
| 249 | (- 2 occur-nlines)) | 263 | (- 2 occur-nlines)) |
| 250 | ((> occur-nlines 0) | 264 | ((> occur-nlines 0) |
| 251 | (+ 2 (* 2 occur-nlines))) | 265 | (+ 2 (* 2 occur-nlines))) |
| 252 | (t 1))))) | 266 | (t 1))))) |
| 253 | (pos (nth occur-number occur-pos-list))) | 267 | (pos (nth occur-number occur-pos-list))) |
| 268 | (if (< line-count 1) | ||
| 269 | (error "No occurrence on this line")) | ||
| 254 | (or pos | 270 | (or pos |
| 255 | (error "No occurrence on this line")) | 271 | (error "No occurrence on this line")) |
| 272 | pos)) | ||
| 273 | |||
| 274 | (defun occur-mode-goto-occurrence () | ||
| 275 | "Go to the occurrence the current line describes." | ||
| 276 | (interactive) | ||
| 277 | (let ((pos (occur-mode-find-occurrence))) | ||
| 256 | (pop-to-buffer occur-buffer) | 278 | (pop-to-buffer occur-buffer) |
| 257 | (goto-char (marker-position pos)))) | 279 | (goto-char (marker-position pos))))) |
| 258 | 280 | ||
| 259 | (defvar list-matching-lines-default-context-lines 0 | 281 | (defvar list-matching-lines-default-context-lines 0 |
| 260 | "*Default number of context lines to include around a `list-matching-lines' | 282 | "*Default number of context lines to include around a `list-matching-lines' |