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
posted @   zjh6  阅读(25)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示