Vim errorformat
Asked Answered
A

1

10

I read the docs, but got even more confused.
I have the following error generated by the compiler:

          rot;
          ^
"cpp\c1.cpp", line 13: error(114): identifier
          "rot" is undefined


1 error detected in the compilation of "c1.cpp".

I know how to detect the line where the error line is given, but I get loads of extra useless info in my errorlist, and the error message is split in two lines, whcih i would prefer to merge.

My starting errorformat is:

:set efm=\"%f\"\\,\ line\ %l:\ error(%n):\ %m

Since we are at it, is there a quick way of testing the efm without resorting to run make all the time?

Amery answered 6/10, 2009 at 12:47 Comment(1)
What sort of stuff is the useless info? Is it stuff from the actual compiler error output that is mistakenly grabbed by one of the specifiers? That might explain the two-line message, too? In case this is helpful, the default value, taken from the source (I couldn't find it in the help): "%f>%l:%c:%t:%n:%m,%f:%l: %t%*\\D%n: %m,%f %l %t%*\\D%n: %m,%*[^\"]\"%f\"%*\\D%l: %m,%f:%l:%m,%f|%l| %m"Olden
A
28

First of all, I talk about debugging. Unfortunately, there's no particularly easy way of doing it, but one useful possibility is to run make and spit the output into a file and then:

:let &makeprg="cat ~/outputfile.log"
:make

Regarding making the errorformat, this does require a bit of trial and error. You can use %A, %C and %Z for multiline messages and you can use %-G to ignore stuff. The order is very important and note that sometimes the %C or even %Z come before the %A! In your case, you may be able to get somewhere with the efm below. I tend to use let &efm = and let &efm .= rather than set as you don't have to escape every space or quotation mark and you can build it up gradually. It's also much more readable.

" Start of the multi-line error message (%A),
" %p^ means a string of spaces and then a ^ to
" get the column number
let &efm  = '%A%p^' . ','
" Next is the main bit: continuation of the error line (%C)
" followed by the filename in quotes, a comma (\,)
" then the rest of the details
let &efm .= '%C"%f"\, line %l: error(%n): %m' . ','
" Next is the last line of the error message, any number
" of spaces (' %#': equivalent to ' *') followed by a bit
" more error message
let &efm .= '%Z %#%m' . ','
" This just ignores any other lines (must be last!)
let &efm .= '%-G%.%#'
Abduction answered 6/10, 2009 at 18:7 Comment(3)
+1 for the debug hint. On windows, where cat utility is unavailable, one may use :let &makeprg="type outputfile.log"Erysipeloid
Depending on where you're changing efm, you may want to use let &l:efm= instead of let &efm= to get setlocal-equivalent behavior. I'm especially thinking about in a filetype plugin or similar vim file.Bristle
Turns out that this is the first really good reason to use spaces instead of tabs in my C++ code, If you use tabs and the compiler output uses tabs, the %p^ will fail :(Dortch

© 2022 - 2024 — McMap. All rights reserved.