summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/preview.vim27
-rw-r--r--autoload/ale/util.vim9
2 files changed, 31 insertions, 5 deletions
diff --git a/autoload/ale/preview.vim b/autoload/ale/preview.vim
index c03cfe51..aefbb691 100644
--- a/autoload/ale/preview.vim
+++ b/autoload/ale/preview.vim
@@ -2,22 +2,41 @@
" Description: Preview windows for showing whatever information in.
" 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
- let l:filetype = get(a:000, 0, 'ale-preview')
+ let l:options = get(a:000, 0, {})
silent pedit ALEPreviewWindow
wincmd P
+
setlocal modifiable
setlocal noreadonly
setlocal nobuflisted
- let &l:filetype = l:filetype
+ let &l:filetype = get(l:options, 'filetype', 'ale-preview')
setlocal buftype=nofile
setlocal bufhidden=wipe
:%d
call setline(1, a:lines)
setlocal nomodifiable
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
" Show a location selection preview window, given some items.
@@ -35,7 +54,7 @@ function! ale#preview#ShowSelection(item_list) abort
\)
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
endfunction
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 0350efc6..28ab8231 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -17,11 +17,18 @@ endfunction
" but NeoVim does. Small messages can be echoed in Vim 8, and larger messages
" have to be shown in preview windows.
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.
if has('nvim') || (a:string !~? "\n" && len(a:string) < &columns)
execute 'echo a:string'
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
endfunction