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: [patch] follow mode for occur, compilation and diff Date: Sat, 28 Aug 2004 19:00:32 -0700 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <200408290200.i7T20ZGK020594@scanner2.ics.uci.edu> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1093744985 7871 80.91.224.253 (29 Aug 2004 02:03:05 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 29 Aug 2004 02:03:05 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 29 04:02:55 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C1F1z-0005Jx-00 for ; Sun, 29 Aug 2004 04:02:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C1F6j-0005Q6-Dt for ged-emacs-devel@m.gmane.org; Sat, 28 Aug 2004 22:07:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C1F6a-0005Pq-7n for emacs-devel@gnu.org; Sat, 28 Aug 2004 22:07:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C1F6Z-0005Pd-6m for emacs-devel@gnu.org; Sat, 28 Aug 2004 22:07:39 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C1F6Y-0005PZ-Mo for emacs-devel@gnu.org; Sat, 28 Aug 2004 22:07:38 -0400 Original-Received: from [128.195.1.36] (helo=scanner2.ics.uci.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C1F0r-0005LV-MJ for emacs-devel@gnu.org; Sat, 28 Aug 2004 22:01:46 -0400 Original-Received: from vino.ics.uci.edu (dann@vino.ics.uci.edu [128.195.11.198]) by scanner2.ics.uci.edu (8.12.10/8.12.10) with ESMTP id i7T20ZGK020594 for ; Sat, 28 Aug 2004 19:00:35 -0700 (PDT) Original-To: emacs-devel@gnu.org Original-Lines: 150 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=-95.49, required 5, J_CHICKENPOX_62, J_CHICKENPOX_72, MSGID_FROM_MTA_SHORT, USER_IN_WHITELIST) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:26599 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:26599 This has been discussed before in the thread starting at: http://lists.gnu.org/archive/html/emacs-devel/2004-05/msg01517.html The implementation below should be complete, it works for: occur, compile, grep and diff mode. The new minor mode can be toggled with to C-c C-f Please check this in if the code is OK. 2004-08-28 Dan Nicolaescu * simple.el (next-error-follow-minor-mode) (next-error-minor-mode-post-command-hook): New functions. * diff-mode.el (diff-mode-map): Bind toggle-next-error-follow-mode. * progmodes/compile.el (compilation-mode-map): Likewise. * replace.el (occur-mode-map): Likewise. Index: etc/NEWS =================================================================== RCS file: /cvsroot/emacs/emacs/etc/NEWS,v retrieving revision 1.1014 diff -c -3 -p -r1.1014 NEWS *** etc/NEWS 26 Aug 2004 01:47:55 -0000 1.1014 --- etc/NEWS 29 Aug 2004 01:44:07 -0000 *************** The new file etc/compilation.txt gives e *** 243,248 **** --- 243,254 ---- Hits are fontified in green, and hits in binary files in orange. Grep buffers can be saved and automatically revisited with the new Grep mode. + ** A new minor mode `next-error-follow-minor-mode' can be used in + compilation-mode, grep-mode, occur-mode, and diff-mode (i.e. all the modes + that can use `next-error') to associate cursor movements in + compilation, grep, occur or diff buffers with cursor movements in the + target buffers. This minor mode can be toggled with C-c C-f. + ** M-x diff uses diff-mode instead of compilation-mode. ** M-x compare-windows now can automatically skip non-matching text to Index: simple.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v retrieving revision 1.653 diff -c -3 -p -r1.653 simple.el *** simple.el 22 Aug 2004 16:59:57 -0000 1.653 --- simple.el 29 Aug 2004 01:45:02 -0000 *************** select the source buffer." *** 212,217 **** --- 212,247 ---- (interactive "p") (next-error-no-select (- n))) + ;;; Internal variable for `next-error-minor-mode-post-command-hook'. + (defvar next-error-follow-last-line nil) + + (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' by `next-error-follow-minor-mode' + ;;; 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 () + "Toggles `next-error-follow-minor-mode'. " + (interactive) + (next-error-follow-minor-mode (not next-error-follow-minor-mode))) + ;;; (defun fundamental-mode () Index: replace.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v retrieving revision 1.187 diff -c -3 -p -r1.187 replace.el *** replace.el 1 Aug 2004 12:59:09 -0000 1.187 --- replace.el 29 Aug 2004 01:45:03 -0000 *************** end of the buffer." *** 618,623 **** --- 618,624 ---- (define-key map "g" 'revert-buffer) (define-key map "q" 'quit-window) (define-key map "z" 'kill-this-buffer) + (define-key map "\C-c\C-f" 'toggle-next-error-follow-mode) map) "Keymap for `occur-mode'.") Index: diff-mode.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/diff-mode.el,v retrieving revision 1.65 diff -c -3 -p -r1.65 diff-mode.el *** diff-mode.el 13 Jun 2004 16:49:55 -0000 1.65 --- diff-mode.el 29 Aug 2004 01:45:03 -0000 *************** when editing big diffs)." *** 139,145 **** ("\C-c\C-r" . diff-refine-hunk) ("\C-c\C-s" . diff-split-hunk) ("\C-c\C-a" . diff-apply-hunk) ! ("\C-c\C-t" . diff-test-hunk)) "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") (easy-menu-define diff-mode-menu diff-mode-map --- 139,146 ---- ("\C-c\C-r" . diff-refine-hunk) ("\C-c\C-s" . diff-split-hunk) ("\C-c\C-a" . diff-apply-hunk) ! ("\C-c\C-t" . diff-test-hunk) ! ("\C-c\C-f" . toggle-next-error-follow-mode)) "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") (easy-menu-define diff-mode-menu diff-mode-map Index: progmodes/compile.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/compile.el,v retrieving revision 1.323 diff -c -3 -p -r1.323 compile.el *** progmodes/compile.el 16 Aug 2004 22:44:56 -0000 1.323 --- progmodes/compile.el 29 Aug 2004 01:45:04 -0000 *************** exited abnormally with code %d\n" *** 1052,1057 **** --- 1052,1058 ---- (set-keymap-parent map compilation-minor-mode-map) (define-key map " " 'scroll-up) (define-key map "\^?" 'scroll-down) + (define-key map "\C-c\C-f" 'toggle-next-error-follow-mode) ;; Set up the menu-bar (define-key map [menu-bar compilation]