Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vim-8.0] quickfix or locationlist steal focus after save #1073

Closed
achilleas-k opened this issue Oct 4, 2016 · 7 comments
Closed

[vim-8.0] quickfix or locationlist steal focus after save #1073

achilleas-k opened this issue Oct 4, 2016 · 7 comments

Comments

@achilleas-k
Copy link

Actual behavior

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.

Expected behavior

Quickfix or location list should appear and not steal focus (or it should be optional).

Steps to reproduce:

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.

Configuration

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']
@fatih
Copy link
Owner

fatih commented Oct 4, 2016

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

@achilleas-k
Copy link
Author

Not at all familiar with vimscript but I'll have a poke.

@achilleas-k
Copy link
Author

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.

@fatih fatih added the vim-8.0 label Oct 5, 2016
@achilleas-k
Copy link
Author

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.

@thsnr
Copy link
Contributor

thsnr commented Jan 4, 2017

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.

@tstromberg
Copy link

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

@fatih
Copy link
Owner

fatih commented May 27, 2017

This is fixed with #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants