[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
follow mode for occur
From: |
Dan Nicolaescu |
Subject: |
follow mode for occur |
Date: |
Wed, 26 May 2004 17:35:47 -0700 |
The code below implements a follow mode for the *Occur*, this was
inspired by `reftex-toc-follow-mode'.
Pointer motion in the *Occur* buffer determines motion in the
original buffer. This allows one to quickly browse the *Occur*
buffer while seeing the corresponding matches in the original buffer.
To try this out just evaluate the elisp code below.
C-c C-f toggles the follow mode.
Is there an interest to have something like this included in Emacs?
If there is I can provide a patch acceptable for inclusion.
How about implementing something similar for compile.el?
I can provide code for that too.
Please let me know what do you think about this.
Thanks.
--dan
(defcustom occur-follow-mode t
"*Non-nil means that poing motion in the Occur buffer causes the file to
follow.")
;;; Internal variable for `occur-mode-post-command-hook'.
(defvar occur-follow-last-line nil)
;;; Used as a post-command-hook for the *Occur* buffer.
(defun occur-mode-post-command-hook ()
(when occur-follow-mode
(unless (equal occur-follow-last-line (line-number-at-pos))
(setq occur-follow-last-line (line-number-at-pos))
(condition-case nil
(occur-mode-display-occurrence)
(error t)))))
(add-hook 'occur-mode-hook
(lambda ()
(add-hook 'post-command-hook 'occur-mode-post-command-hook)))
(defun toggle-occur-follow-mode ()
(interactive)
(setq occur-follow-mode (not occur-follow-mode)))
(define-key occur-mode-map "\C-c\C-f" 'toggle-occur-follow-mode)