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, 28 May 2004 11:56:43 -0700

I want to thank everybody for all the feedback. 
Based on it I have a new version of this code. 

It is still based on post-command-hook because I believe it works
better this way.

It works in *Occur*, *compilation* and *grep* buffers. It works by
using the `next-error-no-select' function. I have not tested it on
diff buffers, but it seems that it should work there too. 

In *compilation*/*grep* buffers it does not work as smoothly as it
could because `compilation-goto-locus' ends up unconditionally calling
`set-window-start'. 
Would the compile.el maintainers accept a patch to fix this? 

It would also be nice if `compilation-mode' had a function similar to 
`occur-mode-display-occurrence' (and bound to the same key) to
display the error on the current line without switching from the
compilation buffer. 

Please let me know what do you think about the new version. 

(defcustom next-error-follow-mode t
  ;; FIXME: fix this docstring
  "*Non-nil means that point motion in the *** buffer causes the file to 
follow."
  ;; FIXME: find a proper group
  :group 'matching)

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

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

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

;;; All this stuff will be put in the corresponding files
;;; the *-hook-functions will be just pasted in the corresponing 
;;; *-mode functions

(defun compilation-follow-hook-function ()   
  (make-variable-buffer-local 'next-error-follow-last-line) 
  (add-hook 'post-command-hook 'next-error-mode-post-command-hook nil t))

(defun occur-follow-hook-function ()   
  (make-variable-buffer-local 'next-error-follow-last-line) 
  (add-hook 'post-command-hook 'next-error-mode-post-command-hook nil t))

(add-hook 'compilation-mode-hook 'compilation-follow-hook-function)
(add-hook 'occur-mode-hook 'occur-follow-hook-function)

;;; Key bindings 
;;; FIXME: Are these good? 
;;; 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))

(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]