开发者

Vim script: How to easily pipe data into the cwindow

I use a custom function (currently residing in .vimrc) and not :make or another direct command line tool to compile/check my currently edited file for errors. Like this:

function! CompileMyCode(...)
    set errorformat=Error:\ %m\\,\ in\ line\ %l
    let l:output = "Error: bad code!, in line 9"
    return l:output
endfunction
command! -nargs=* CompileMyCode :call CompileMyCode(<f-args>)

when using the new command in command mode, no error window shows up.

:CompileMyCode | cwindow

What am I doing wrong?

Edit: I now tried the following which also does not open any cwindow.

function! CompileMyCode(...)
    set errorformat=Error:\ %m\\,\ in\ line\ %l
    let l:output = "Error: bad code!, in line 9"
    " I tried both of the following lines separately
    cexpr l:output 
    call setqflist([l:output])
endfunction

The proposed commands cexpr and setqflist() do not open the cwi开发者_开发知识库ndow correctly in my example. Maybe somebody can propose a complete solution?

Edit 2:

The main problem is solved. Here is my current code:

    let l:result = expand("%").'|8| errortext'
    cexpr [ l:result, l:result ]
    caddexpr ''
    cwindow

This example respects a default error format that vim seems to support. When cexpring the actual error output and using an errorformat the cwindow seems to ignore that.

Nevertheless, I wanted stick to a default error format anyway in the output, not having to rely on a custom errorformat

Thx for your answers!


I did something similar using cexpr l:output instead of returning the string and that placed the output of the compile in the quickfix window. You can see my vim function here: http://www.zenskg.net/wordpress/?p=199

Update

Adding a blank line to the quickfix list seems to allow the cwindow to appear. For example:

function! MyCompile()
  let l:output = "Error: line 1"
  cexpr l:output
  caddexpr ""
  cwindow
endfunction


If you already have access to the error information as structured data in Vim (or can easily obtain it), you can use setqflist().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜