>> Suppose we have such customization: >> >> (setq display-buffer-alist '(("\\`\\*grep\\*\\'" display-buffer-same-window))) >> >> Now after running grep with a non-empty output in ‘emacs -Q’, >> typing ‘C-o’ (compilation-display-error) will display two identical >> buffers instead of displaying the buffer with the found grep hit. >> >> The problem is with pop-to-buffer in next-error-no-select. >> I wonder what is an idiomatic way to ensure a buffer is already >> displayed in some window, to not display the same buffer >> in other window? > > I'm not quite sure I understand: Is there a reason you did not supply > 'display-buffer-reuse-window' in the above customization? Because it's an idiomatic way to tell the Emacs window manager to display the *grep* buffer in the same window (an old way to do the same was using same-window-buffer-names and same-window-regexps) when manually running M-x grep. But it fails when using C-o from the already displayed *grep*. I think next-error-no-select should override the user setting with display-buffer-overriding-action because the purpose of pop-to-buffer in next-error-no-select is to ensure the *grep* buffer is displayed somewhere: