3

我使用 Vim/gVim 在 javascript (node) 中进行编程。我在我的文件类型插件中将 jslint 连接为 makeprg。这是错误格式:

efm=%-P%f,
        \%A%>%\\s%\\?#%*\\d\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
        \%-G%f\ is\ OK.,%-Q

这是 jslint 的输出:

routes/pcr.js
#1 'db' was used before it was defined.
db.collection('pcrs', function (err, collection) { // Line 11, Pos 5
#2 'db' was used before it was defined.
db.collection('pcrs', function (err, collection) { // Line 23, Pos 5
#3 'BSON' was used before it was defined.
collection.findOne({'_id': new BSON.ObjectID(id)}, function (err, item) { // Line 24, Pos 40

这是快速修复窗口的输出:

routes/pcr.js|11 col 5| 'db' was used before it was defined.
routes/pcr.js|23 col 5| 'db' was used before it was defined.
routes/pcr.js|24 col 40| 'BSON' was used before it was defined.

在列号之后,我想将其保留为 2 位数字(我希望文件的错误不超过 99 个!),使其看起来像:

routes/pcr.js|11 col  5| 'db' was used before it was defined.
routes/pcr.js|23 col  5| 'db' was used before it was defined.
routes/pcr.js|24 col 40| 'BSON' was used before it was defined.

我想这也会影响行号 0-9。是否可以有条件地填充输出?

4

2 回答 2

2

合理的数字肯定会很好,但我认为这需要 Vim 的源代码补丁。

quickfix 窗口中的信息来自 Vim 的内部数据结构(:help getqflist()格式参见 参考资料),Vim 决定如何将其可视化。

于 2013-05-03T06:38:13.550 回答
1

:help quickfix-window提到重新格式化错误列表。

以下设置适用于我(更新):

au BufRead quickfix setl modifiable
            \| silent exe "%!perl -ple '
                \my ($file, $pos, $msg) = split qr{[|]}, $_, 3;
                \my $aligned_pos = sub {
                \  my @p = split qr{[ ]}, shift;
                \  return                                        if @p == 0;
                \  return sprintf q{\\%3s}, @p                   if @p == 1;
                \  return sprintf q{\\%3s \\%s}, @p              if @p == 2;
                \  return sprintf q{\\%3s \\%s \\%2s}, @p        if @p == 3;
                \  return sprintf q{\\%3s \\%s \\%2s \\%-8s}, @p if @p == 4;
                \  return join q{ }, @p;
                \}->($pos);
                \$_ = join q{|}, $file, $aligned_pos, $msg;
            \'"
            \| setl nomodifiable
于 2013-05-04T04:55:24.320 回答