Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In emacs, when I do a grep-find, how can I have the files displayed to me open in the same frame as the grep output rather than a different one? [duplicate]

Tags:

emacs

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..

like image 539
Palace Chan Avatar asked Dec 18 '25 03:12

Palace Chan


1 Answers

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)
like image 177
event_jr Avatar answered Dec 19 '25 17:12

event_jr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!