3

I added add-to-list 'same-window-buffer-names "*grep*" to my .emacs in order to get output from grep-find to come out in the same buffer I M-x grep find from. But after I get the output of the grep, say:

-*- mode: grep; default-directory: "~/sandbox/" -*-
Grep started at Sat Sep  1 17:01:38

find . -type f -print0 | xargs -0 -e grep -nH -e vector
./main.cpp:4:#include <vector>
./typelist.cpp:2:#include <vector>
./main.cpp.eulerbak:4:#include <vector>

If I hit enter on one of those, say typelist.cpp:2, it will split my buffer horizontally and open it there, switching point to the line in that file with the include..is there a way for it NOT to split my buffer and just open it over the grep buffer? This would make it easy for me to then kill the buffer and fall back on the grep results..

Palace Chan
  • 8,845
  • 11
  • 41
  • 93
  • Alternatively, you could just type `C-x 4 0` in the new frame, which will kill both the buffer and the window. – Thomas Sep 02 '12 at 00:21

1 Answers1

2

Add this to your init file.

(eval-when-compile (require 'cl))
(defun kill-grep-window ()
  (destructuring-bind (window major-mode)
      (with-selected-window (next-window (selected-window))
        (list (selected-window) major-mode))
    (when (eq major-mode 'grep-mode)
      (delete-window window))))

(add-hook 'next-error-hook 'kill-grep-window)
event_jr
  • 17,467
  • 4
  • 47
  • 62
  • What version of emacs are you guys using? I'm on 24.1, and this doesn't change the new-frame behavior of `grep` for me. :( – sandinmyjoints Nov 16 '12 at 18:26
  • I've adjusted the code. Also when you talk about Emacs, you need to adjust your terminalogy so everyone can be one the same page. You meant "window" when you "frame", I assume? – event_jr Nov 17 '12 at 01:46
  • Thanks for the reply and for updating the code. I actually do get a whole new emacs frame when I hit enter on a `grep-find` result. http://stackoverflow.com/a/2299261/599258 turns out to be a working solution for that behavior. – sandinmyjoints Nov 18 '12 at 16:13