-
Notifications
You must be signed in to change notification settings - Fork 119
/
sonokai.vim
327 lines (325 loc) · 15 KB
/
sonokai.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
" =============================================================================
" URL: https://github.com/sainnhe/sonokai
" Filename: autoload/sonokai.vim
" Author: sainnhe
" Email: [email protected]
" License: MIT License
" =============================================================================
function! sonokai#get_configuration() "{{{
return {
\ 'style': get(g:, 'sonokai_style', 'default'),
\ 'colors_override': get(g:, 'sonokai_colors_override', {}),
\ 'transparent_background': get(g:, 'sonokai_transparent_background', 0),
\ 'dim_inactive_windows': get(g:, 'sonokai_dim_inactive_windows', 0),
\ 'disable_italic_comment': get(g:, 'sonokai_disable_italic_comment', 0),
\ 'enable_italic': get(g:, 'sonokai_enable_italic', 0),
\ 'cursor': get(g:, 'sonokai_cursor', 'auto'),
\ 'menu_selection_background': get(g:, 'sonokai_menu_selection_background', 'blue'),
\ 'spell_foreground': get(g:, 'sonokai_spell_foreground', 'none'),
\ 'show_eob': get(g:, 'sonokai_show_eob', 1),
\ 'float_style': get(g:, 'sonokai_float_style', 'bright'),
\ 'current_word': get(g:, 'sonokai_current_word', get(g:, 'sonokai_transparent_background', 0) == 0 ? 'grey background' : 'bold'),
\ 'inlay_hints_background': get(g:, 'sonokai_inlay_hints_background', 'none'),
\ 'lightline_disable_bold': get(g:, 'sonokai_lightline_disable_bold', 0),
\ 'diagnostic_text_highlight': get(g:, 'sonokai_diagnostic_text_highlight', 0),
\ 'diagnostic_line_highlight': get(g:, 'sonokai_diagnostic_line_highlight', 0),
\ 'diagnostic_virtual_text': get(g:, 'sonokai_diagnostic_virtual_text', 'grey'),
\ 'disable_terminal_colors': get(g:, 'sonokai_disable_terminal_colors', 0),
\ 'better_performance': get(g:, 'sonokai_better_performance', 0),
\ }
endfunction "}}}
function! sonokai#get_palette(style, colors_override) "{{{
if a:style ==# 'default'
let palette = {
\ 'black': ['#181819', '232'],
\ 'bg_dim': ['#222327', '232'],
\ 'bg0': ['#2c2e34', '235'],
\ 'bg1': ['#33353f', '236'],
\ 'bg2': ['#363944', '236'],
\ 'bg3': ['#3b3e48', '237'],
\ 'bg4': ['#414550', '237'],
\ 'bg_red': ['#ff6077', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#a7df78', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#85d3f2', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e2e2e3', '250'],
\ 'red': ['#fc5d7c', '203'],
\ 'orange': ['#f39660', '215'],
\ 'yellow': ['#e7c664', '179'],
\ 'green': ['#9ed072', '107'],
\ 'blue': ['#76cce0', '110'],
\ 'purple': ['#b39df3', '176'],
\ 'grey': ['#7f8490', '246'],
\ 'grey_dim': ['#595f6f', '240'],
\ 'none': ['NONE', 'NONE']
\ }
elseif a:style ==# 'shusia'
let palette = {
\ 'black': ['#1a181a', '232'],
\ 'bg_dim': ['#211f21', '232'],
\ 'bg0': ['#2d2a2e', '235'],
\ 'bg1': ['#37343a', '236'],
\ 'bg2': ['#3b383e', '236'],
\ 'bg3': ['#423f46', '237'],
\ 'bg4': ['#49464e', '237'],
\ 'bg_red': ['#ff6188', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#a9dc76', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#78dce8', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e3e1e4', '250'],
\ 'red': ['#f85e84', '203'],
\ 'orange': ['#ef9062', '215'],
\ 'yellow': ['#e5c463', '179'],
\ 'green': ['#9ecd6f', '107'],
\ 'blue': ['#7accd7', '110'],
\ 'purple': ['#ab9df2', '176'],
\ 'grey': ['#848089', '246'],
\ 'grey_dim': ['#605d68', '240'],
\ 'none': ['NONE', 'NONE']
\ }
elseif a:style ==# 'andromeda'
let palette = {
\ 'black': ['#181a1c', '232'],
\ 'bg_dim': ['#252630', '232'],
\ 'bg0': ['#2b2d3a', '235'],
\ 'bg1': ['#333648', '236'],
\ 'bg2': ['#363a4e', '236'],
\ 'bg3': ['#393e53', '237'],
\ 'bg4': ['#3f445b', '237'],
\ 'bg_red': ['#ff6188', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#a9dc76', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#77d5f0', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e1e3e4', '250'],
\ 'red': ['#fb617e', '203'],
\ 'orange': ['#f89860', '215'],
\ 'yellow': ['#edc763', '179'],
\ 'green': ['#9ed06c', '107'],
\ 'blue': ['#6dcae8', '110'],
\ 'purple': ['#bb97ee', '176'],
\ 'grey': ['#7e8294', '246'],
\ 'grey_dim': ['#5a5e7a', '240'],
\ 'none': ['NONE', 'NONE']
\ }
elseif a:style ==# 'atlantis'
let palette = {
\ 'black': ['#181a1c', '232'],
\ 'bg_dim': ['#24272e', '232'],
\ 'bg0': ['#2a2f38', '235'],
\ 'bg1': ['#333846', '236'],
\ 'bg2': ['#373c4b', '236'],
\ 'bg3': ['#3d4455', '237'],
\ 'bg4': ['#424b5b', '237'],
\ 'bg_red': ['#ff6d7e', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#a5e179', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#7ad5f1', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e1e3e4', '250'],
\ 'red': ['#ff6578', '203'],
\ 'orange': ['#f69c5e', '215'],
\ 'yellow': ['#eacb64', '179'],
\ 'green': ['#9dd274', '107'],
\ 'blue': ['#72cce8', '110'],
\ 'purple': ['#ba9cf3', '176'],
\ 'grey': ['#828a9a', '246'],
\ 'grey_dim': ['#5a6477', '240'],
\ 'none': ['NONE', 'NONE']
\ }
elseif a:style ==# 'maia'
let palette = {
\ 'black': ['#1c1e1f', '232'],
\ 'bg_dim': ['#21282c', '232'],
\ 'bg0': ['#273136', '235'],
\ 'bg1': ['#313b42', '236'],
\ 'bg2': ['#353f46', '236'],
\ 'bg3': ['#3a444b', '237'],
\ 'bg4': ['#414b53', '237'],
\ 'bg_red': ['#ff6d7e', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#a2e57b', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#7cd5f1', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e1e2e3', '250'],
\ 'red': ['#f76c7c', '203'],
\ 'orange': ['#f3a96a', '215'],
\ 'yellow': ['#e3d367', '179'],
\ 'green': ['#9cd57b', '107'],
\ 'blue': ['#78cee9', '110'],
\ 'purple': ['#baa0f8', '176'],
\ 'grey': ['#82878b', '246'],
\ 'grey_dim': ['#55626d', '240'],
\ 'none': ['NONE', 'NONE']
\ }
elseif a:style ==# 'espresso'
let palette = {
\ 'black': ['#1f1e1c', '232'],
\ 'bg_dim': ['#242120', '232'],
\ 'bg0': ['#312c2b', '235'],
\ 'bg1': ['#393230', '236'],
\ 'bg2': ['#413937', '236'],
\ 'bg3': ['#49403c', '237'],
\ 'bg4': ['#4e433f', '237'],
\ 'bg_red': ['#fd6883', '203'],
\ 'diff_red': ['#55393d', '52'],
\ 'bg_green': ['#adda78', '107'],
\ 'diff_green': ['#394634', '22'],
\ 'bg_blue': ['#85dad2', '110'],
\ 'diff_blue': ['#354157', '17'],
\ 'diff_yellow':['#4e432f', '54'],
\ 'fg': ['#e4e3e1', '250'],
\ 'red': ['#f86882', '203'],
\ 'orange': ['#f08d71', '215'],
\ 'yellow': ['#f0c66f', '179'],
\ 'green': ['#a6cd77', '107'],
\ 'blue': ['#81d0c9', '110'],
\ 'purple': ['#9fa0e1', '176'],
\ 'grey': ['#90817b', '246'],
\ 'grey_dim': ['#6a5e59', '240'],
\ 'none': ['NONE', 'NONE']
\ }
endif
return extend(palette, a:colors_override)
endfunction "}}}
function! sonokai#highlight(group, fg, bg, ...) "{{{
execute 'highlight' a:group
\ 'guifg=' . a:fg[0]
\ 'guibg=' . a:bg[0]
\ 'ctermfg=' . a:fg[1]
\ 'ctermbg=' . a:bg[1]
\ 'gui=' . (a:0 >= 1 ?
\ a:1 :
\ 'NONE')
\ 'cterm=' . (a:0 >= 1 ?
\ a:1 :
\ 'NONE')
\ 'guisp=' . (a:0 >= 2 ?
\ a:2[0] :
\ 'NONE')
endfunction "}}}
function! sonokai#syn_gen(path, last_modified, msg) "{{{
" Generate the `after/syntax` directory.
let full_content = join(readfile(a:path), "\n") " Get the content of `colors/sonokai.vim`
let syn_conent = []
let rootpath = sonokai#syn_rootpath(a:path) " Get the path to place the `after/syntax` directory.
call substitute(full_content, '" syn_begin.\{-}syn_end', '\=add(syn_conent, submatch(0))', 'g') " Search for 'syn_begin.\{-}syn_end' (non-greedy) and put all the search results into a list.
for content in syn_conent
let syn_list = []
call substitute(matchstr(matchstr(content, 'syn_begin:.\{-}{{{'), ':.\{-}{{{'), '\(\w\|-\)\+', '\=add(syn_list, submatch(0))', 'g') " Get the file types. }}}}}}
for syn in syn_list
call sonokai#syn_write(rootpath, syn, content) " Write the content.
endfor
endfor
call sonokai#syn_write(rootpath, 'text', "let g:sonokai_last_modified = '" . a:last_modified . "'") " Write the last modified time to `after/syntax/text/sonokai.vim`
let syntax_relative_path = has('win32') ? '\after\syntax' : '/after/syntax'
if a:msg ==# 'update'
echohl WarningMsg | echom '[sonokai] Updated ' . rootpath . syntax_relative_path | echohl None
call sonokai#ftplugin_detect(a:path)
else
echohl WarningMsg | echom '[sonokai] Generated ' . rootpath . syntax_relative_path | echohl None
execute 'set runtimepath+=' . fnamemodify(rootpath, ':p') . 'after'
endif
endfunction "}}}
function! sonokai#syn_write(rootpath, syn, content) "{{{
" Write the content.
let syn_path = a:rootpath . '/after/syntax/' . a:syn . '/sonokai.vim' " The path of a syntax file.
" create a new file if it doesn't exist
if !filereadable(syn_path)
call mkdir(a:rootpath . '/after/syntax/' . a:syn, 'p')
call writefile([
\ "if !exists('g:colors_name') || g:colors_name !=# 'sonokai'",
\ ' finish',
\ 'endif'
\ ], syn_path, 'a') " Abort if the current color scheme is not sonokai.
call writefile([
\ "if index(g:sonokai_loaded_file_types, '" . a:syn . "') ==# -1",
\ " call add(g:sonokai_loaded_file_types, '" . a:syn . "')",
\ 'else',
\ ' finish',
\ 'endif'
\ ], syn_path, 'a') " Abort if this file type has already been loaded.
endif
" If there is something like `call sonokai#highlight()`, then add
" code to initialize the palette and configuration.
if matchstr(a:content, 'sonokai#highlight') !=# ''
call writefile([
\ 'let s:configuration = sonokai#get_configuration()',
\ 'let s:palette = sonokai#get_palette(s:configuration.style, s:configuration.colors_override)'
\ ], syn_path, 'a')
endif
" Append the content.
call writefile(split(a:content, "\n"), syn_path, 'a')
" Add modeline.
call writefile(['" vim: set sw=2 ts=2 sts=2 et tw=80 ft=vim fdm=marker fmr={{{,}}}:'], syn_path, 'a')
endfunction "}}}
function! sonokai#syn_rootpath(path) "{{{
" Get the directory where `after/syntax` is generated.
if (matchstr(a:path, '^/usr/share') ==# '') " Return the plugin directory. The `after/syntax` directory should never be generated in `/usr/share`, even if you are a root user.
return fnamemodify(a:path, ':p:h:h')
else " Use vim home directory.
if has('nvim')
return stdpath('config')
else
return expand('~') . '/.vim'
endif
endif
endfunction "}}}
function! sonokai#syn_newest(path, last_modified) "{{{
" Determine whether the current syntax files are up to date by comparing the last modified time in `colors/sonokai.vim` and `after/syntax/text/sonokai.vim`.
let rootpath = sonokai#syn_rootpath(a:path)
execute 'source ' . rootpath . '/after/syntax/text/sonokai.vim'
return a:last_modified ==# g:sonokai_last_modified ? 1 : 0
endfunction "}}}
function! sonokai#syn_clean(path, msg) "{{{
" Clean the `after/syntax` directory.
let rootpath = sonokai#syn_rootpath(a:path)
" Remove `after/syntax/**/sonokai.vim`.
let file_list = split(globpath(rootpath, 'after/syntax/**/sonokai.vim'), "\n")
for file in file_list
call delete(file)
endfor
" Remove empty directories.
let dir_list = split(globpath(rootpath, 'after/syntax/*'), "\n")
for dir in dir_list
if globpath(dir, '*') ==# ''
call delete(dir, 'd')
endif
endfor
if globpath(rootpath . '/after/syntax', '*') ==# ''
call delete(rootpath . '/after/syntax', 'd')
endif
if globpath(rootpath . '/after', '*') ==# ''
call delete(rootpath . '/after', 'd')
endif
if a:msg
let syntax_relative_path = has('win32') ? '\after\syntax' : '/after/syntax'
echohl WarningMsg | echom '[sonokai] Cleaned ' . rootpath . syntax_relative_path | echohl None
endif
endfunction "}}}
function! sonokai#syn_exists(path) "{{{
return filereadable(sonokai#syn_rootpath(a:path) . '/after/syntax/text/sonokai.vim')
endfunction "}}}
function! sonokai#ftplugin_detect(path) "{{{
" Check if /after/ftplugin exists.
" This directory is generated in earlier versions, users may need to manually clean it.
let rootpath = sonokai#syn_rootpath(a:path)
if filereadable(sonokai#syn_rootpath(a:path) . '/after/ftplugin/text/sonokai.vim')
let ftplugin_relative_path = has('win32') ? '\after\ftplugin' : '/after/ftplugin'
echohl WarningMsg | echom '[sonokai] Detected ' . rootpath . ftplugin_relative_path | echohl None
echohl WarningMsg | echom '[sonokai] This directory is no longer used, you may need to manually delete it.' | echohl None
endif
endfunction "}}}
" vim: set sw=2 ts=2 sts=2 et tw=80 ft=vim fdm=marker fmr={{{,}}}: