Vim:错误格式匹配所有内容

发布于 2024-09-19 06:09:37 字数 748 浏览 4 评论 0原文

我试图将以下错误与 efm 匹配:

AssertionError: 1 == 2
    at /home/strager/projects/blah/blah.js:13:37

错误消息可以是任何内容(即它并不总是与 AssertionError: .*.*Error: .* 格式匹配)。一般格式为:

errormessage
    at filename:line:column

我的问题是错误消息与任意行匹配;我需要将错误消息限制为仅一行,并且仅在其后跟匹配的“at”行时才匹配。

我尝试过以下efm

set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m
" %Z    at %f:%l:%c,%E%m

这几乎可以工作,但除了错误之外,它还匹配状态行(例如,错误之前和之后的非错误)。如何强制 %E%m ... %Z 总共只有两行(一行用于错误消息,一行用于 at 行)?如果需要,我可以使用 makeprg 的标准 UNIX 工具。

I am trying to match the following error with efm:

AssertionError: 1 == 2
    at /home/strager/projects/blah/blah.js:13:37

The error message can be anything (i.e. it doesn't always match the AssertionError: .* or .*Error: .* formats). The general format is:

errormessage
    at filename:line:column

My problem is that the error message matches any line; I need to restrict the error message to one line only, and only match if it's followed by a matching "at" line.

I have tried the following efm:

set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m
" %Z    at %f:%l:%c,%E%m

This almost works, but it matches status lines (e.g. non-errors before and after the error) in addition to the errors. How can I force %E%m ... %Z to be only two lines total (one for the error message, and one for the at line)? I have access to the standard UNIX tools for makeprg if needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

神仙妹妹 2024-09-26 06:09:37

这有效吗?

set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m,%-G%.%#

%-G%.%# 告诉 vim 忽略与其他模式不匹配的整行。

Does this work?

set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m,%-G%.%#

The %-G%.%# tells vim to ignore entire lines that do not match the other patterns.

债姬 2024-09-26 06:09:37

您真的想花时间学习一种在其他地方没有应用的晦涩模式语言吗?除非有人付钱让你编写 vim 编译器插件,否则我不会(而且我喜欢 vim!)。既然您愿意打开工具箱,只需在检查器周围编写一个包装器并输出易于解析的格式即可。例如:

#!/usr/bin/perl
use warnings;
use strict;

open my $fh, '-|', 'compiler', @_ or die $!;

my $last_line = <$fh> // exit;
while (defined(my $line = <$fh>)) {
    my($file, $l, $c) = $line =~ /^    at (.+?):(\d+):(\d+)$/;
    print "$file:$l:$c: $last_line" if defined($file);
    $last_line = $line;
}

Do you really want to spend your time learning an obscure pattern language that has no application anywhere else? Unless someone is paying you to write vim compiler plug-ins, I wouldn't (and I love vim!). Since you're willing to open the toolbox, just write a wrapper around your checker and spit out an easy-to-parse format. Eg:

#!/usr/bin/perl
use warnings;
use strict;

open my $fh, '-|', 'compiler', @_ or die $!;

my $last_line = <$fh> // exit;
while (defined(my $line = <$fh>)) {
    my($file, $l, $c) = $line =~ /^    at (.+?):(\d+):(\d+)$/;
    print "$file:$l:$c: $last_line" if defined($file);
    $last_line = $line;
}
江南月 2024-09-26 06:09:37

怎么样...

set efm=%E%m,%Z\ \ \ \ at\ %f:%l:%c

What about ...

set efm=%E%m,%Z\ \ \ \ at\ %f:%l:%c
冷…雨湿花 2024-09-26 06:09:37

也许

set efm=%E%>%m,%Z\ \ \ \ at\ %f:%l:%c

检查这个

:help efm%>

Maybe

set efm=%E%>%m,%Z\ \ \ \ at\ %f:%l:%c

Check this

:help efm%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文