I want to be able to use grep to find matching lines and to be able to jump through them using next-error and previous-error however I don't feel the need to have the match list on screen and it takes up considerable space. I would like to find a way to get similar functionality without having to have the window visible.

I managed to avoid showing the window using (setq-default display-buffer-alist '(("\\*grep\\*" (display-buffer-no-window)))) however when the buffer is not in a visible window I get an error when using next-error.

Debugger entered--Lisp error: (wrong-type-argument window-live-p nil)
  #<subr select-window>(nil nil)
  ad-Advice-select-window(#<subr select-window> nil)
  apply(ad-Advice-select-window #<subr select-window> nil)
  next-error-found(#<buffer *grep*> #<buffer controller.rs>)
  funcall-interactively(next-error nil)
  call-interactively(next-error nil nil)

Manually making the window visible then running next-error works, so it isn't broken but something assumes the window is visible for some reason.

  • 2
    Please provide a link to the library where you got rustc-scroll-down-after-next-error, or if you wrote it yourself, then provide the code for that function.
    – lawlist
    Dec 26, 2019 at 17:40
  • Ah, this is from rust-mode. I guess this might be a bug in that code. I'll investigate and file a bug report. github.com/rust-lang/rust-mode/blob/…
    – Kevin Cox
    Jan 2, 2020 at 18:49

1 Answer 1


You say that for you next-error doesn't work unless the buffer with the "error" messages is visible (i.e., in a visible window). I don't see that.

Can you repro the problem starting with emacs -Q (no init file)? If not, bisect your init file to find the culprit.

When I use emacs -Q (with any Emacs version), and then I grep or whatever, to get some "error" messages in a buffer, and then I delete the window showing that buffer, next-error works just fine.

  • I executed grep in a directory, closed the window which contained the *grep* buffer, executed M-x previous-error and this caused a window with the *grep* buffer to be opened. Whenever, M-x previous-error and M-x next-error was executed, the *grep* buffer was shown in a window. I started Emacs with emacs -Q and I'm using Emacs 27.1.
    – doltes
    Nov 15, 2020 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.