]> git.r.bdr.sh - rbdr/dotfiles/blame - vim/autoload/Powerline/Functions.vim
Add DS_Store to gitignore
[rbdr/dotfiles] / vim / autoload / Powerline / Functions.vim
CommitLineData
321ecaca
BB
1" Recalculate the trailing whitespace warning when idle, and after saving
2autocmd CursorHold,BufWritePost,InsertLeave * unlet! b:statusline_trailing_space_warning
3
4function! Powerline#Functions#GetMode() " {{{
5 let mode = mode()
6
7 if mode =~# '\v(v|V|\16)'
8 " Visual mode
9 if mode ==# 'v'
10 let mode = 'VISUAL'
11 elseif mode ==# 'V'
12 let mode = 'V·LINE'
13 elseif mode ==# '\16'
14 let mode = 'V·BLOCK'
15 endif
16 elseif mode =~# '\v(s|S|\13)'
17 " Select mode
18 if mode ==# 's'
19 let mode = 'SELECT'
20 elseif mode ==# 'S'
21 let mode = 'S·LINE'
22 elseif mode ==# '\13'
23 let mode = 'S·BLOCK'
24 endif
25 elseif mode =~# '\vi'
26 let mode = 'INSERT' " Insert mode
27 elseif mode =~# '\v(R|Rv)'
28 let mode = 'REPLACE' " Replace mode
29 else
30 " Fallback to normal mode
31 let mode = ' N ' " Normal (current)
32 endif
33
34 return mode
35endfunction " }}}
36function! Powerline#Functions#GetFilesize() " {{{
37 let bytes = getfsize(expand("%:p"))
38
39 if bytes <= 0
40 return ''
41 endif
42
43 if bytes < 1024
44 return bytes . 'B'
45 else
46 return (bytes / 1024) . 'kB'
47 endif
48endfunction "}}}
49function! Powerline#Functions#GetCharCode() " {{{
50 " Get the output of :ascii
51 redir => ascii
52 silent! ascii
53 redir END
54
55 if match(ascii, 'NUL') != -1
56 return 'NUL'
57 endif
58
59 " Zero pad hex values
60 let nrformat = '0x%02x'
61
62 let encoding = (&fenc == '' ? &enc : &fenc)
63
64 if encoding == 'utf-8'
65 " Zero pad with 4 zeroes in unicode files
66 let nrformat = '0x%04x'
67 endif
68
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]+)')
73
74 " Format the numeric value
75 let nr = printf(nrformat, nr)
76
77 return "'". char ."' ". nr
78endfunction "}}}
79function! Powerline#Functions#GetWSMarker() " {{{
80 " Return '...' if trailing white space is detected
81 " Return '' otherwise
82 if ! exists("b:statusline_trailing_space_warning")
83 if search('\s$', 'nw') != 0
84 let b:statusline_trailing_space_warning = ' … '
85 else
86 let b:statusline_trailing_space_warning = ''
87 endif
88 endif
89 return b:statusline_trailing_space_warning
90endfunction " }}}