0
点赞
收藏
分享

微信扫一扫

vim的make构建工具


​make​​是同步工具,可丢弃了.

可用​​:h:terminal​​或​​:h term_start()​​在​​vim​​中异步.这里用​​term_start​​.

​​Make位置​​

目标

1,异步​​make​​,​​quickfix​​后更新,用户可像终端中的​​make​​一样,看到​​make​​的进度.

2,如果正确,则显示​​成功make消息​​,不会警告.

3,如果存在具特定​​缓冲区号和行号​​的​​quickfix​​项,显示​​found n qf entries​​.

4,如果用户在​​构建​​时,请求构建,则切换​​make​​缓冲.

5,如果用户在​​空闲​​时构建,请求,则​​删除​​上个​​构建缓冲​​.

接口

nnoremap <f7> :Make<cr>
command -nargs=* Make call s:make(<q-args>)

生成异步作业

let s:making = 0

function s:make(args) abort

if s:making
if bufwinid(s:make_buf) == -1
"显示构建缓冲"
exe "sbuffer" s:make_buf
wincmd p
else
"隐藏构建"
exe printf("%d wincmd q", bufwinnr(s:make_buf))
endif
return
endif

" 删上个结果"
if exists("s:make_buf") && bufexists(s:make_buf)
silent! exe "bdelete" s:make_buf
endif

"产生新造"
let cmd = "make"
if !empty(a:args)
let cmd .= " " . a:args
endif

let options = {"close_cb": function("s:make_callback"), "term_rows": 16}

let s:make_buf = term_start(cmd, options)
let s:making = 1

wincmd p

endfunction

微妙的处理器

func s:make_callback(channel)

"不能直接取"
call timer_start(10, function("s:make_callback_impl"))
endfunction

function s:make_callback_impl(timer) abort

exe "cgetbuffer" s:make_buf

"考虑行号,缓冲号"
let qfl = filter(getqflist(), {k,v -> v.bufnr != 0 && v.lnum != 0})

if empty(qfl)
echo "构建成功"
else
echohl WarningMsg
echom printf("found %d qf entries", len(qfl))
echohl None
endif

let s:making = 0



举报

相关推荐

0 条评论