Hello,

I've put some spare time into an errorformat string and a filter script
which I think makes plain-old javac compilation (read: not using JUnit,
not using Ant) quite a bit nicer than the examples from :help
errorformat-javac, without being too heavy or complicated. I've tested
this with only Vim 7.0.122 on Linux, Sun Java 1.6.0, and only minimally
at that.

It correctly discovers the column number even if you use tabs in your
source code, doesn't fill the "error message" variable with extra crud,
shows the "symbol:" and "location:" lines in the quickfix window, but
properly skips over them when doing :cnext and :cprevious. Note that
"symbol:" and "location:" will appear above their related error message
in the quickfix window.

Here's the sed script to filter the output from javac. I named it
'vim-javac-filter' and placed it in my path.

        #!/bin/sed -f
        /\^$/s/\t/\ /g;/:[0-9]\+:/{h;d};/^[ \t]*\^/G;

In English, that sed script:
 - Changes tabs to spaces and
 - Moves the line with the filename, line number, error message to just
   after the pointer line. That way, the extra gunk between doesn't
   break vim's notion of a "multi-line message" and also doesn't force
   us to include that gunk as a "continuation of a multi-line message."

Here's the corresponding efm:

        :setlocal errorformat=%Z%f:%l:\ %m,%A%p^,%-G%*[^sl]%.%#

To make it work using ":make":

        :setlocal makeprg=javac\ %\ 2>&1\ \\\|\ vim-javac-filter

Enjoy,
-Mike

Reply via email to