How to get vim to parse my multi-line error message for quickfix window?

I want to run my application under vim using make , and I want the quickfix window quickfix display my errors.

So, I have this format, which starts with Error: , and then filename, row and column, separated by : and then on the next line there will be a multiline message without special formatting, then the message will end with ErrorEnd .

So here is an example:

 Error: /somefile/something/something.c:12:123 SOME MESSAGE ANOTHER HELPFUL MESSAGE ANOTHER MESSAGE ErrorEnd 

I kind of lost in the documentation how to make it fit these lines. Everything seems so confusing, and the examples are not like these. I know how to make it match the first line, but I don’t know how to make it match the following lines as an error message. So the question is what will be the errorformat string that could parse all this.

+4
source share
3 answers

You can capture multiple lines of text in the error message using the %+ prefix, as described in :help efm-ignore , in combination with the multi-line error format specifier %E , %C , %Z , etc. described in :help errorformat-multi-line . In your specific example, the following works:

 let &l:efm='%EError: %f:%l:%c,%-ZErrorEnd,%+C%.%#' 

Notice the %+C element that matches any text in the line and adds it to the error message. Also, pay attention to how I had to place the %-Z element in front of this element to be used, since the first syntax errorformat element will be used when parsing the string.

+1
source

On the help page, error error: vim:

 Multi-line messages *errorformat-multi-line* It is possible to read the output of programs that produce multi-line messages, ie error strings that consume more than one line. Possible prefixes are: %E start of a multi-line error message %W start of a multi-line warning message %I start of a multi-line informational message %A start of a multi-line message (unspecified type) %> for next line start with current pattern again |efm-%>| %C continuation of a multi-line message %Z end of a multi-line message These can be used with '+' and '-', see |efm-ignore| below. Using "\n" in the pattern won't work to match multi-line messages. Example: Your compiler happens to write out errors in the following format (leading line numbers not being part of the actual output): 1 Error 275 2 line 42 3 column 3 4 ' ' expected after '--' The appropriate error format string has to look like this: :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m 

Edit: Do you mean a multi-line error. Right. This is harder.

+4
source

You are correct, parsing multi-line error messages for quickfix is ​​difficult. I'm not even sure that you can parse errors in such a block as individual errors.

The workaround I used to cumbersome error output is to add a transformation step (usually using sed ) to 'makeprg' , which converts multi-line errors to traditional single-line messages per error; sort of

 Error: /somefile/something/something.c:12:123 SOME MESSAGE Error: /somefile/something/something.c:12:123 ANOTHER HELPFUL MESSAGE Error: /somefile/something/something.c:12:123 ANOTHER MESSAGE 

in your case.

+3
source

Source: https://habr.com/ru/post/1490606/


All Articles