emacs-devel
[Top][All Lists]
Advanced

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

[patch] follow mode for occur, compilation and diff


From: Dan Nicolaescu
Subject: [patch] follow mode for occur, compilation and diff
Date: Sat, 28 Aug 2004 19:00:32 -0700

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  <address@hidden>

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




reply via email to

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