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









