#653 - Jump to the position which Vim does not jump to for moving from quickfix/loclist items to other buffers

This commit is contained in:
w0rp
2017-08-20 15:59:18 +01:00
parent 47e681529b
commit 456378cb53
4 changed files with 98 additions and 2 deletions

View File

@@ -60,10 +60,40 @@ function! s:HitReturn(...) abort
if get(split(l:output, "\n"), -1, '') =~# '^E92[456]'
call ale#util#FeedKeys("\<CR>", 'n')
" If we hit one of the errors and cleared it, then Vim didn't
" move to the position we wanted. Change the position to the one
" the user selected.
if exists('g:ale_list_window_selection')
let l:pos = getcurpos()
let [l:pos[1], l:pos[2]] = g:ale_list_window_selection
call setpos('.', l:pos)
endif
endif
endif
" Always clear the last selection when trying to cancel the errors above
" here. This prevents us from remembering invalid positions.
unlet! g:ale_list_window_selection
endfunction
function! ale#events#BufWinLeave() abort
call timer_start(0, function('s:HitReturn'))
endfunction
" Grab the position for a problem from the loclist or quickfix windows
" when moving through selections. This selection will be remembered and
" set as the position when jumping to an error in another file.
function! ale#events#ParseLoclistWindowItemPosition() abort
" Parses lines like
" test.txt|72 col 5 error| ...
" test.txt|72| ...
let l:match = matchlist(getline('.'), '\v^[^|]+\|(\d+)( [^ ]+ )?(\d*)')
if !empty(l:match)
let g:ale_list_window_selection = [
\ l:match[1] + 0,
\ max([l:match[3] + 0, 1]),
\]
endif
endfunction