Say I run
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?
Something like this should work for all modes derived from
(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.