1 " Recalculate the trailing whitespace warning when idle, and after saving
2 autocmd CursorHold,BufWritePost,InsertLeave * unlet! b:statusline_trailing_space_warning
4 function! Powerline#Functions#GetMode() " {{{
7 if mode =~# '\v(v|V|
\16)'
16 elseif mode =~# '\v(s|S|
\13)'
26 let mode = 'INSERT' " Insert mode
27 elseif mode =~# '\v(R|Rv)'
28 let mode = 'REPLACE' " Replace mode
30 " Fallback to normal mode
31 let mode = ' N ' " Normal (current)
36 function! Powerline#Functions#GetFilesize() " {{{
37 let bytes = getfsize(expand("%:p"))
46 return (bytes / 1024) . 'kB'
49 function! Powerline#Functions#GetCharCode() " {{{
50 " Get the output of :ascii
55 if match(ascii, 'NUL') != -1
60 let nrformat = '0x%02x'
62 let encoding = (&fenc == '' ? &enc : &fenc)
64 if encoding == 'utf-8'
65 " Zero pad with 4 zeroes in unicode files
66 let nrformat = '0x%04x'
69 " Get the character and the numeric value from the return value of :ascii
70 " This matches the two first pieces of the return value, e.g.
71 " "<F> 70" => char: 'F', nr: '70'
72 let [str, char, nr; rest] = matchlist(ascii, '\v\<(.{-1,})\>\s*([0-9]+)')
74 " Format the numeric value
75 let nr = printf(nrformat, nr)
77 return "'". char ."' ". nr
79 function! Powerline#Functions#GetWSMarker() " {{{
80 " Return '...' if trailing white space is detected
82 if ! exists("b:statusline_trailing_space_warning")
83 if search('\s$', 'nw') != 0
84 let b:statusline_trailing_space_warning = ' … '
86 let b:statusline_trailing_space_warning = ''
89 return b:statusline_trailing_space_warning