unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [patch] follow mode for occur, compilation and diff
@ 2004-08-29  2:00 Dan Nicolaescu
  2004-08-29 16:29 ` Stefan
  2004-09-13 18:00 ` Ted Zlatanov
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Nicolaescu @ 2004-08-29  2:00 UTC (permalink / raw)



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  <dann@ics.uci.edu>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] follow mode for occur, compilation and diff
  2004-08-29  2:00 [patch] follow mode for occur, compilation and diff Dan Nicolaescu
@ 2004-08-29 16:29 ` Stefan
  2004-08-29 17:21   ` Dan Nicolaescu
  2004-09-13 18:00 ` Ted Zlatanov
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan @ 2004-08-29 16:29 UTC (permalink / raw)
  Cc: emacs-devel

> + (define-minor-mode next-error-follow-minor-mode

I wouldn't bother with the "-minor".

> + (defun toggle-next-error-follow-mode ()
> +   "Toggles `next-error-follow-minor-mode'. "
> +   (interactive)
> +   (next-error-follow-minor-mode (not next-error-follow-minor-mode)))

What is this for?  Toggling is almost never ever used when called from
Lisp anyway.  And M-x next-error-follow-minor-mode RET will do the toggling
just fine, as happens for all minor modes.  I.e. just bind C-c C-f to
next-error-follow-minor-mode.


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] follow mode for occur, compilation and diff
  2004-08-29 16:29 ` Stefan
@ 2004-08-29 17:21   ` Dan Nicolaescu
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Nicolaescu @ 2004-08-29 17:21 UTC (permalink / raw)
  Cc: emacs-devel

Stefan <monnier@iro.umontreal.ca> writes:

  > > + (define-minor-mode next-error-follow-minor-mode
  > 
  > I wouldn't bother with the "-minor".

OK

  > What is this for?  Toggling is almost never ever used when called from

You're right.

An updated patch is attached. It also contains a patch to grep.el that
was accidentally left out.

Please apply if OK. 
Thanks!

2004-08-29  Dan Nicolaescu  <dann@ics.uci.edu>

	* simple.el (next-error-follow-mode)
	(next-error-follow-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.
	* progmodes/grep.el (grep-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 16:56:09 -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-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 16:56:18 -0000
*************** select the source buffer."
*** 212,217 ****
--- 212,242 ----
    (interactive "p")
    (next-error-no-select (- n)))
  
+ ;;; Internal variable for `next-error-follow-mode-post-command-hook'.
+ (defvar next-error-follow-last-line nil)
+ 
+ (define-minor-mode next-error-follow-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-mode)
+       (remove-hook 'post-command-hook 'next-error-follow-mode-post-command-hook t)
+     (add-hook 'post-command-hook 'next-error-follow-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-mode'
+ ;;; for the *Compilation* *grep* and *Occur* buffers.
+ (defun next-error-follow-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 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 16:56:18 -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" '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 16:56:19 -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" . 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 16:56:19 -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" 'next-error-follow-mode)
  
      ;; Set up the menu-bar
      (define-key map [menu-bar compilation]
Index: progmodes/grep.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.19
diff -c -3 -p -r1.19 grep.el
*** progmodes/grep.el	28 Aug 2004 15:31:20 -0000	1.19
--- progmodes/grep.el	29 Aug 2004 16:56:19 -0000
*************** See `compilation-error-screen-columns'"
*** 166,171 ****
--- 166,172 ----
    (let ((map (cons 'keymap compilation-minor-mode-map)))
      (define-key map " " 'scroll-up)
      (define-key map "\^?" 'scroll-down)
+     (define-key map "\C-c\C-f" 'next-error-follow-mode)
  
      ;; This is intolerable -- rms
  ;;;    (define-key map [remap next-line] 'compilation-next-error)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] follow mode for occur, compilation and diff
  2004-08-29  2:00 [patch] follow mode for occur, compilation and diff Dan Nicolaescu
  2004-08-29 16:29 ` Stefan
@ 2004-09-13 18:00 ` Ted Zlatanov
  1 sibling, 0 replies; 4+ messages in thread
From: Ted Zlatanov @ 2004-09-13 18:00 UTC (permalink / raw)


I had problems with next-error-follow-minor-mode.  When enabled with
an Occur buffer, I couldn't escape the Occur buffer.  I would move 1
line in Occur, jump to source, move 1 line, and get booted back to
Occur where the cycle would resume.  Has anyone else had this problem
or is it just me?

Thanks
Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-09-13 18:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-29  2:00 [patch] follow mode for occur, compilation and diff Dan Nicolaescu
2004-08-29 16:29 ` Stefan
2004-08-29 17:21   ` Dan Nicolaescu
2004-09-13 18:00 ` Ted Zlatanov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).