vim/vimrc.d/statusline.vim

176 lines
6.6 KiB
VimL
Raw Normal View History

2018-03-17 23:42:49 +00:00
" #statusline format
2018-03-18 00:24:20 +00:00
function! GetStatus(isactive) "{{{
2018-03-17 23:42:49 +00:00
" let l:linter = ale#statusline#Count(bufnr(''))
let l:divider = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >'
let l:separator = '%#StatusLineSeparator# '
let l:normal = '%#StatusLineNormal#'
let l:active = '%#StatusLineActive#'
let l:bracket_open = '%#CRNoiseDark#('
let l:bracket_close = '%#CRNoiseDark#) '
let l:statusline = ''
" file percentage
2018-03-18 00:24:20 +00:00
let l:statusline .= '%#FoldColumn#: '
if a:isactive
let l:statusline .= '%#StatusLineNormal#'
else
let l:statusline .= '%#StatusLineDir#'
endif
let l:statusline .= '%P%* '
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
" non-empty buftype (help, quickfix, etc)
if a:isactive "{{{
2018-03-17 23:42:49 +00:00
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"
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
" file info
2018-03-18 00:24:20 +00:00
if a:isactive == 1 "{{{
2018-03-17 23:42:49 +00:00
let l:statusline.=l:active
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.=l:separator . l:active
let l:statusline.=' %{&spelllang} '
else
let l:statusline.=l:separator
endif
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
" current register
2018-03-18 00:24:20 +00:00
if a:isactive "{{{
2018-03-17 23:42:49 +00:00
let l:statusline.=l:separator . l:active
2018-03-17 23:50:54 +00:00
let l:statusline.=' %#StatusLineActiveQuotes#"' . l:active . '%{v:register}%#StatusLineActiveQuotes#" '
2018-03-17 23:42:49 +00:00
endif
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
" session status
2018-03-18 00:24:20 +00:00
if a:isactive "{{{
2018-03-17 23:42:49 +00:00
let l:statusline.=l:separator . l:active
let l:statusline.=" %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*"
let l:statusline.=l:separator . l:active
endif
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
" right/left divider
2018-03-18 00:24:20 +00:00
" modified version {{{
2018-03-17 23:42:49 +00:00
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 . '%*%='
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
" path/filename.extension
if a:isactive "{{{
let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
let l:statusline.='%#StatusLineFileActive#'
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
let l:statusline.="%{expand('%:t:r')}"
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
else
let l:statusline.='%#StatusLineDir# '
let l:statusline.="%{expand('%:p:h')}/"
let l:statusline.='%#StatusLineFile#'
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
let l:statusline.="%{expand('%:t:r')}"
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
let l:statusline.='%#StatusLineDot#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExt#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
endif
2018-03-17 23:42:49 +00:00
let l:statusline .= '%#CRNormal#%r' " TODO color
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
" linter status "
2018-03-18 00:24:20 +00:00
if a:isactive "{{{
2018-03-17 23:42:49 +00:00
" errors
let l:statusline .= " %#CRNoiseDark#%{(GetLinterStatus('error') == 0?'-':'')}"
let l:statusline .= "%#InterfaceSignError#%{(GetLinterStatus('error') == 0?'':GetLinterStatus('error'))}"
" style errors
let l:statusline .= '%#CRNoiseDarker#|'
let l:statusline .= "%#CRNoiseDark#%{(GetLinterStatus('style_error') == 0?'-':'')}"
let l:statusline .= "%#InterfaceSignErrorDark#%{(GetLinterStatus('style_error') == 0?'':GetLinterStatus('style_error'))} "
" warnings
let l:statusline .= "%#CRNoiseDark#%{(GetLinterStatus('warning') == 0?'-':'')}"
let l:statusline .= "%#InterfaceSignWarning#%{(GetLinterStatus('warning') == 0?'':GetLinterStatus('warning'))}"
" style warnings
let l:statusline .= '%#CRNoiseDarker#|'
let l:statusline .= "%#CRNoiseDark#%{(GetLinterStatus('style_warning') == 0?'-':'')}"
let l:statusline .= "%#InterfaceSignWarningDark#%{(GetLinterStatus('style_warning') == 0?'':GetLinterStatus('style_warning'))} "
" info
let l:statusline .= "%#CRNoiseDark#%{(GetLinterStatus('info') == 0?'-':'')}"
let l:statusline .= "%#CRNoiseRed#%{(GetLinterStatus('info') == 0?'':GetLinterStatus('info'))}"
else
" errors
let l:statusline .= " %#CRNoiseDarker#%{(GetLinterStatus('error') == 0?'-':'')}"
let l:statusline .= "%#CRNoiseBright#%{(GetLinterStatus('error') == 0?'':GetLinterStatus('error'))}"
" style errors
let l:statusline .= '%#CRNoiseDarker#|'
let l:statusline .= "%{(GetLinterStatus('style_error') == 0?'-':'')}"
let l:statusline .= "%#CRNoiseBright#%{(GetLinterStatus('style_error') == 0?'':GetLinterStatus('style_error'))} "
" warnings
let l:statusline .= "%#CRNoiseDarker#%{(GetLinterStatus('warning') == 0?'-':'')}"
let l:statusline .= "%#CRNoise#%{(GetLinterStatus('warning') == 0?'':GetLinterStatus('warning'))}"
" style warnings
let l:statusline .= '%#CRNoiseDarker#|'
let l:statusline .= "%{(GetLinterStatus('style_warning') == 0?'-':'')}"
let l:statusline .= "%#CRNoise#%{(GetLinterStatus('style_warning') == 0?'':GetLinterStatus('style_warning'))} "
" info
let l:statusline .= "%#CRNoiseDarker#%{GetLinterStatus('info') == 0 ? '-' : GetLinterStatus('info')}"
endif
2018-03-18 00:24:20 +00:00
"}}}
2018-03-17 23:42:49 +00:00
return l:statusline
2018-03-18 00:24:20 +00:00
endfunction "}}}
2018-03-17 23:42:49 +00:00
2018-03-18 00:24:20 +00:00
augroup status "{{{
2018-03-17 23:42:49 +00:00
autocmd!
autocmd WinEnter * setlocal statusline=%!GetStatus(1)
autocmd WinLeave * setlocal statusline=%!GetStatus(0)
" autocmd WinNew * setlocal statusline=%!GetStatus(1)
" autocmd InsertChange * setlocal statusline=%!GetStatus(1)
2018-03-18 00:24:20 +00:00
augroup END"}}}
2018-03-17 23:42:49 +00:00
function! LinterStatus() abort "{{{
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf('%dW %dE', l:all_non_errors, l:all_errors)
endfunction
"}}}
" vim: foldmethod=marker