summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/loclist_jumping.vim13
-rw-r--r--doc/ale.txt7
-rw-r--r--plugin/ale.vim4
-rw-r--r--test/test_loclist_jumping.vader (renamed from test/test_loclist_jumping_loading.vader)25
4 files changed, 47 insertions, 2 deletions
diff --git a/autoload/ale/loclist_jumping.vim b/autoload/ale/loclist_jumping.vim
index 58fb8638..88ed4c97 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 45fe4902..9949d150 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 |<Plug>| mappings are defined for the commands: >
<Plug>(ale_previous) - ALEPrevious
<Plug>(ale_previous_wrap) - ALEPreviousWrap
<Plug>(ale_next) - ALENext
<Plug>(ale_next_wrap) - ALENextWrap
+ <Plug>(ale_first) - ALEFirst
+ <Plug>(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 25622318..40e1a363 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 <silent> <Plug>(ale_previous) :ALEPrevious<Return>
nnoremap <silent> <Plug>(ale_previous_wrap) :ALEPreviousWrap<Return>
nnoremap <silent> <Plug>(ale_next) :ALENext<Return>
nnoremap <silent> <Plug>(ale_next_wrap) :ALENextWrap<Return>
+nnoremap <silent> <Plug>(ale_first) :ALEFirst<Return>
+nnoremap <silent> <Plug>(ale_last) :ALELast<Return>
nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return>
nnoremap <silent> <Plug>(ale_lint) :ALELint<Return>
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
diff --git a/test/test_loclist_jumping_loading.vader b/test/test_loclist_jumping.vader
index 9da5bd5f..13eac5ce 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])