dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

statusline.vim (4776B)


      1 " return '[&et]' if &et is set wrong
      2 " return '[mixed-indenting]' if spaces and tabs are used to indent
      3 " return an empty string if everything is fine
      4 "
      5 " Indentation functions borrowed from airline, they do this pretty well.
      6 " Mixed indentation within a line. Returns the line number, or 0.
      7 function! s:check_mixed_line_indent()
      8     " [<tab>]<space><tab>
      9     " spaces before or between tabs are not allowed
     10     let t_s_t = '(^\t* +\t\s*\S)'
     11     " <tab>(<space> x count)
     12     " count of spaces at the end of tabs should be less than tabstop value
     13     let t_l_s = '(^\t+ {' . &ts . ',}' . '\S)'
     14     return search('\v' . t_s_t . '|' . t_l_s, 'nw')
     15 endfunction
     16 
     17 " Mixed indentation across the file. Returns line numbers
     18 " with_tabs:with_spaces, or empty string
     19 function! s:check_mixed_indent_file()
     20     let c_like_langs = ['arduino', 'c', 'cpp', 'cuda', 'go', 'javascript', 'ld', 'php' ]
     21     if index(c_like_langs, &ft) > -1
     22         " for C-like languages: allow /** */ comment style with one space before the '*'
     23         let head_spc = '\v(^ +\*@!)'
     24     else
     25         let head_spc = '\v(^ +)'
     26     endif
     27     let indent_tabs = search('\v(^\t+)', 'nw')
     28     let indent_spc  = search(head_spc, 'nw')
     29     if indent_tabs > 0 && indent_spc > 0
     30         return printf("%d:%d", indent_tabs, indent_spc)
     31     else
     32         return ''
     33     endif
     34 endfunction
     35 
     36 function! statusline#StatuslineTabWarning()
     37     if &readonly || &bt == "nofile"
     38         return ""
     39     endif
     40 
     41     if !exists("b:statusline_tab_warning")
     42         let mixed_on_line = s:check_mixed_line_indent()
     43         let mixed_on_line_str = mixed_on_line ==# 0 ? '' : '[mixed-line '..mixed_on_line..']'
     44         let mixed_in_file = s:check_mixed_indent_file()
     45         let mixed_in_file_str = empty(mixed_in_file) ? '' : '[mixed-indenting '..mixed_in_file..']'
     46         let b:statusline_tab_warning = mixed_on_line_str .. mixed_in_file_str
     47     endif
     48     return b:statusline_tab_warning
     49 endfunction
     50 
     51 " return '[\s]' if trailing white space is detected
     52 " return '' otherwise
     53 function! statusline#StatuslineTrailingSpaceWarning()
     54     if &readonly || &bt == "nofile"
     55         return ""
     56     endif
     57 
     58     if !exists("b:statusline_trailing_space_warning")
     59         if search('\s\+$', 'nw') != 0
     60             let b:statusline_trailing_space_warning = '[\s]'
     61         else
     62             let b:statusline_trailing_space_warning = ''
     63         endif
     64     endif
     65     return b:statusline_trailing_space_warning
     66 endfunction
     67 
     68 " build the current working directory string
     69 function! statusline#StatuslineBuildCwd()
     70     let cwd = substitute(getcwd(),$HOME,'~','g')
     71     return "(".cwd.")"
     72 endfunction
     73 
     74 " get the current fold info
     75 function! statusline#StatuslineFoldmethod()
     76     if &foldmethod == "indent"
     77         return "z".&foldlevel.",c".foldlevel(line('.'))
     78     elseif &foldmethod == "expr"
     79         return "f:exp,l".&foldlevel
     80     else
     81         return "f:".strpart(&foldmethod, 0, 4)
     82     endif
     83 endfunction
     84 
     85 " print the textwrap information (textwidth or wrapmargin)
     86 function! statusline#StatuslineWrapCol()
     87     if &textwidth == 0 && &wrapmargin == 0 && &wrap
     88         return "softwrap"
     89     endif
     90     if &textwidth == 0
     91         return "⟺  ".(winwidth(0)-&wrapmargin)."(M".&wrapmargin.")"
     92     else
     93         return "⟺  ".&textwidth
     94     endif
     95 endfunction
     96 
     97 function! statusline#StatuslineSpacesUsed()
     98     if &expandtab
     99         return (&shiftwidth ># 0 ? &shiftwidth : &tabstop)
    100     else
    101         if &shiftwidth ==# &tabstop
    102             return &shiftwidth
    103         else
    104             return &tabstop."s".&shiftwidth
    105         endif
    106     endif
    107 endfunction
    108 
    109 function! statusline#StatuslineWordCount()
    110     return wordcount().words . " words"
    111 endfunction
    112 
    113 function! statusline#StatuslineVimtexCompiler()
    114     " From vimtex documentation:
    115     let VIMTEX_SUCCESS = 2
    116     let VIMTEX_FAIL = 3
    117 
    118     if exists('b:vimtex') && b:vimtex->has_key('compiler')
    119       let l:str = ""
    120       if b:vimtex['compiler']['continuous']
    121         let l:str ..= "🔄 "
    122       endif
    123 
    124       if b:vimtex['compiler']['status'] ==# VIMTEX_SUCCESS
    125         return l:str..'✅ {'.(fnamemodify(b:vimtex['tex'], ":p:.")).'}'
    126       elseif b:vimtex['compiler']['status'] ==# VIMTEX_FAIL
    127         return l:str..'❌ {'.(fnamemodify(b:vimtex['tex'], ":p:.")).'}'
    128       elseif b:vimtex['compiler']['is_running']()
    129         return l:str..'🔨  {'.(fnamemodify(b:vimtex['tex'], ":p:.")).'}'
    130       endif
    131     endif
    132     return ''
    133 endfunction
    134 
    135 " Naive implementation, should improve with stuff from :h ale
    136 function! statusline#StatuslineAle()
    137   if !exists('g:loaded_ale')
    138     return ''
    139   endif
    140 
    141   if g:ale_enabled
    142     return '[linting]'
    143   else
    144     return ''
    145   endif
    146 endfunction
    147 
    148 function! statusline#StatuslineRemoteFile()
    149     if exists('b:netrw_lastfile')
    150         return ' ('.b:netrw_lastfile.')'
    151     endif
    152     return ''
    153 endfunction
    154