You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able dispatch tsc -w (typescript compiler watch mode) in the background and get automatic updates in the quickfix window as new errors come and go.
Is it possible to achieve this using vim-dispatch? Perhaps with a little bit of extra scripting?
A :w[rite] in vim usually triggers a tool with a watch mode. Since vim has the autocmd BufWritePost we can immediately fire :Make in vim without needing a watch mode.
Example: cpp project using cmake with my default compilation during development in _builds/debug:
It is important that make has the option -C to run make from the pwd of vim which does not agree with the build directory for cmake's out-of-source build directories (see also https://mesonbuild.com/).
Similar to vimtex, autocmd which fires :Make on save is not active by default. Only after pressing <leader>ll which also invokes a first run of :Make
function!ToggleMakeOnSaveForCurrentFT()
letl:augroupname='make_on_save_'.&ftexecute("if !exists('#".l:augroupname."#BufWritePost')")
callEnableMakeOnSaveForCurrentFT()
execute('Make')
elseexecute("augroup ".l:augroupname)
autocmd!redrawechom"Make on BufWritePost for ".&ft." not active"augroupENDendifendfunctionfunction!EnableMakeOnSaveForCurrentFT()
letl:augroupname='make_on_save_'.&ftexecute("if !exists('#".l:augroupname."#BufWritePost')")
execute("augroup ".l:augroupname)
autocmd!silentexecute("au BufWritePost * if &ft ==# '".&ft."' | execute('Make') | endif")
redraw" required to avoid loosing the messageechom"Make on BufWritePost for ".&ft." active (makeprg=".&mp.")"augroupENDendifendfunction
If you want to go one step further, you could immediately activate the autocmd if the vim-projectionist heuristics worked out with
augroupmyprojectionistautocmd!autocmdUserProjectionistActivatecalls:activate()
augroupENDfunction!s:activate() abortfor [root, value] inprojectionist#query('make')
if &ft==# 'cpp'callEnableMakeOnSaveForCurrentFT()
endifbreakendforendfunction
Btw one can replace vim-dispatch :Make with neomake:NeomakeProject (this does not open a window, offers support for feedback via the statusline).
Activity
kiryph commentedon Jun 5, 2019
There are also other build tools with a watch mode, e.g.
latexmk -pvcorwatchman-make.My current take on this is similar to vimtex:
Run
:Makeon saveA
:w[rite]in vim usually triggers a tool with a watch mode. Since vim has the autocmd BufWritePost we can immediately fire:Makein vim without needing a watch mode.Example: cpp project using cmake with my default compilation during development in
_builds/debug:The following vim setup runs
:Make -j8(4 cores with hyperthreading, hence 8 jobs) whenever I save a*.cppor*.hfile.Using vim-projectionist heuristics to find my preferred Makefile to run
It is important that make has the option
-Cto run make from the pwd of vim which does not agree with the build directory for cmake's out-of-source build directories (see also https://mesonbuild.com/).Similar to vimtex, autocmd which fires
:Makeon save is not active by default. Only after pressing<leader>llwhich also invokes a first run of:MakeIf you want to go one step further, you could immediately activate the autocmd if the vim-projectionist heuristics worked out with
Btw one can replace vim-dispatch
:Makewith neomake:NeomakeProject(this does not open a window, offers support for feedback via the statusline).