Last active
April 13, 2020 15:56
-
-
Save bfrg/924d35b060c8d4d4d1dc81c9c625a460 to your computer and use it in GitHub Desktop.
Like :messages but instead display the output in a popup window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ============================================================================== | |
" Display the output of :messages in a popup window | |
" | |
" Commands: | |
" :Messages | |
" | |
" Popup Mappings: | |
" j/k - scroll down/up one line | |
" d/u - scroll down/up one half page | |
" f/b - scroll down/up one full page | |
" g/G - scroll to top/bottom | |
" q - close popup window | |
" | |
" The popup window is automatically scrolled to the bottom | |
" ============================================================================== | |
function! s:popup_filter(winid, key) abort | |
if a:key ==# 'j' | |
call win_execute(a:winid, "normal! \<c-e>") | |
elseif a:key ==# 'k' | |
call win_execute(a:winid, "normal! \<c-y>") | |
elseif a:key ==# 'g' | |
call win_execute(a:winid, 'normal! gg') | |
elseif a:key ==# 'G' | |
call win_execute(a:winid, 'normal! G') | |
elseif a:key ==# 'd' | |
call win_execute(a:winid, "normal! \<c-d>") | |
elseif a:key ==# 'u' | |
call win_execute(a:winid, "normal! \<c-u>") | |
elseif a:key ==# 'f' | |
call win_execute(a:winid, "normal! \<c-f>") | |
elseif a:key ==# 'b' | |
call win_execute(a:winid, "normal! \<c-b>") | |
elseif a:key ==# 'q' | |
call popup_close(a:winid) | |
else | |
return v:false | |
endif | |
return v:true | |
endfunction | |
function! s:popup_messages() abort | |
let msg = execute('messages')->split('\n')->filter('!empty(v:val)') | |
let winid = popup_create(msg, { | |
\ 'maxheight': 15, | |
\ 'minwidth': &columns - 2, | |
\ 'maxwidth': &columns - 1, | |
\ 'padding': [], | |
\ 'scrollbar': v:true, | |
\ 'wrap': v:true, | |
\ 'mapping': v:false, | |
\ 'filtermode': 'n', | |
\ 'filter': funcref('s:popup_filter') | |
\ }) | |
" Scroll to bottom of buffer | |
call win_execute(winid, 'normal! G') | |
let bufnr = winbufnr(winid) | |
call matchadd('ErrorMsg', '\%1l', 10, -1, {'window': winid}) | |
call matchadd('WarningMsg', '\C^search hit BOTTOM, continuing at TOP', 10, -1, {'window': winid}) | |
call matchadd('WarningMsg', '\C^search hit TOP, continuing at BOTTOM', 10, -1, {'window': winid}) | |
call matchadd('WarningMsg', '\C^W\d\+.*', 10, -1, {'window': winid}) | |
call matchadd('Question', '\C^Scanning.*', 10, -1, {'window': winid}) | |
call matchadd('ErrorMsg', '\C^E\d\+.*', 10, -1, {'window': winid}) | |
call matchadd('ErrorMsg', '\C^Error detected while processing.*', 10, -1, {'window': winid}) | |
call matchadd('LineNr', '\C^line\s\+\d\+:', 10, -1, {'window': winid}) | |
return winid | |
endfunction | |
command! Messages call s:popup_messages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment