The @code{next-error} and @code{previous-error} commands don't just act on the errors or matches listed in @file{*compilation*} and @file{*grep*} buffers; they also know how to iterate through error or match lists produced by other commands, such as @kbd{M-x occur} (@pxref{Other Repeating Search}). If the current buffer contains error messages or matches, these commands will iterate through them; otherwise, Emacs looks for a buffer containing error messages or matches amongst the windows of the selected frame, frame (if the variable @code{next-error-find-buffer-function} is customized to the value @code{next-error-buffer-on-selected-frame}), then for any a buffer that used previously by @code{next-error} or @code{previous-error} previously visited, @code{previous-error}, and finally all other buffers. Any buffer these commands iterate through that is not currently displayed in a window will be displayed. You can use the @command{next-error-select-buffer} command to switch to a different buffer to be used by the subsequent invocation of @code{next-error}.