]>
Commit | Line | Data |
---|---|---|
1 | let s:segment_mods = [] | |
2 | ||
3 | function! Pl#Mod#AddSegmentMod(action, properties) " {{{ | |
4 | call add(s:segment_mods, [a:action, a:properties]) | |
5 | endfunction " }}} | |
6 | function! Pl#Mod#ApplySegmentMods(theme) " {{{ | |
7 | let theme = deepcopy(a:theme) | |
8 | ||
9 | for mod in s:segment_mods | |
10 | let [action, properties] = mod | |
11 | ||
12 | " We have to loop through the segments instead of using index() because some | |
13 | " segments are lists! | |
14 | let target_seg_idx = -1 | |
15 | ||
16 | for i in range(0, len(theme) - 1) | |
17 | unlet! segment | |
18 | let segment = theme[i] | |
19 | ||
20 | if type(segment) == type(properties.target_segment) && segment == properties.target_segment | |
21 | let target_seg_idx = i | |
22 | break | |
23 | endif | |
24 | endfor | |
25 | ||
26 | if action == 'insert_segment' | |
27 | " Insert segment | |
28 | if target_seg_idx != -1 | |
29 | call insert(theme, properties.new_segment, (properties.where == 'before' ? target_seg_idx : target_seg_idx + 1)) | |
30 | endif | |
31 | elseif action == 'remove_segment' | |
32 | " Remove segment | |
33 | if target_seg_idx != -1 | |
34 | call remove(theme, target_seg_idx) | |
35 | endif | |
36 | endif | |
37 | endfor | |
38 | ||
39 | return theme | |
40 | endfunction " }}} |