Close #1590 - Automatically close previews for hover
This commit is contained in:
parent
8bca073763
commit
935740cf93
@ -2,22 +2,41 @@
|
|||||||
" Description: Preview windows for showing whatever information in.
|
" Description: Preview windows for showing whatever information in.
|
||||||
|
|
||||||
" Open a preview window and show some lines in it.
|
" Open a preview window and show some lines in it.
|
||||||
" An optional second argument can set an alternative filetype for the window.
|
" A second argument can be passed as a Dictionary with options. They are...
|
||||||
|
"
|
||||||
|
" filetype - The filetype to use, defaulting to 'ale-preview'
|
||||||
|
" stay_here - If 1, stay in the window you came from.
|
||||||
function! ale#preview#Show(lines, ...) abort
|
function! ale#preview#Show(lines, ...) abort
|
||||||
let l:filetype = get(a:000, 0, 'ale-preview')
|
let l:options = get(a:000, 0, {})
|
||||||
|
|
||||||
silent pedit ALEPreviewWindow
|
silent pedit ALEPreviewWindow
|
||||||
wincmd P
|
wincmd P
|
||||||
|
|
||||||
setlocal modifiable
|
setlocal modifiable
|
||||||
setlocal noreadonly
|
setlocal noreadonly
|
||||||
setlocal nobuflisted
|
setlocal nobuflisted
|
||||||
let &l:filetype = l:filetype
|
let &l:filetype = get(l:options, 'filetype', 'ale-preview')
|
||||||
setlocal buftype=nofile
|
setlocal buftype=nofile
|
||||||
setlocal bufhidden=wipe
|
setlocal bufhidden=wipe
|
||||||
:%d
|
:%d
|
||||||
call setline(1, a:lines)
|
call setline(1, a:lines)
|
||||||
setlocal nomodifiable
|
setlocal nomodifiable
|
||||||
setlocal readonly
|
setlocal readonly
|
||||||
|
|
||||||
|
if get(l:options, 'stay_here')
|
||||||
|
wincmd p
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Close the preview window if the filetype matches the given one.
|
||||||
|
function! ale#preview#CloseIfTypeMatches(filetype) abort
|
||||||
|
for l:win in getwininfo()
|
||||||
|
let l:wintype = gettabwinvar(l:win.tabnr, l:win.winnr, '&filetype')
|
||||||
|
|
||||||
|
if l:wintype is# a:filetype
|
||||||
|
silent! pclose!
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Show a location selection preview window, given some items.
|
" Show a location selection preview window, given some items.
|
||||||
@ -35,7 +54,7 @@ function! ale#preview#ShowSelection(item_list) abort
|
|||||||
\)
|
\)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call ale#preview#Show(l:lines, 'ale-preview-selection')
|
call ale#preview#Show(l:lines, {'filetype': 'ale-preview-selection'})
|
||||||
let b:ale_preview_item_list = a:item_list
|
let b:ale_preview_item_list = a:item_list
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -17,11 +17,18 @@ endfunction
|
|||||||
" but NeoVim does. Small messages can be echoed in Vim 8, and larger messages
|
" but NeoVim does. Small messages can be echoed in Vim 8, and larger messages
|
||||||
" have to be shown in preview windows.
|
" have to be shown in preview windows.
|
||||||
function! ale#util#ShowMessage(string) abort
|
function! ale#util#ShowMessage(string) abort
|
||||||
|
if !has('nvim')
|
||||||
|
call ale#preview#CloseIfTypeMatches('ale-preview.message')
|
||||||
|
endif
|
||||||
|
|
||||||
" We have to assume the user is using a monospace font.
|
" We have to assume the user is using a monospace font.
|
||||||
if has('nvim') || (a:string !~? "\n" && len(a:string) < &columns)
|
if has('nvim') || (a:string !~? "\n" && len(a:string) < &columns)
|
||||||
execute 'echo a:string'
|
execute 'echo a:string'
|
||||||
else
|
else
|
||||||
call ale#preview#Show(split(a:string, "\n"))
|
call ale#preview#Show(split(a:string, "\n"), {
|
||||||
|
\ 'filetype': 'ale-preview.message',
|
||||||
|
\ 'stay_here': 1,
|
||||||
|
\})
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user