I can use display-buffer-alist to configure a command to open in the same window:
(add-to-list 'display-buffer-alist '("*grep*" display-buffer-same-window))
The problem in this case, however, is if I then open a result and subsequently run a new search without closing the original window, Emacs will open a second view of the search results in the current buffer. That gives me two redundant views of the same results, which is obviously not my intention.
I would like this to be a bit smarter, in that if the buffer is already visible in the current frame, it should merely reuse it (or change focus to it), and display in the current window otherwise.
How can I achieve this behavior?