From 33b0852c84452afbaf0f41c2abc954008be7ef77 Mon Sep 17 00:00:00 2001 From: Drew Neil Date: Sat, 3 Jun 2017 12:45:52 +0100 Subject: [PATCH] Add :ALEFirst and :ALELast commands (#616) * Add :ALEFirst and :ALELast commands * Add documentation for ALEFirst and ALELast commands * Add tests for ale#loclist_jumping#JumpToIndex() * Fix the loclist jumping tests --- autoload/ale/loclist_jumping.vim | 13 ++++++++++ doc/ale.txt | 7 ++++++ plugin/ale.vim | 4 +++ ...ading.vader => test_loclist_jumping.vader} | 25 +++++++++++++++++-- 4 files changed, 47 insertions(+), 2 deletions(-) rename test/{test_loclist_jumping_loading.vader => test_loclist_jumping.vader} (68%) diff --git a/autoload/ale/loclist_jumping.vim b/autoload/ale/loclist_jumping.vim index 58fb863..88ed4c9 100644 --- a/autoload/ale/loclist_jumping.vim +++ b/autoload/ale/loclist_jumping.vim @@ -64,3 +64,16 @@ function! ale#loclist_jumping#Jump(direction, wrap) abort call cursor(l:nearest) endif endfunction + +function! ale#loclist_jumping#JumpToIndex(index) abort + let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []}) + let l:loclist = l:info.loclist + if empty(l:loclist) + return + endif + + let l:item = l:loclist[a:index] + if !empty(l:item) + call cursor([l:item.lnum, l:item.col]) + endif +endfunction diff --git a/doc/ale.txt b/doc/ale.txt index 45fe490..9949d15 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -857,6 +857,8 @@ ALEPrevious *ALEPrevious* ALEPreviousWrap *ALEPreviousWrap* ALENext *ALENext* ALENextWrap *ALENextWrap* +ALEFirst *ALEFirst* +ALELast *ALELast* *ale-navigation-commands* Move between warnings or errors in a buffer. ALE will only navigate between @@ -867,11 +869,16 @@ ALENextWrap *ALENextWrap* `ALEPreviousWrap` and `ALENextWrap` will wrap around the file to find the last or first warning or error in the file, respectively. + `ALEFirst` goes the the first error or warning in the buffer, while `ALELast` + goes to the last one. + The following || mappings are defined for the commands: > (ale_previous) - ALEPrevious (ale_previous_wrap) - ALEPreviousWrap (ale_next) - ALENext (ale_next_wrap) - ALENextWrap + (ale_first) - ALEFirst + (ale_last) - ALELast < For example, these commands could be bound to the keys Ctrl + j and Ctrl + k: > diff --git a/plugin/ale.vim b/plugin/ale.vim index 2562231..40e1a36 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -311,6 +311,8 @@ command! -bar ALEPrevious :call ale#loclist_jumping#Jump('before', 0) command! -bar ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1) command! -bar ALENext :call ale#loclist_jumping#Jump('after', 0) command! -bar ALENextWrap :call ale#loclist_jumping#Jump('after', 1) +command! -bar ALEFirst :call ale#loclist_jumping#JumpToIndex(0) +command! -bar ALELast :call ale#loclist_jumping#JumpToIndex(-1) " A command for showing error details. command! -bar ALEDetail :call ale#cursor#ShowCursorDetail() @@ -338,6 +340,8 @@ nnoremap (ale_previous) :ALEPrevious nnoremap (ale_previous_wrap) :ALEPreviousWrap nnoremap (ale_next) :ALENext nnoremap (ale_next_wrap) :ALENextWrap +nnoremap (ale_first) :ALEFirst +nnoremap (ale_last) :ALELast nnoremap (ale_toggle) :ALEToggle nnoremap (ale_lint) :ALELint nnoremap (ale_detail) :ALEDetail diff --git a/test/test_loclist_jumping_loading.vader b/test/test_loclist_jumping.vader similarity index 68% rename from test/test_loclist_jumping_loading.vader rename to test/test_loclist_jumping.vader index 9da5bd5..13eac5c 100644 --- a/test/test_loclist_jumping_loading.vader +++ b/test/test_loclist_jumping.vader @@ -13,9 +13,14 @@ Before: \ }, \} - function! TestJump(direction, wrap, pos) + function! TestJump(position, wrap, pos) call cursor(a:pos) - call ale#loclist_jumping#Jump(a:direction, a:wrap) + + if type(a:position) == type(0) + call ale#loclist_jumping#JumpToIndex(a:position) + else + call ale#loclist_jumping#Jump(a:position, a:wrap) + endif return getcurpos()[1:2] endfunction @@ -53,3 +58,19 @@ Execute(loclist jumping not jump when the loclist is empty): AssertEqual [1, 6], TestJump('before', 1, [1, 6]) AssertEqual [1, 6], TestJump('after', 0, [1, 6]) AssertEqual [1, 6], TestJump('after', 1, [1, 6]) + +Execute(We should be able to jump to the last item): + AssertEqual [2, 8], TestJump(-1, 0, [1, 6]) + +Execute(We shouldn't move when jumping to the last item where there are none): + let g:ale_buffer_info[bufnr('%')].loclist = [] + + AssertEqual [1, 6], TestJump(-1, 0, [1, 6]) + +Execute(We should be able to jump to the first item): + AssertEqual [1, 2], TestJump(0, 0, [1, 6]) + +Execute(We shouldn't move when jumping to the first item where there are none): + let g:ale_buffer_info[bufnr('%')].loclist = [] + + AssertEqual [1, 6], TestJump(0, 0, [1, 6])