繁体   English   中英

如何让vim解析quickfix窗口的多行错误信息?

[英]How to make vim parse my multi-line error message for the quickfix window?

我想使用make在vim下运行我的应用程序,我希望quickfix窗口显示我的错误。

所以我有这种格式,首先以Error:开头Error:然后文件名,行和列分隔:然后在下一行,这将是一个没有特殊格式的多行消息,然后消息将以ErrorEnd结束。

所以这是一个例子:

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

我在文档中迷失了如何使它与这些线匹配。 一切看起来都很混乱,例子不像这个。 我知道如何使它与第一行匹配,但不知道如何使它与下一行匹配作为错误消息。 所以问题是什么是一个可以解析它的errorformat字符串。

从vim errorformat帮助页面:

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

编辑:啊,你的意思是多行错误。 对。 那更难。

你是对的,解析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

在你的情况下。

您可以使用%+前缀捕获错误消息中的多行文本,如下所述:help efm-ignore结合多行错误格式说明符%E%C%Z等描述于:help errorformat-multi-line 在您的具体示例中,以下似乎有效:

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

请注意与该行上的任何文本匹配的%+C项,并将其添加到错误消息中。 另请注意我必须将%-Z项放在此项之前才能使用它,因为在解析该行时将使用第一个匹配的errorformat项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM