From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: follow mode for occur Date: Fri, 28 May 2004 11:56:43 -0700 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200405281856.i4SIufGK022679@scanner2.ics.uci.edu> References: <200405270035.i4R0ZjGK017770@scanner2.ics.uci.edu> <877juxlyz3.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085771478 22020 80.91.224.253 (28 May 2004 19:11:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 28 May 2004 19:11:18 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri May 28 21:10:53 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTmkn-00020T-00 for ; Fri, 28 May 2004 21:10:53 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTmkm-0007F2-00 for ; Fri, 28 May 2004 21:10:52 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTmfO-0003zs-QV for emacs-devel@quimby.gnus.org; Fri, 28 May 2004 15:05:18 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BTmfH-0003yy-FZ for emacs-devel@gnu.org; Fri, 28 May 2004 15:05:11 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BTmek-0003uM-Ll for emacs-devel@gnu.org; Fri, 28 May 2004 15:05:09 -0400 Original-Received: from [128.195.1.36] (helo=scanner2.ics.uci.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTmYD-0003G3-Cz for emacs-devel@gnu.org; Fri, 28 May 2004 14:57:53 -0400 Original-Received: from vino.ics.uci.edu (vino.ics.uci.edu [128.195.11.198]) by scanner2.ics.uci.edu (8.12.10/8.12.10) with ESMTP id i4SIufGK022679; Fri, 28 May 2004 11:56:41 -0700 (PDT) Original-To: Juri Linkov In-Reply-To: <877juxlyz3.fsf@mail.jurta.org> Original-Lines: 74 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=-100, required 5, USER_IN_WHITELIST) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24092 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24092 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)