mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/vim-go/autoload/go/list.vim

127 lines
3.2 KiB
VimL
Raw Normal View History

2016-02-20 08:13:10 -05:00
if !exists("g:go_list_type")
2016-06-26 07:12:36 -04:00
let g:go_list_type = ""
2016-02-20 08:13:10 -05:00
endif
" Window opens the list with the given height up to 10 lines maximum.
2015-12-08 08:20:04 -05:00
" Otherwise g:go_loclist_height is used. If no or zero height is given it
" closes the window
2016-02-20 08:13:10 -05:00
function! go#list#Window(listtype, ...)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
" we don't use lwindow to close the location list as we need also the
" ability to resize the window. So, we are going to use lopen and lclose
" for a better user experience. If the number of errors in a current
" location list increases/decreases, cwindow will not resize when a new
" updated height is passed. lopen in the other hand resizes the screen.
if !a:0 || a:1 == 0
if l:listtype == "locationlist"
lclose
else
cclose
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
return
endif
2015-12-08 08:20:04 -05:00
2016-06-26 07:12:36 -04:00
let height = get(g:, "go_list_height", 0)
if height == 0
" prevent creating a large location height for a large set of numbers
if a:1 > 10
let height = 10
2016-02-20 08:13:10 -05:00
else
2016-06-26 07:12:36 -04:00
let height = a:1
2016-02-20 08:13:10 -05:00
endif
2016-06-26 07:12:36 -04:00
endif
if l:listtype == "locationlist"
exe 'lopen ' . height
else
exe 'copen ' . height
endif
2015-12-08 08:20:04 -05:00
endfunction
" Get returns the current list of items from the location list
2016-02-20 08:13:10 -05:00
function! go#list#Get(listtype)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
return getloclist(0)
else
return getqflist()
endif
2015-12-08 08:20:04 -05:00
endfunction
" Populate populate the location list with the given items
2016-02-20 08:13:10 -05:00
function! go#list#Populate(listtype, items)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
call setloclist(0, a:items, 'r')
else
call setqflist(a:items, 'r')
endif
2015-12-08 08:20:04 -05:00
endfunction
2015-12-16 08:53:53 -05:00
function! go#list#PopulateWin(winnr, items)
2016-06-26 07:12:36 -04:00
call setloclist(a:winnr, a:items, 'r')
2015-12-16 08:53:53 -05:00
endfunction
2015-12-08 08:20:04 -05:00
" Parse parses the given items based on the specified errorformat nad
" populates the location list.
2016-02-20 08:13:10 -05:00
function! go#list#ParseFormat(listtype, errformat, items)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat
2015-12-08 08:20:04 -05:00
2016-06-26 07:12:36 -04:00
" parse and populate the location list
let &errorformat = a:errformat
if l:listtype == "locationlist"
lgetexpr a:items
else
cgetexpr a:items
endif
2015-12-08 08:20:04 -05:00
2016-06-26 07:12:36 -04:00
"restore back
let &errorformat = old_errorformat
2015-12-08 08:20:04 -05:00
endfunction
2016-02-20 08:13:10 -05:00
" Parse parses the given items based on the global errorformat and
2015-12-08 08:20:04 -05:00
" populates the location list.
2016-02-20 08:13:10 -05:00
function! go#list#Parse(listtype, items)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
lgetexpr a:items
else
cgetexpr a:items
endif
2015-12-08 08:20:04 -05:00
endfunction
" JumpToFirst jumps to the first item in the location list
2016-02-20 08:13:10 -05:00
function! go#list#JumpToFirst(listtype)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
ll 1
else
cc 1
endif
2015-12-08 08:20:04 -05:00
endfunction
" Clean cleans the location list
2016-02-20 08:13:10 -05:00
function! go#list#Clean(listtype)
2016-06-26 07:12:36 -04:00
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
lex []
else
cex []
endif
2015-12-08 08:20:04 -05:00
endfunction
2016-02-20 08:13:10 -05:00
function! go#list#Type(listtype)
2016-06-26 07:12:36 -04:00
if g:go_list_type == "locationlist"
return "locationlist"
elseif g:go_list_type == "quickfix"
return "quickfix"
else
return a:listtype
endif
2016-02-20 08:13:10 -05:00
endfunction
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et