With the current vim-8.0 branch, after saving a file, linting begins in the background (async). If there are errors, the quickfix or location-list buffer appears and the cursor moves into the new split. This is especially bad with the new async feature, since the user is free to continue typing or move around the file while linting is running in the background (which can take a few seconds) and the focus stealing interrups flow.
Quickfix or location list should appear and not steal focus (or it should be optional).
Reproducible with minimal vimrc file. Only vim-go installed. Just save a go file with an error that would be caught by an active linter.
vim version: 8.0
vim-go version: vim-8.0 head (29196e5cb81793983c6838fbf15871c9298c35ff)
Configuration:
let g:go_metalinter_enabled = ['go', 'vet', 'golint', 'errcheck']
let g:go_metalinter_autosave = 1
let g:go_metalinter_autosave_enabled = ['go', 'vet', 'golint', 'errcheck']
Hi @achilleas-k
I agree, but I couldn't find a solution for that. Even though I say don't jump, Vim still jumps :) If you find something let me know
Not at all familiar with vimscript but I'll have a poke.
Well, I managed to hack up a workaround, at least for the quickfix window (not sure about location list).
From this SO solution, the following does prevent the qf window from stealing focus:
augroup quickfix
autocmd!
autocmd Syntax qf wincmd p
augroup END
The problem then becomes that the cursor jumps to the beginning of the file when qf opens.
So after that, I wrapped copen in a winview save and restore. The entire callback in the lint_job function now looks like this:
function! s:callback(chan, msg) closure
let old_errorformat = &errorformat
let &errorformat = l:errformat
caddexpr a:msg
let &errorformat = old_errorformat
" TODO(arslan): cursor still jumps to first error even If I don't want
" it. Seems like there is a regression somewhere, but not sure where.
augroup quickfix
autocmd!
autocmd Syntax qf wincmd p
augroup END
let winview=winsaveview()
copen
call winrestview(winview)
endfunction
and it works as expected.
I suspect the augroup quickfix block can be set somewhere globally instead of running every time, though.
Discovered now that for some reason (I guess from the opening of the qf window), the main buffer is set to nomodifiable, so I added a set modifiable after the call winrestview(winview) line.
This is definitely getting dirtier but I hope it points in the right direction.
It seems to me, that instead of hooking an autocmd to syntax being set to qf, it is a lot simpler to just add wincmd p after copen in the callback.
function! s:callback(chan, msg) closure
let old_errorformat = &errorformat
let &errorformat = l:errformat
caddexpr a:msg
let &errorformat = old_errorformat
" TODO(arslan): cursor still jumps to first error even If I don't want
" it. Seems like there is a regression somewhere, but not sure where.
copen
wincmd p " the cursor jumped to qf: go back to the active window
endfunction
In my quick local tests this seemed to work. It also preserves the cursor position and modifiable option of the buffer.
I can confirm that thsnr's one-line patch (wincmd p) fixes this issue for me in the following vim build:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 07 2017 03:33:23)
Included patches: 1-197, 322, 377-378
This is fixed with https://github.com/fatih/vim-go/pull/1293. Please pull the latest master branch to test it (note that master is development branch) or wait until the next stable release. Thanks for all the feedback.
Most helpful comment
It seems to me, that instead of hooking an autocmd to
syntaxbeing set toqf, it is a lot simpler to just addwincmd paftercopenin the callback.In my quick local tests this seemed to work. It also preserves the cursor position and
modifiableoption of the buffer.