nvim/init.statusline.vim

304 lines
10 KiB
VimL

function! GetLinterStatus(key) abort "{{{
let l:statuscount = 0
if exists('b:ale_linted')
let l:linter = ale#statusline#Count(bufnr(''))
else
let l:linter = GetDiagnosticCountsFromSigns(bufnr(''))
endif
if has_key(l:linter, a:key)
let l:statuscount = l:linter[a:key]
endif
return l:statuscount
endfunction
"}}}
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort "{{{
" TODO better name
let l:frag='%#' . a:colorname . '#'
let l:frag.=a:conditionprefix
let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
return l:frag
endfunction
"}}}
function! GetDiagnosticCountsFromSigns(buffer) abort "{{{
let l:error = 0
let l:warn = 0
let l:info = 0
let l:hint = 0
redir => l:result
silent exec 'sign place buffer=' . a:buffer
redir end
let l:lines = split(l:result, '\n')
for l:line in l:lines
if l:line =~? 'Error'
let l:error += 1
endif
if l:line =~? 'Warning'
let l:warn += 1
endif
if l:line =~? 'Info'
let l:info += 1
endif
if l:line =~? 'Hint'
let l:hint += 1
endif
endfor
return {'error': l:error, 'warning': l:warn, 'info': l:info, 'hint': l:hint}
endfunction
"}}}
augroup statusline "{{{
autocmd!
autocmd WinNew,WinEnter * setlocal statusline=%!GetStatus(1)
autocmd WinLeave * setlocal statusline=%!GetStatus(0)
autocmd Filetype qf setlocal statusline=%!GetStatus(1)
autocmd Filetype help setlocal statusline=%!GetStatus(1)
augroup END
"}}}
function! GetStatus(isactive) abort "{{{
" let l:linter = ale#statusline#Count(bufnr(''))
let l:divider = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >'
let l:separator = '%#StatusLineSeparator# '
let l:normal = '%#StatusLineNormal#'
let l:active = '%#StatusLineActive#'
let l:linterdash = '%#LinterDash#·'
let l:linterdashactive = '%#LinterDashActive#·'
let l:statusline = l:separator
"buffer number {{{
if a:isactive
let l:statusline .= '%#StatusLineBufferNrActive#'
else
let l:statusline .= '%#StatusLineBufferNr#'
endif
let l:statusline .= ' %n ' . l:separator
"}}}
" file percentage {{{
if a:isactive
let l:statusline .= '%#StatusLinePercentActive#'
let l:statusline .= ' %P %#StatusLineNoiseActive#of %#StatusLineLinecountActive#%L '
else
let l:statusline .= '%#StatusLinePercent#'
let l:statusline .= ' %P %#StatusLineNoise#of %#StatusLineLinecount#%L '
endif"}}}
" non-empty buftype (help, quickfix, etc) {{{
if a:isactive
let l:statusline .= l:active . "%{&buftype == '' ? '' : ' '}%q%h%w%#StatusLineActiveNoText#"
else
let l:statusline .= l:normal . "%{&buftype == '' ? '' : ' '}%q%h%w%#StatusLineNormalNoText#"
endif
let l:statusline .= "%{&buftype == '' ? '' : ' '}%s"
"}}}
" right/left divider {{{
let l:statusline.=l:separator
" modified version
let l:color = 'StatusLineDivMod' . (a:isactive?'Active':'')
let l:statusline .= GetStatusFrag("&modified && mode() != 'i'", l:color, '%<', l:divider)
" unmodified version
let l:color = 'StatusLineDiv' . (a:isactive?'Active':'')
let l:statusline .= GetStatusFrag("!&modified && mode() != 'i'", l:color, '%<', l:divider)
" input mode version
if a:isactive
let l:statusline .= GetStatusFrag("mode() == 'i'", 'StatusLineDivInput', '%<', l:divider)
endif
let l:statusline.= l:separator . '%*%='
"}}}
" file info{{{
if a:isactive == 1
" let l:statusline.=l:active
let l:statusline.='%#StatusLineFileInfo#'
" let l:statusline.=" %{strlen(&ft)?&ft:'none'} "
" let l:statusline.=l:separator . l:active
let l:statusline.='%{strlen(&fenc)?&fenc:&enc}'
" let l:statusline.=l:separator . l:active
let l:statusline.=' %{&fileformat}'
let l:statusline.="%{strlen(expand('%:e')) > 1?' ' . expand('%:e'):''}"
" let l:statusline.=l:separator . l:active
" let l:statusline.=' %{&spelllang} '
let l:statusline .= l:separator
endif
"}}}
" path/filename.extension {{{
if a:isactive
if &readonly
let l:statusline .= '%#StatusLineWarningActive# %r '
let l:statusline .= '%#StatusLineFileReadOnlyActive#'
" let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
" let l:statusline.='%#StatusLineFileActive#'
let l:statusline.="%{expand('%:t:r')}"
" let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
" let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{expand('%:e')} "
else
let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
let l:statusline.='%#StatusLineFileActive#'
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{expand('%:e')} "
endif
else
let l:statusline .= ' %#StatusLineWarning#%r'
let l:statusline.='%#StatusLineDir# '
let l:statusline.="%{fnamemodify(expand('%:p:h'),':~')}/"
let l:statusline.='%#StatusLineFile#'
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDot#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExt#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')} "
endif
"}}}
let l:statusline.='%*' . l:separator
" linter status {{{
if a:isactive
" errors
let l:statusline .= "%#LinterDashActive#%{(GetLinterStatus('error') == 0?'-':'')}"
let l:statusline .= "%#LinterErrorActive#%{(GetLinterStatus('error') == 0?'':GetLinterStatus('error'))}"
" style errors
let l:statusline .= l:linterdashactive
let l:statusline .= "%#LinterDashActive#%{(GetLinterStatus('style_error') == 0?'-':'')}"
let l:statusline .= "%#LinterErrorStyleActive#%{(GetLinterStatus('style_error') == 0?'':GetLinterStatus('style_error'))} "
" warnings
let l:statusline .= "%#LinterDashActive#%{(GetLinterStatus('warning') == 0?'-':'')}"
let l:statusline .= "%#LinterWarningActive#%{(GetLinterStatus('warning') == 0?'':GetLinterStatus('warning'))}"
" style warnings
let l:statusline .= l:linterdashactive
let l:statusline .= "%#LinterDashActive#%{(GetLinterStatus('style_warning') == 0?'-':'')}"
let l:statusline .= "%#LinterWarningStyleActive#%{(GetLinterStatus('style_warning') == 0?'':GetLinterStatus('style_warning'))} "
" info
let l:statusline .= "%#LinterDashActive#%{(GetLinterStatus('info') == 0?'-':'')}"
let l:statusline .= "%#LinterInfoActive#%{(GetLinterStatus('info') == 0?'':GetLinterStatus('info'))}"
else
" errors
let l:statusline .= "%#LinterDash#%{(GetLinterStatus('error') == 0?'-':'')}"
let l:statusline .= "%#LinterError#%{(GetLinterStatus('error') == 0?'':GetLinterStatus('error'))}"
" style errors
let l:statusline .= l:linterdash
let l:statusline .= "%{(GetLinterStatus('style_error') == 0?'-':'')}"
let l:statusline .= "%#LinterErrorStyle#%{(GetLinterStatus('style_error') == 0?'':GetLinterStatus('style_error'))} "
" warnings
let l:statusline .= "%#LinterDash#%{(GetLinterStatus('warning') == 0?'-':'')}"
let l:statusline .= "%#LinterWarning#%{(GetLinterStatus('warning') == 0?'':GetLinterStatus('warning'))}"
" style warnings
let l:statusline .= l:linterdash
let l:statusline .= "%{(GetLinterStatus('style_warning') == 0?'-':'')}"
let l:statusline .= "%#LinterWarningStyle#%{(GetLinterStatus('style_warning') == 0?'':GetLinterStatus('style_warning'))} "
" info
let l:statusline .= "%#LinterInfo#%{GetLinterStatus('info') == 0 ? '-' : GetLinterStatus('info')}"
endif
"}}}
let l:statusline .= ' ' . l:separator
if exists('gutentags#statusline')
let l:statusline .= '%#StatusLineWarning#%{gutentags#statusline("", "", "☢")}'
endif
return l:statusline
endfunction
"}}}
" highlight groups {{{
hi def link StatusLineSeparator Ignore
hi def link StatusLineNormal StatusLineNC
hi def link StatusLineActive StatusLine
hi def link StatusLineNormalNoText TabLineFill
hi def link StatusLineActiveNoText TabLineFill
hi def link StatusLineNoise StatusLineNormal
hi def link StatusLineNoiseActive StatusLineNormal
hi def link StatusLineBufferNr StatusLineNormal
hi def link StatusLineBufferNrActive StatusLineActive
hi def link StatusLinePercent StatusLineNormal
hi def link StatusLinePercentActive StatusLineActive
hi def link StatusLineLinecount StatusLinePercent
hi def link StatusLineLinecountActive StatusLinePercentActive
hi DivActive ctermbg=darkgray ctermfg=darkgray guibg=#666666 guifg=#666666
hi DivMod ctermbg=darkred ctermfg=darkred guibg=#660000 guifg=#660000
hi DivModActive ctermbg=red ctermfg=red guibg=#aa0000 guifg=#aa0000
hi DivInput ctermbg=darkblue ctermfg=darkblue guibg=#000022 guifg=#000022
hi def link StatusLineDiv TabLineFill
hi def link StatusLineDivActive DivActive
hi def link StatusLineDivMod DivMod
hi def link StatusLineDivModActive DivModActive
hi def link StatusLineDivInput DivInput
hi def link StatusLineFileInfo StatusLineActive
hi def link StatusLineFile StatusLineNormal
hi def link StatusLineFileActive StatusLineActive
hi def link StatusLineDir StatusLineFile
hi def link StatusLineDirActive StatusLineFileActive
hi def link StatusLineDot StatusLineDir
hi def link StatusLineDotActive StatusLineDirActive
hi def link StatusLineExt StatusLineDir
hi def link StatusLineExtActive StatusLineDirActive
hi def link StatusLineFileReadOnlyActive WarningMsg
hi def link StatusLineWarning StatusLineNormal
hi def link StatusLineWarningActive WarningMsg
hi def link LinterDash Normal
hi def link LinterDashActive Normal
hi def link LinterError Normal
hi def link LinterErrorActive ErrorMsg
hi def link LinterErrorStyle Normal
hi def link LinterErrorStyleActive SpellBad
hi def link LinterWarning Normal
hi def link LinterWarningActive SpellCap
hi def link LinterWarningStyle Normal
hi def link LinterWarningStyleActive LinterWarningActive
hi def link LinterInfo Normal
hi def link LinterInfoActive SpellRare
"}}}
set statusline=%!GetStatus(1)
" vim: set foldmethod=marker: