comparison lisp/replace.el @ 6596:80df3b456672

(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.
author Richard M. Stallman <rms@gnu.org>
date Wed, 30 Mar 1994 17:54:38 +0000
parents 3989978f6631
children ef938821c625
comparison
equal deleted inserted replaced
6595:7fbc171fd1b5 6596:80df3b456672
207 207
208 (defvar occur-mode-map ()) 208 (defvar occur-mode-map ())
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)
215 (defvar occur-nlines nil) 216 (defvar occur-nlines nil)
216 (defvar occur-pos-list nil) 217 (defvar occur-pos-list nil)
228 (make-local-variable 'occur-buffer) 229 (make-local-variable 'occur-buffer)
229 (make-local-variable 'occur-nlines) 230 (make-local-variable 'occur-nlines)
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'
261 match. A negative number means to include that many lines before the match. 283 match. A negative number means to include that many lines before the match.
262 A positive number means to include that many lines both before and after.") 284 A positive number means to include that many lines both before and after.")