From 456378cb53dbf38ff0077b8f41894bbdc7c9671e Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 20 Aug 2017 15:59:18 +0100 Subject: #653 - Jump to the position which Vim does not jump to for moving from quickfix/loclist items to other buffers --- autoload/ale/events.vim | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'autoload') diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index c84954c1..2ee7f86a 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -60,10 +60,40 @@ function! s:HitReturn(...) abort if get(split(l:output, "\n"), -1, '') =~# '^E92[456]' call ale#util#FeedKeys("\", '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 -- cgit v1.2.3