2017-01-22 12:57:05 +00:00
|
|
|
" Author: Bjorn Neergaard <bjorn@neersighted.com>, modified by Yann fery <yann@fery.me>
|
|
|
|
" Description: Manages the loclist and quickfix lists
|
|
|
|
|
|
|
|
" Return 1 if there is a buffer with buftype == 'quickfix' in bufffer list
|
|
|
|
function! ale#list#IsQuickfixOpen() abort
|
|
|
|
for l:buf in range(1, bufnr('$'))
|
2017-08-08 07:39:13 +00:00
|
|
|
if getbufvar(l:buf, '&buftype') is# 'quickfix'
|
2017-01-22 12:57:05 +00:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfor
|
2017-01-22 14:54:57 +00:00
|
|
|
return 0
|
2017-01-22 12:57:05 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-08-07 23:46:42 +00:00
|
|
|
" Check if we should open the list, based on the save event being fired, and
|
|
|
|
" that setting being on, or the setting just being set to `1`.
|
|
|
|
function! s:ShouldOpen(buffer) abort
|
|
|
|
let l:val = ale#Var(a:buffer, 'open_list')
|
|
|
|
let l:saved = getbufvar(a:buffer, 'ale_save_event_fired', 0)
|
|
|
|
|
2017-08-08 07:43:51 +00:00
|
|
|
return l:val is 1 || (l:val is# 'on_save' && l:saved)
|
2017-08-07 23:46:42 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-03-09 00:43:53 +00:00
|
|
|
function! ale#list#SetLists(buffer, loclist) abort
|
2017-05-31 21:55:23 +00:00
|
|
|
let l:title = expand('#' . a:buffer . ':p')
|
|
|
|
|
2017-01-22 12:57:05 +00:00
|
|
|
if g:ale_set_quickfix
|
2017-05-31 21:55:23 +00:00
|
|
|
if has('nvim')
|
|
|
|
call setqflist(a:loclist, ' ', l:title)
|
|
|
|
else
|
|
|
|
call setqflist(a:loclist)
|
|
|
|
call setqflist([], 'r', {'title': l:title})
|
|
|
|
endif
|
2017-01-22 12:57:05 +00:00
|
|
|
elseif g:ale_set_loclist
|
2017-03-13 23:45:25 +00:00
|
|
|
" If windows support is off, bufwinid() may not exist.
|
2017-05-31 21:55:23 +00:00
|
|
|
" We'll set result in the current window, which might not be correct,
|
|
|
|
" but is better than nothing.
|
|
|
|
let l:win_id = exists('*bufwinid') ? bufwinid(str2nr(a:buffer)) : 0
|
|
|
|
|
|
|
|
if has('nvim')
|
|
|
|
call setloclist(l:win_id, a:loclist, ' ', l:title)
|
2017-03-13 23:45:25 +00:00
|
|
|
else
|
2017-05-31 21:55:23 +00:00
|
|
|
call setloclist(l:win_id, a:loclist)
|
|
|
|
call setloclist(l:win_id, [], 'r', {'title': l:title})
|
2017-03-13 23:45:25 +00:00
|
|
|
endif
|
2017-01-22 12:57:05 +00:00
|
|
|
endif
|
|
|
|
|
2017-08-07 23:46:42 +00:00
|
|
|
let l:keep_open = ale#Var(a:buffer, 'keep_list_window_open')
|
|
|
|
|
|
|
|
" Open a window to show the problems if we need to.
|
|
|
|
if s:ShouldOpen(a:buffer) && (l:keep_open || !empty(a:loclist))
|
2017-01-22 12:57:05 +00:00
|
|
|
let l:winnr = winnr()
|
2017-08-07 21:08:35 +00:00
|
|
|
let l:mode = mode()
|
2017-08-08 07:39:13 +00:00
|
|
|
let l:reset_visual_selection = l:mode is? 'v' || l:mode is# "\<c-v>"
|
|
|
|
let l:reset_character_selection = l:mode is? 's' || l:mode is# "\<c-s>"
|
2017-08-07 20:57:59 +00:00
|
|
|
|
2017-06-06 16:31:13 +00:00
|
|
|
if g:ale_set_quickfix
|
|
|
|
if !ale#list#IsQuickfixOpen()
|
|
|
|
execute 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))
|
|
|
|
endif
|
|
|
|
elseif g:ale_set_loclist
|
|
|
|
execute 'lopen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))
|
2017-01-22 12:57:05 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
" If focus changed, restore it (jump to the last window).
|
|
|
|
if l:winnr !=# winnr()
|
|
|
|
wincmd p
|
|
|
|
endif
|
2017-08-07 20:57:59 +00:00
|
|
|
|
|
|
|
if l:reset_visual_selection || l:reset_character_selection
|
2017-08-07 21:08:35 +00:00
|
|
|
" If we were in a selection mode before, select the last selection.
|
2017-08-07 20:57:59 +00:00
|
|
|
normal! gv
|
2017-08-07 21:08:35 +00:00
|
|
|
|
2017-08-07 20:57:59 +00:00
|
|
|
if l:reset_character_selection
|
2017-08-07 21:08:35 +00:00
|
|
|
" Switch back to Select mode, if we were in that.
|
2017-08-07 20:57:59 +00:00
|
|
|
normal! "\<c-g>"
|
|
|
|
endif
|
|
|
|
endif
|
2017-06-07 22:12:45 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
2017-01-22 12:57:05 +00:00
|
|
|
|
2017-06-07 22:12:45 +00:00
|
|
|
function! ale#list#CloseWindowIfNeeded(buffer) abort
|
2017-08-07 23:46:42 +00:00
|
|
|
if ale#Var(a:buffer, 'keep_list_window_open') || !s:ShouldOpen(a:buffer)
|
2017-06-07 22:12:45 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-07-24 08:29:54 +00:00
|
|
|
try
|
|
|
|
" Only close windows if the quickfix list or loclist is completely empty,
|
|
|
|
" including errors set through other means.
|
|
|
|
if g:ale_set_quickfix
|
|
|
|
if empty(getqflist())
|
|
|
|
cclose
|
|
|
|
endif
|
|
|
|
elseif g:ale_set_loclist && empty(getloclist(0))
|
|
|
|
lclose
|
2017-06-07 22:12:45 +00:00
|
|
|
endif
|
2017-07-24 08:29:54 +00:00
|
|
|
" Ignore 'Cannot close last window' errors.
|
|
|
|
catch /E444/
|
|
|
|
endtry
|
2017-01-22 12:57:05 +00:00
|
|
|
endfunction
|