]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/autoload/Pl/Theme.vim
da1581e207bf7ad96a4d3b8eadbbc60e5b715803
[rbdr/dotfiles] / vim / autoload / Pl / Theme.vim
1 function! Pl#Theme#Create(...) " {{{
2 let buffer_segments = []
3
4 for buffer_segment in a:000
5 " Remove empty segments (e.g. 'Pl#Theme#Function's)
6 if empty(buffer_segment)
7 continue
8 endif
9
10 call add(buffer_segments, buffer_segment)
11 endfor
12
13 let buffer_segments = Pl#Colorscheme#Apply(g:Powerline_colorscheme, buffer_segments)
14
15 return buffer_segments
16 endfunction " }}}
17 function! Pl#Theme#Callback(name, expr) " {{{
18 return ['callback', a:name, a:expr]
19 endfunction " }}}
20 function! Pl#Theme#Buffer(ns, ...) " {{{
21 let segments = []
22 let ns = ! empty(a:ns) ? a:ns .':' : ''
23
24 " Match namespace parameter by default
25 let matches = Pl#Match#Any(a:ns)
26 let callback = []
27
28 let args = a:000
29 let args = Pl#Mod#ApplySegmentMods(args)
30
31 " Fetch segment data dicts
32 for item in args
33 if type(item) == type([])
34 if item[0] == 'match'
35 " Match item, overrides default namespace match
36 let matches = item
37
38 unlet! item
39 continue
40 elseif item[0] == 'callback'
41 " Store the item as a callback expression
42 let matches = ['match', 'none']
43 let callback = [a:ns, item[1], item[2]]
44
45 unlet! item
46 continue
47 endif
48
49 " printf segment, append ns to first item in list
50 let item[0] = ns . item[0]
51 else
52 let item = ns . item
53 endif
54
55 let segment = Pl#Segment#Get(item)
56
57 if ! empty(segment)
58 " Skip empty (possible disabled) segments
59 call add(segments, segment)
60 endif
61
62 unlet! item
63 endfor
64
65 return {
66 \ 'matches': matches
67 \ , 'callback': callback
68 \ , 'segments': segments
69 \ }
70 endfunction " }}}
71 function! Pl#Theme#InsertSegment(new_segment, where, target_segment) " {{{
72 " It's very important to NOT refer to the theme dict until everything's loaded!
73 "
74 " Because these functions are called from the vimrc, we need to put the
75 " actions in a list which will be parsed later.
76 "
77 " These functions don't accept a name parameter, because they work on the
78 " currently selected theme (will change any selected theme)
79 call Pl#Mod#AddSegmentMod('insert_segment', {
80 \ 'new_segment': a:new_segment,
81 \ 'where': a:where,
82 \ 'target_segment': a:target_segment
83 \ })
84 endfunction " }}}
85 function! Pl#Theme#RemoveSegment(target_segment) " {{{
86 " It's very important to NOT refer to the theme dict until everything's loaded!
87 "
88 " Because these functions are called from the vimrc, we need to put the
89 " actions in a list which will be parsed later.
90 "
91 " These functions don't accept a name parameter, because they work on the
92 " currently selected theme (will change any selected theme)
93 call Pl#Mod#AddSegmentMod('remove_segment', {
94 \ 'target_segment': a:target_segment
95 \ })
96 endfunction " }}}
97 function! Pl#Theme#ReplaceSegment(old_segment, new_segment) " {{{
98 call Pl#Theme#InsertSegment(a:new_segment, 'after', a:old_segment)
99 call Pl#Theme#RemoveSegment(a:old_segment)
100 endfunction " }}}