2013-05-03 82 views
3

我使用Vim/gVim進行javascript(節點)編程。我的jslint在我的文件類型插件中作爲makeprg進行了連接。這裏的錯誤格式運用於:在Vim中調整/對齊errorformat輸出

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 

這裏是輸出到quickfix窗口:

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。是否可以有條件地填充輸出?

回答

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 
+0

那麼怎麼樣!你搖滾,很好的答案。現在來溝通那個perl來看魔術...... – regretoverflow 2013-05-04 19:08:22

+0

對不起,我重寫了我醜陋的單線性腳本。新的可能比這更清晰。 – ernix 2013-12-23 07:37:27

2

合理的數字肯定會很好,但我認爲這需要Vim的源代碼補丁。

quickfix窗口中的信息來自Vim的內部數據結構(格式參見:help getqflist()),Vim決定如何將其可視化。

+0

感謝,因爲夜深了,我周圍挖,實現了錯誤格式運用於字符串就是你如何提取從makeprg輸出信息,但什麼都不做格式化輸出 – regretoverflow 2013-05-03 16:48:53