]>
Commit | Line | Data |
---|---|---|
321ecaca BB |
1 | function! Pl#Colorscheme#Init(hi) " {{{ |
2 | let colorscheme = {} | |
3 | ||
4 | for hi in a:hi | |
5 | " Ensure that the segments are a list | |
6 | let segments = type(hi[0]) == type('') ? [ hi[0] ] : hi[0] | |
7 | let mode_hi_dict = hi[1] | |
8 | ||
9 | for segment in segments | |
10 | let colorscheme[segment] = mode_hi_dict | |
11 | endfor | |
12 | endfor | |
13 | ||
14 | return colorscheme | |
15 | endfunction " }}} | |
16 | function! Pl#Colorscheme#Apply(colorscheme, buffer_segments) " {{{ | |
17 | " Set color parameters for all segments in a:buffer_segments | |
18 | ||
19 | " TODO This function should be recursive and work on both segments and groups | |
20 | " TODO We could probably handle the NS stuff here... | |
21 | ||
22 | try | |
23 | let colorscheme = g:Powerline#Colorschemes#{a:colorscheme}#colorscheme | |
24 | catch | |
25 | echom 'Color scheme "'. a:colorscheme .'" doesn''t exist!' | |
26 | ||
27 | return | |
28 | endtry | |
29 | ||
30 | let buffer_segments = a:buffer_segments | |
31 | ||
32 | " This is a bit complex, I'll walk you through exactly what happens here... | |
33 | " | |
34 | " First of all we loop through the buffer_segments, which are the segments that | |
35 | " this specific buffer will have. | |
36 | for buffer_segment in buffer_segments | |
37 | " The buffer_segment consists of a 'matches' list and a 'segments' list. | |
38 | " The 'matches' list has conditions to limit this statusline to specific buffers/windows. | |
39 | " The 'segments' list has each segment and segment group for this buffer | |
40 | for segment in buffer_segment.segments | |
41 | let type = get(segment, 'type', '') | |
42 | ||
43 | if type == 'segment_group' | |
44 | " We're going to handle segment groups different from single segments. Segment groups | |
45 | " have child segments which may have their own highlighting (e.g. fileinfo.flags), | |
46 | " and these child segments may be grouped (e.g. fileinfo.flags.ro) to provide very | |
47 | " specific highlighting. So here we'll handle all that: | |
48 | ||
49 | " Set the default/fallback colors for this group | |
50 | for i in range(len(segment.variants), 0, -1) | |
51 | " Check for available highlighting for the main group segment | |
52 | " | |
53 | " This works like the segment highlighting below | |
54 | " TODO Create a function for this | |
55 | let seg_variants = join(segment.variants[0:i], '.') | |
56 | ||
57 | let seg_name = i > 0 ? segment.name .'.'. seg_variants : segment.name | |
58 | let seg_ns_name = len(segment.ns) > 0 ? segment.ns .':'. seg_name : seg_name | |
59 | ||
60 | if has_key(colorscheme, seg_ns_name) | |
61 | " We have a namespaced highlight group | |
62 | let segment.colors = colorscheme[seg_ns_name] | |
63 | break | |
64 | elseif has_key(colorscheme, seg_name) | |
65 | " We have a non-namespaced group | |
66 | let segment.colors = colorscheme[seg_name] | |
67 | break | |
68 | endif | |
69 | endfor | |
70 | ||
71 | " The reason why we need to deepcopy the group's segments is that the child segments | |
72 | " all point to the same base segments and that screws up highlighting if we highlight | |
73 | " some child segments with different namespaced colors | |
74 | let segment.segments = deepcopy(segment.segments) | |
75 | ||
76 | " Apply colors to each child segment | |
77 | for child_segment in segment.segments | |
78 | " Check if this child segment is grouped (e.g. fileinfo.flags.group.subgroup) | |
79 | " We're going to prioritize the most specific grouping and then work back to the | |
80 | " most common group (e.g. fileinfo.flags) | |
81 | ||
82 | " FIXME We don't have the variants from before because group children aren't run through Pl#Segment#Get | |
83 | let child_segment.variants = [seg_name] + split(child_segment.name, '\.') | |
84 | ||
85 | " Use the parent group's namespace | |
86 | let child_segment.ns = segment.ns | |
87 | ||
88 | for i in range(len(child_segment.variants), 0, -1) | |
89 | " Check for available highlighting for the main group segment | |
90 | let child_seg_name = join(child_segment.variants[0:i], '.') | |
91 | ||
92 | let child_seg_ns_name = len(child_segment.ns) > 0 ? child_segment.ns .':'. child_seg_name : child_seg_name | |
93 | ||
94 | if has_key(colorscheme, child_seg_ns_name) | |
95 | " We have a namespaced highlight group | |
96 | let child_segment.colors = colorscheme[child_seg_ns_name] | |
97 | break | |
98 | elseif has_key(colorscheme, child_seg_name) | |
99 | " We have a non-namespaced group | |
100 | let child_segment.colors = colorscheme[child_seg_name] | |
101 | break | |
102 | endif | |
103 | endfor | |
104 | endfor | |
105 | elseif type == 'segment' | |
106 | for i in range(len(segment.variants), 0, -1) | |
107 | " Check for available highlighting | |
108 | " | |
109 | " This is done in the following manner, using the segment gundo:static_filename.text.buffer as an example: | |
110 | " | |
111 | " * Look for the hl group: gundo:static_filename.text.buffer | |
112 | " * Look for the hl group: static_filename.text.buffer | |
113 | " * Look for the hl group: gundo:static_filename.text | |
114 | " * Look for the hl group: static_filename.text | |
115 | " * Look for the hl group: gundo:static_filename | |
116 | " * Look for the hl group: static_filename | |
117 | " * Return the segment without highlighting, causing an error in the parser | |
118 | let seg_variants = join(segment.variants[0:i], '.') | |
119 | ||
120 | let seg_name = i > 0 ? segment.name .'.'. seg_variants : segment.name | |
121 | let seg_ns_name = len(segment.ns) > 0 ? segment.ns .':'. seg_name : seg_name | |
122 | ||
123 | if has_key(colorscheme, seg_ns_name) | |
124 | " We have a namespaced highlight group | |
125 | let segment.colors = colorscheme[seg_ns_name] | |
126 | break | |
127 | elseif has_key(colorscheme, seg_name) | |
128 | " We have a non-namespaced group | |
129 | let segment.colors = colorscheme[seg_name] | |
130 | break | |
131 | endif | |
132 | endfor | |
133 | endif | |
134 | ||
135 | unlet! segment | |
136 | endfor | |
137 | endfor | |
138 | ||
139 | " Good luck parsing this return value | |
140 | " | |
141 | " It's a huge dict with all segments for all buffers with their respective syntax highlighting. | |
142 | " It will be parsed by the main Powerline code, where all the data will be shortened to a simple | |
143 | " array consiting of a statusline for each mode, with generated highlighting groups and dividers. | |
144 | return buffer_segments | |
145 | endfunction " }}} |