2013-07-10 48 views
4

我想使用make在vim下運行我的應用程序,並且我希望quickfix窗口顯示我的錯誤。如何讓vim解析我的quickfix窗口的多行錯誤信息?

所以我有這種格式,它首先以Error:開頭,然後用:分隔文件名,行和列,然後在下一行中會有一個沒有特殊格式的多行消息,然後消息將以ErrorEnd

所以這裏有一個例子:

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

我有點失去了文檔中如何使它符合這些線路。一切似乎都很混亂,而且這些例子並不是這樣的。我知道如何使它匹配第一行,但不知道如何使它與下一行匹配成爲錯誤消息。所以問題是什麼可以解析所有的錯誤格式字符串。

回答

1

可以通過使用如在:help efm-ignore結合多行的錯誤格式運用於符%E%C%Z等在:help errorformat-multi-line描述中描述的%+前綴捕獲錯誤消息多行文本。在您的具體的例子,下面似乎工作:

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

注意%+C項目相匹配線路上的任何文字並將其添加到錯誤消息。請注意,我必須將%-Z項目放在這個項目之前才能使用它,因爲解析該行時將使用第一個匹配的errorformat項目。

3

你說得對,解析quickfix的多行錯誤信息很困難。我甚至不確定是否有可能在個別的錯誤等塊中解析錯誤。

我爲難處理的錯誤輸出採用的解決方法是將轉換步驟(通常使用sed)附加到'makeprg',該轉換步驟將多行錯誤轉換爲傳統的每行錯誤消息;像

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 

你的情況。

+0

Yeap,這就是我在做什麼。希望有更多的支持這樣的錯誤。 –

4

從vim的錯誤格式運用於幫助頁面:

Multi-line messages    *errorformat-multi-line* 

It is possible to read the output of programs that produce multi-line 
messages, i.e. 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 

編輯:你丫的意思是多行錯誤。對。這更困難。

相關問題