2

Say I run ag or grep via M-x and display a window with search results. Say I then use my enter key to open a result. How can I force emacs to open this result in the same window as the search results are currently displaying, rather than a different window?

7
  • Do you mean the same window instead of buffer? Reusing the same buffer would overwrite the search results. See also the answers to this question for further clarification. Commented Jun 30, 2017 at 5:34
  • good shout. Edited Commented Jun 30, 2017 at 9:07
  • Do you want to be able to pick between using the current or a different window, or do you only ever want the current window to be reused? Commented Jun 30, 2017 at 9:50
  • See related questions here, here and here. Commented Jun 30, 2017 at 9:52
  • Ideally I am looking for the equivalent of pressing o vs Enter in Dired mode (e,g an easy way to pick one or the other) Thanks for the links, will look through them over lunch! Commented Jun 30, 2017 at 10:01

1 Answer 1

6

Something like this should work for all modes derived from compilation-mode:

(defun my-compile-goto-error-same-window () (interactive) (let ((display-buffer-overriding-action '((display-buffer-reuse-window display-buffer-same-window) (inhibit-same-window . nil)))) (call-interactively #'compile-goto-error))) (defun my-compilation-mode-hook () (local-set-key (kbd "o") #'my-compile-goto-error-same-window)) (add-hook 'compilation-mode-hook #'my-compilation-mode-hook) 

With this snippet added to your init file, pressing o in a grep buffer (or any buffer derived from compilation-mode) will open the location in the same window.

1
  • Just wanted to say thanks for this, working great 8 years later :) Commented Jan 2 at 1:30

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.