emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: follow mode for occur


From: Dan Nicolaescu
Subject: Re: follow mode for occur
Date: Fri, 4 Jun 2004 11:41:18 -0700
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Here is a new incarnation of this code. It is a minor mode now. 
It works with very well occur, compile, grep and diff-mode. 
It is _not_ turned on by default.

Now there's the question of defaults. 

Should this mode be on by default? 
IMVHO it would be nice to have it on by default at least in  occur-mode
and diff-mode. 

How should it be turned on? Using a menu entry? 

Feedback would be appreciated. 

;;; Internal variable for `next-error-minor-mode-post-command-hook'.
(defvar next-error-follow-last-line nil)

;;;###autoload
(define-minor-mode next-error-follow-minor-mode
  "Minor mode for compilation, occur and diff modes.
When turned on cursor motion in the compilation, occur or diff
buffer determines the cursor in the corresponding buffer to move
to the corresponding position .  " 
  nil " Fol" nil
  (if (not next-error-follow-minor-mode)
      (remove-hook 'post-command-hook 'next-error-minor-mode-post-command-hook 
t)
    (add-hook 'post-command-hook 'next-error-minor-mode-post-command-hook nil t)
    (make-variable-buffer-local 'next-error-follow-last-line) 
    ))

;;; Used as a post-command-hook for the *Compilation* *grep* 
;;; and *Occur* buffers.
(defun next-error-minor-mode-post-command-hook ()
  (unless (equal next-error-follow-last-line (line-number-at-pos))
    (setq next-error-follow-last-line (line-number-at-pos))
    (condition-case nil
        (let ((compilation-context-lines nil))
          (setq compilation-current-error (point))
          (next-error-no-select 0))
      (error t))))

(defun toggle-next-error-follow-mode ()
  (interactive)
  (next-error-follow-minor-mode (not next-error-follow-minor-mode)))

;;; All this stuff will be put in the corresponding files: compile.el
;;; grep.el diff-mode.el and simple.el

;;; FIXME: Should there be a menu entry for the toggle? 
(eval-after-load "compile"
  '(define-key compilation-mode-map "\C-c\C-f" 'toggle-next-error-follow-mode))

(eval-after-load "grep"
  '(define-key grep-mode-map "\C-c\C-f" 'toggle-next-error-follow-mode))


(eval-after-load "diff-mode"
  '(define-key diff-mode-map "\C-c\C-f" 'toggle-next-error-follow-mode))


(define-key occur-mode-map "\C-c\C-f" 'toggle-next-error-follow-mode)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]