How to highlight source in Emacs compilation-mode when compilation error occurs

1.3k Views Asked by At

I read the documentation about compilation-mode but I didn't find any technique to hightlight source code where a compilation error occurs.

For example change the background color of the source code that produces the compilation error (like the red underline in Eclipse or Netbeans). And also a way to read the error message somewhere.

2

There are 2 best solutions below

1
On BEST ANSWER

Normally, compilation mode will highlight the error message in the compiler output and you can use that to jump to the code. If you want your code syntax checked/highlighted you might want to look at flymake, which is supposed to be able to do exactly that.

0
On

Option next-error-highlight controls highlighting of compilation and grep hits in the source buffers. The possibilities for this are these:

  • highlight for a given time or until the next command
  • highlight until the next command or until next hit visit
  • do not highlight
  • show location in fringe -- which indication moves with the locus

If you use library simple+.el, then you have another possibility: highlight until the locus moves. This highlights, like the first two possibilities above, but the highlighting does not go away -- it just moves, like the last possibility above (fringe).

That sounds like what you want. (It is what I use.) For grep, for instance, the matching text is highlighted in the source file at the location you visit. It stays highlighted until you visit a different hit.

The same holds for the similar option next-error-highlight-no-select.

In addition, for grep and compilation to respect the new value provided by simple+.el, you will also need libraries grep+.el and compile+.el, respectively.