I found AsyncCommand on StackOverflow, and found it is a terrific tool! I am trying to get it work with errormarker plugin, but encountered some problem.
i don’t know exactly what the problem is. I traced errormarker’s script, and found error use following script to hook QuickFixCmdPost to event, and set markers to lines of source files.
augroup errormarker
autocmd QuickFixCmdPost make call <SID>SetErrorMarkers()
augroup END
According to the :help, the second argument(make) is the pattern of the file(for example: *.html). I don’t what is a make file pattern, I tried
autocmd QuickFixCmdPost AsyncMake call <SID>SetErrorMarkers()
It does not work(sure). But I don’t know what else I can do. I do googled “AsyncCommand errormarker” but get nothing.
Is there are any comment? Any suggestion is appreciated. Thanks in advance.
I found a solution.
The solution works, but ugly.
The key is to call
errormarker‘sSetErrorMarkers()function at the right time automatically.I tried Peter Rincker’s solution, but it turns out the
AsyncCommandQuickFixCmdPostfired too early. The quickfix list is not set yet. SoSetErrorMarkers()does nothing.I read some
AsyncCommand‘s manual and traced some code, theAsyncMakeis actually a wrapper, which invokewith
So, since
asynchandler#qfcan be called at the right time, I traced the call point of theasynchandler#qf, and find the functionasynccommand#donein fileasynccommand.vimline 92 call theasynchandler#qf.Got you!
Let’s add some code at line 101 to invoke the
SetErrorMarkers()functionNotice the function we called here is
ExposeSetErrorMarkers()notSetErrorMarkers(). Because theSetErrorMarkers()is a script local function, can not be called from outside of the script. so I add a delegate functionExposeSetErrorMarkers()inerrormarker.vimto expose that function.Moreover, I add some auto commands to my
.vimrcto invoke AsyncMake automatically every time I save my source file.
It works! Ugly, though 😛