I try to navigate through compilation errors in my compilation buffer: I place the cursor on an error, and press Enter (alternatively, I use M-g n).

What happens: the compilation buffer places the relevant error line at the top of the compilation buffer.

Why I don't like it: I can't see the relevant context, the few rows above the error (which typically tell me the function the error is in, the file, ...)

How can I configure my compilation buffer so that is doesn't move (or better, places the current error line in the middle) upon selecting an error?

  • Apparently, it has to do with not having a left fringe. Since there's nowhere to display an arrow, emacs falls back to putting the row on top. I could customize the number of context row, with compilation-context-lines. – Gauthier Oct 11 '17 at 14:28

Without a left fringe, there is no place for emacs to show an arrow on the current row. In that case it scrolls down so that the buffer shows the current row on top instead. See here:

If the *compilation* buffer is shown in a window with a left fringe (see Fringes), the locus-visiting commands put an arrow in the fringe, pointing to the current error message. If the window has no left fringe, such as on a text terminal, these commands scroll the window so that the current message is at the top of the window. If you change the variable compilation-context-lines to an integer value n, these commands scroll the window so that the current error message is n lines from the top, whether or not there is a fringe; the default value, nil, gives the behavior described above.

Setting compilation-context-lines to a sensible value (15 in my case, since I always only have narrow buffers at full height) solved my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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