This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
" Base16 Classic Dark vim-airline-theme (https://github.com/dawikur/base16-vim-airline-themes)
|
||||
" For vim-airline (https://github.com/vim-airline/vim-airline)
|
||||
" By Jason Heeris (http://heeris.id.au)
|
||||
|
||||
let s:scheme_slug = 'sunbather_dark'
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette = {}
|
||||
|
||||
" GUI color definitions
|
||||
let s:gui00 = '#151515'
|
||||
let s:gui01 = '#202020'
|
||||
let s:gui02 = '#303030'
|
||||
let s:gui03 = '#505050'
|
||||
let s:gui04 = '#B0B0B0'
|
||||
let s:gui05 = '#D0D0D0'
|
||||
let s:gui06 = '#E0E0E0'
|
||||
let s:gui07 = '#F5F5F5'
|
||||
let s:gui08 = '#AC4142'
|
||||
let s:gui09 = '#D28445'
|
||||
let s:gui0A = '#F4BF75'
|
||||
let s:gui0B = '#90A959'
|
||||
let s:gui0C = '#75B5AA'
|
||||
let s:gui0D = '#6A9FB5'
|
||||
let s:gui0E = '#AA759F'
|
||||
let s:gui0F = '#8F5536'
|
||||
|
||||
" Terminal color definitions
|
||||
let s:cterm00 = "00"
|
||||
let s:cterm03 = "08"
|
||||
let s:cterm05 = "07"
|
||||
let s:cterm07 = "15"
|
||||
let s:cterm08 = "01"
|
||||
let s:cterm0A = "03"
|
||||
let s:cterm0B = "02"
|
||||
let s:cterm0C = "06"
|
||||
let s:cterm0D = "04"
|
||||
let s:cterm0E = "05"
|
||||
if exists("base16colorspace") && base16colorspace == "256"
|
||||
let s:cterm01 = "18"
|
||||
let s:cterm02 = "19"
|
||||
let s:cterm04 = "20"
|
||||
let s:cterm06 = "21"
|
||||
let s:cterm09 = "16"
|
||||
let s:cterm0F = "17"
|
||||
else
|
||||
let s:cterm01 = "10"
|
||||
let s:cterm02 = "11"
|
||||
let s:cterm04 = "12"
|
||||
let s:cterm06 = "13"
|
||||
let s:cterm09 = "09"
|
||||
let s:cterm0F = "14"
|
||||
endif
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.normal = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui04, s:cterm01, s:cterm04 ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.normal_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.insert = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui0B, s:cterm01, s:cterm0B ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.insert_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.replace = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui0E, s:cterm01, s:cterm0E ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.replace_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.visual = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui09, s:cterm01, s:cterm09 ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.visual_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.inactive = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui01, s:cterm01, s:cterm01 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ],
|
||||
\ [ s:gui05, s:gui01, s:cterm05, s:cterm01 ])
|
||||
@@ -1,85 +0,0 @@
|
||||
" Base16 Summerfruit Light vim-airline-theme (https://github.com/dawikur/base16-vim-airline-themes)
|
||||
" For vim-airline (https://github.com/vim-airline/vim-airline)
|
||||
" By Christopher Corley (http://christop.club/)
|
||||
|
||||
let s:scheme_slug = 'sunbather_light'
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette = {}
|
||||
|
||||
" GUI color definitions
|
||||
let s:gui00 = '#FFFFFF'
|
||||
let s:gui01 = '#E0E0E0'
|
||||
let s:gui02 = '#D0D0D0'
|
||||
let s:gui03 = '#B0B0B0'
|
||||
let s:gui04 = '#000000'
|
||||
let s:gui05 = '#101010'
|
||||
let s:gui06 = '#151515'
|
||||
let s:gui07 = '#202020'
|
||||
let s:gui08 = '#FF0086'
|
||||
let s:gui09 = '#FD8900'
|
||||
let s:gui0A = '#ABA800'
|
||||
let s:gui0B = '#00C918'
|
||||
let s:gui0C = '#1FAAAA'
|
||||
let s:gui0D = '#3777E6'
|
||||
let s:gui0E = '#AD00A1'
|
||||
let s:gui0F = '#CC6633'
|
||||
|
||||
" Terminal color definitions
|
||||
let s:cterm00 = "00"
|
||||
let s:cterm03 = "08"
|
||||
let s:cterm05 = "07"
|
||||
let s:cterm07 = "15"
|
||||
let s:cterm08 = "01"
|
||||
let s:cterm0A = "03"
|
||||
let s:cterm0B = "02"
|
||||
let s:cterm0C = "06"
|
||||
let s:cterm0D = "04"
|
||||
let s:cterm0E = "05"
|
||||
if exists("base16colorspace") && base16colorspace == "256"
|
||||
let s:cterm01 = "18"
|
||||
let s:cterm02 = "19"
|
||||
let s:cterm04 = "20"
|
||||
let s:cterm06 = "21"
|
||||
let s:cterm09 = "16"
|
||||
let s:cterm0F = "17"
|
||||
else
|
||||
let s:cterm01 = "10"
|
||||
let s:cterm02 = "11"
|
||||
let s:cterm04 = "12"
|
||||
let s:cterm06 = "13"
|
||||
let s:cterm09 = "09"
|
||||
let s:cterm0F = "14"
|
||||
endif
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.normal = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui04, s:cterm01, s:cterm04 ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.normal_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.insert = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui0B, s:cterm01, s:cterm0B ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.insert_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.replace = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui0E, s:cterm01, s:cterm0E ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.replace_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.visual = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui09, s:cterm01, s:cterm09 ],
|
||||
\ [ s:gui04, s:gui02, s:cterm04, s:cterm02 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ])
|
||||
let g:airline#themes#{s:scheme_slug}#palette.visual_modified = {
|
||||
\ 'airline_c' : [ s:gui07, s:gui01, s:cterm07, s:cterm01 ]}
|
||||
|
||||
let g:airline#themes#{s:scheme_slug}#palette.inactive = airline#themes#generate_color_map(
|
||||
\ [ s:gui01, s:gui01, s:cterm01, s:cterm01 ],
|
||||
\ [ s:gui04, s:gui01, s:cterm04, s:cterm01 ],
|
||||
\ [ s:gui05, s:gui01, s:cterm05, s:cterm01 ])
|
||||
@@ -1,27 +0,0 @@
|
||||
" vim build with clipboard support doesn't need this and it work
|
||||
" better than neovim
|
||||
|
||||
func s:helper()
|
||||
call system('printf "%s" '.shellescape(join(v:event['regcontents'], "\n")).' | xclip -sel clip' )
|
||||
endfunc
|
||||
|
||||
func! clipboard#get()
|
||||
endfunc
|
||||
|
||||
func! clipboard#enable()
|
||||
augroup WSLClipboard
|
||||
au!
|
||||
au TextYankPost * call s:helper()
|
||||
augroup END
|
||||
endfunc
|
||||
|
||||
func! clipboard#disable()
|
||||
augroup WSLClipboard
|
||||
au!
|
||||
augroup END
|
||||
endfunc
|
||||
|
||||
func! clipboard#paste()
|
||||
return system('xclip -o -sel clip' )
|
||||
endfunc
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
let s:path = get(g:, '_config_path', fnamemodify(
|
||||
\ resolve(expand('<sfile>:p')), ':h:h').'/_config.vim')
|
||||
let s:config = {}
|
||||
|
||||
function! config#saveConfig()
|
||||
let p = utils#readvar(s:path)
|
||||
if type(p) != type({})
|
||||
let p = {}
|
||||
endif
|
||||
let vim_type = has('nvim') ? 'nvim' : 'vim'
|
||||
let config = has_key(p, vim_type) && type(p[vim_type]) == v:t_dict
|
||||
\ ? p[vim_type] : {}
|
||||
let config = utils#merge(config, s:config)
|
||||
|
||||
" vim and nvim may have diferenrt available plugins
|
||||
let p[vim_type] = config
|
||||
call utils#savevar(p, s:path)
|
||||
endfunction
|
||||
|
||||
function! s:loadConfig()
|
||||
let result = utils#readvar(s:path)
|
||||
" if it is dictionary
|
||||
let vim_type = has('nvim') ? 'nvim' : 'vim'
|
||||
if type(result) == v:t_dict
|
||||
if has_key(result, vim_type)
|
||||
let config = result[vim_type]
|
||||
if type(config) == v:t_dict
|
||||
let s:config = config
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! config#setConfig(dict)
|
||||
let s:config = utils#merge(s:config, a:config)
|
||||
endfunction
|
||||
|
||||
function! config#init()
|
||||
call config#loadConfig()
|
||||
augroup config
|
||||
autocmd!
|
||||
autocmd VimLeave * call config#saveConfig()
|
||||
augroup END
|
||||
endfunction
|
||||
@@ -1,171 +0,0 @@
|
||||
|
||||
" this intent to create a list of options that can be toggled on/off
|
||||
|
||||
let s:options = {}
|
||||
|
||||
if !has('nvim')
|
||||
import autoload 'fuzzyy/utils/selector.vim'
|
||||
endif
|
||||
|
||||
" opt is a dictionary with the following keys(* = required):
|
||||
" togglefunc and enablefunc/disablefunc are mutually exclusive
|
||||
" params:
|
||||
" - name: name of the option
|
||||
" - opt: a dictionary with following options():
|
||||
" - desc: description,
|
||||
" - togglefunc: function reference, if exists, enablefunc and disablefunc
|
||||
" will be ignored,
|
||||
" - enablefunc: function reference, if this exists, disablefunc must exists
|
||||
" as well and vice verse
|
||||
" - disablefunc: function reference,
|
||||
" - isEnabled: string, true or false or function reference. only needed when
|
||||
" using enablefunc and disablefunc
|
||||
function! options#add(name, opt) abort
|
||||
if (!has_key(a:opt, 'togglefunc')
|
||||
\ && (!has_key(a:opt, 'enablefunc') || !has_key(a:opt, 'disablefunc')))
|
||||
throw 'invalid option (togglefunc or enablefunc/disablefunc must be set))'
|
||||
endif
|
||||
|
||||
if !has_key(a:opt, 'isEnabled') && !has_key(a:opt, 'togglefunc')
|
||||
throw 'specify initial state(isEnabled) or set togglefunc'
|
||||
endif
|
||||
|
||||
for key in ['togglefunc', 'enablefunc', 'disablefunc']
|
||||
if has_key(a:opt, key) && type(a:opt[key]) != v:t_func
|
||||
throw key . ' must be a function reference'
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !has_key(a:opt, 'desc')
|
||||
let a:opt['desc'] = ''
|
||||
endif
|
||||
|
||||
let s:options[a:name] = a:opt
|
||||
endfunction
|
||||
|
||||
" Register a simple vim option
|
||||
" params:
|
||||
" - name: name of the option
|
||||
" - dictionary(optional):
|
||||
" - desc: description of the option
|
||||
function! options#addVimOption(name, ...) abort
|
||||
let opt = {}
|
||||
|
||||
func opt.togglefunc(key)
|
||||
if eval('&' . a:key)
|
||||
execute('set no' . a:key)
|
||||
else
|
||||
execute('set ' . a:key)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
if a:0 > 0
|
||||
let opt['desc'] = a:1
|
||||
endif
|
||||
|
||||
call options#add(a:name, opt)
|
||||
endfunction
|
||||
|
||||
function! options#getAll() abort
|
||||
let list = []
|
||||
for [key, val] in items(s:options)
|
||||
let desc = val.desc != '' ? ' - ' . val.desc : ''
|
||||
call add(list, [key, key . desc])
|
||||
endfor
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! options#getAllRaw() abort
|
||||
let list = []
|
||||
for [key, val] in items(s:options)
|
||||
call add(list, [key, desc])
|
||||
endfor
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! options#toggle(name) abort
|
||||
if !has_key(s:options, a:name)
|
||||
throw 'invalid option name: ' . a:name
|
||||
endif
|
||||
|
||||
let opt = s:options[a:name]
|
||||
if has_key(opt, 'togglefunc')
|
||||
call opt.togglefunc(a:name)
|
||||
else
|
||||
if type(opt.isEnabled) == v:t_func
|
||||
let isEnabled = opt.isEnabled()
|
||||
else
|
||||
let isEnabled = opt.isEnabled
|
||||
endif
|
||||
if isEnabled
|
||||
call opt.disablefunc()
|
||||
else
|
||||
call opt.enablefunc()
|
||||
endif
|
||||
if type(opt.isEnabled) != v:t_func
|
||||
let s:options[a:name].isEnabled = opt.isEnabled ? v:false : v:true
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! options#preSet()
|
||||
call options#addVimOption('number', 'show line number')
|
||||
call options#addVimOption('relativenumber')
|
||||
|
||||
let colorcolumnOpt = {
|
||||
\ 'desc': 'show color column',
|
||||
\ 'isEnabled': &colorcolumn != ''
|
||||
\ }
|
||||
function colorcolumnOpt.togglefunc(...)
|
||||
if &colorcolumn == ''
|
||||
let &colorcolumn = '80'
|
||||
else
|
||||
let &colorcolumn = ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
call options#add('colorcolumn', colorcolumnOpt)
|
||||
|
||||
let toggleBgOpt = {
|
||||
\ 'desc': 'toggle dark/light theme',
|
||||
\ }
|
||||
function toggleBgOpt.togglefunc(...)
|
||||
call theme#toggleBg()
|
||||
endfunction
|
||||
call options#add('dark/light', toggleBgOpt)
|
||||
endfunction
|
||||
|
||||
function! s:select(wid, result)
|
||||
let result = a:result[0]
|
||||
if result != v:null
|
||||
let key = s:rmap[result]
|
||||
call options#toggle(key)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! options#fzf_options()
|
||||
let list = []
|
||||
let s:rmap = {}
|
||||
for [key, val] in items(s:options)
|
||||
let desc = val.desc != '' ? key . ' - ' . val.desc : key
|
||||
call add(list, desc)
|
||||
let s:rmap[desc] = key
|
||||
endfor
|
||||
let s:fzf_list = list
|
||||
call selector.Start( list,
|
||||
\ {
|
||||
\ 'select_cb' : function('s:select'),
|
||||
\ 'yoffset' : 0.3,
|
||||
\ 'height' : 0.4,
|
||||
\ 'title' : 'Options',
|
||||
\ 'width' : 0.4
|
||||
\ })
|
||||
endfunc
|
||||
|
||||
function! options#init()
|
||||
call options#preSet()
|
||||
if !has('nvim')
|
||||
command! -nargs=0 Options call options#fzf_options()
|
||||
nnoremap <silent> <leader>fo :Options<CR>
|
||||
endif
|
||||
endfunction
|
||||
@@ -1,8 +0,0 @@
|
||||
func! os#getOS()
|
||||
if has("win64") || has("win32") || has("win16")
|
||||
return "Windows"
|
||||
else
|
||||
return substitute(system('uname'), '\n', '', '')
|
||||
endif
|
||||
endfunc
|
||||
|
||||
+98
-361
@@ -1,383 +1,120 @@
|
||||
let s:path = get(g:, 'theme_config_path', fnamemodify(
|
||||
\ resolve(expand('<sfile>:p')), ':h:h').'/theme_config.vim')
|
||||
let s:path = get(g:, 'vim_dir', expand('~/.vim')) . '/theme.json'
|
||||
let s:defaults = {
|
||||
\ 'background': 'dark',
|
||||
\ 'dark': {'theme': 'moonfly', 'transparent': v:false},
|
||||
\ 'light': {'theme': 'PaperColor', 'transparent': v:false}}
|
||||
let s:config = deepcopy(s:defaults)
|
||||
let s:applying = v:false
|
||||
let s:transparent_groups = [
|
||||
\ 'Normal', 'NormalNC', 'EndOfBuffer', 'Folded', 'LineNr', 'SignColumn',
|
||||
\ 'StatusLine', 'StatusLineNC', 'VertSplit', 'WinSeparator', 'NormalFloat']
|
||||
|
||||
let s:themefixes = []
|
||||
|
||||
let s:bgType = has('termguicolors') ? 'guibg' : 'ctermbg'
|
||||
|
||||
" sometimes even in termguicolors, when guibg is not set, the bg will fall
|
||||
" back to use ctermbg, so we have to set them both to none
|
||||
let s:bgNonType = !has('termguicolors') ? 'guibg=NONE' : 'ctermbg=NONE'
|
||||
let s:transBlendOpt = has('nvim') ? ' blend=0' : ''
|
||||
|
||||
let s:default_config = {
|
||||
\ 'background': 'dark',
|
||||
\ 'light': {
|
||||
\ 'theme': 'sunbather_light',
|
||||
\ 'default': 'sunbather_light',
|
||||
\ 'transparent': v:false,
|
||||
\ 'airline_theme': 'sunbather_light',
|
||||
\ },
|
||||
\ 'dark': {
|
||||
\ 'theme': 'base16-harmonic-dark',
|
||||
\ 'default': 'base16-harmonic-dark',
|
||||
\ 'transparent': v:false,
|
||||
\ 'airline_theme': 'base16-harmonic-dark',
|
||||
\ },
|
||||
\ }
|
||||
|
||||
" When enable transparent background, these group will be set to transparent
|
||||
let s:transgroups = [
|
||||
\ 'Normal', 'NormalNC', 'Comment', 'Constant', 'Special', 'Identifier',
|
||||
\ 'Folded', 'Statusline', 'StatuslineNC',
|
||||
\ 'Statement', 'PreProc', 'Type', 'Underlined', 'String', 'Function',
|
||||
\ 'Conditional', 'Repeat', 'Operator', 'Structure', 'LineNr', 'NonText',
|
||||
\ 'SignColumn', 'CursorLineNr', 'EndOfBuffer', 'VertSplit',
|
||||
\ 'DiagnosticSignWarn', 'DiagnosticSignError', 'DiagnosticSignInfo',]
|
||||
|
||||
" background group that will be set to normal's background color
|
||||
let s:cleanbg = ['DiagnosticSignWarn', 'DiagnosticSignError', 'DiagnosticSignInfo',
|
||||
\ 'VertSplit', 'LineNr', 'SignColumn', 'NormalFloat']
|
||||
|
||||
let s:config = get(g:, 'theme_config', s:default_config)
|
||||
|
||||
function! theme#setConfig(bg, key, value)
|
||||
let s:config[a:bg][a:key] = a:value
|
||||
endfunction
|
||||
" register extra transparent hi group
|
||||
function! theme#getCleanBg()
|
||||
return s:cleanbg
|
||||
endfunction
|
||||
|
||||
function! theme#getBgType()
|
||||
return s:bgType
|
||||
endfunction
|
||||
|
||||
function! theme#getTransGroup()
|
||||
return s:transgroups
|
||||
endfunction
|
||||
|
||||
" register extra transparent hi group
|
||||
function theme#addCleanBg(group)
|
||||
let li = type(a:group) == 1 ? [a:group] : a:group
|
||||
for hi in li
|
||||
if index(s:cleanbg, hi) == -1
|
||||
call add(s:cleanbg, hi)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" register extra transparent hi group
|
||||
function theme#addTransGroup(group)
|
||||
let li = type(a:group) == 1 ? [a:group] : a:group
|
||||
for hi in li
|
||||
if index(s:transgroups, hi) == -1
|
||||
call add(s:transgroups, hi)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! theme#setColor(bg, ...)
|
||||
let colors_name = a:0 > 0 ? a:1 : s:config[a:bg].theme
|
||||
if !utils#hascolorscheme(colors_name)
|
||||
let colors_name = 'default'
|
||||
endif
|
||||
noa let &bg = a:bg
|
||||
call theme#setStlColor(a:bg)
|
||||
let s:config.background = a:bg
|
||||
let s:config[a:bg].theme = colors_name
|
||||
noa execute("colorscheme " . colors_name)
|
||||
if &background != a:bg
|
||||
noa let &bg = a:bg
|
||||
endif
|
||||
" some theme will pick their own airline theme or airline will
|
||||
" automatically pick theme based on colorscheme
|
||||
if exists('g:airline_theme') && g:airline_theme != s:config[a:bg].airline_theme
|
||||
call theme#setStlColor(a:bg, g:airline_theme)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Change bottom airline/lualine theme
|
||||
function! theme#setStlColor(bg, ...)
|
||||
if has('nvim-0.5')
|
||||
" lualine will change theme automatically
|
||||
function! s:Merge(defaults, override) abort
|
||||
let l:result = deepcopy(a:defaults)
|
||||
if type(a:override) != v:t_dict
|
||||
return l:result
|
||||
endif
|
||||
for [l:key, l:value] in items(a:override)
|
||||
if type(l:value) == v:t_dict && type(get(l:result, l:key)) == v:t_dict
|
||||
let l:result[l:key] = s:Merge(l:result[l:key], l:value)
|
||||
else
|
||||
if utils#hasplug('vim-airline') && exists(':AirlineTheme')
|
||||
let theme = a:0 > 0 ? a:1 : s:config[a:bg].airline_theme
|
||||
try
|
||||
execute('AirlineTheme ' . theme)
|
||||
catch
|
||||
let theme = s:default_config[a:bg].airline_theme
|
||||
execute('AirlineTheme ' . theme)
|
||||
endtry
|
||||
let s:config[a:bg].airline_theme = theme
|
||||
endif
|
||||
let l:result[l:key] = l:value
|
||||
endif
|
||||
endfor
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
function! theme#inTransparent()
|
||||
return s:config[&background].transparent
|
||||
function! s:Available(name) abort
|
||||
return !empty(globpath(&runtimepath, 'colors/' . a:name . '.vim', 1, 1))
|
||||
endfunction
|
||||
|
||||
" return 1 if link to other group
|
||||
" return 2 if not exists
|
||||
" return 0 if normal
|
||||
function! s:hiType(group)
|
||||
try
|
||||
let hi = execute('hi '.a:group)
|
||||
if hi =~# 'link'
|
||||
return 2
|
||||
endif
|
||||
catch
|
||||
return 1
|
||||
endtry
|
||||
return 0
|
||||
function! s:ApplyTransparency() abort
|
||||
if !s:config[&background].transparent
|
||||
return
|
||||
endif
|
||||
for l:group in s:transparent_groups
|
||||
execute 'highlight ' . l:group . ' guibg=NONE ctermbg=NONE'
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function s:applyTransparent()
|
||||
let tail = ' ' . s:bgType . '=NONE term=NONE gui=NONE cterm=NONE '
|
||||
if has('nvim')
|
||||
let tail .= s:transBlendOpt
|
||||
else
|
||||
let tail .= s:bgNonType
|
||||
endif
|
||||
for group in s:transgroups
|
||||
if s:hiType(group) != 0
|
||||
continue
|
||||
endif
|
||||
" cterm and term sometimes are set to reverse so we need to clean them
|
||||
" too
|
||||
" for the last part, we can't clear all terms or it will fall back to
|
||||
" default which is not transparent
|
||||
execute('hi! '.group . tail)
|
||||
endfor
|
||||
call s:generalThemeFix()
|
||||
" for group in s:cleanbg
|
||||
" if s:hiType(group) != 0
|
||||
" continue
|
||||
" endif
|
||||
" execute('hi! '.group . tail)
|
||||
" endfor
|
||||
function! s:Load() abort
|
||||
if !filereadable(s:path)
|
||||
return deepcopy(s:defaults)
|
||||
endif
|
||||
try
|
||||
let l:saved = json_decode(join(readfile(s:path), "\n"))
|
||||
return s:Merge(s:defaults, l:saved)
|
||||
catch
|
||||
return deepcopy(s:defaults)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" some callback function to enable transparent background
|
||||
" for specific colorscheme
|
||||
|
||||
" or general callback for all colorscheme when specific colorscheme callback
|
||||
" is not available
|
||||
" g:dark_transparent_enable_cb
|
||||
" g:light_transparent_enable_cb
|
||||
|
||||
function! theme#enableTransparent() abort
|
||||
let colorscheme_name = utils#colorschemename()
|
||||
let bg = &background
|
||||
if exists('g:'.bg.'_transparent_enable_cb') && g:dark_transparent_enable_cb != ''
|
||||
let cb_name = get(g:, bg.'_transparent_enable_cb', '')
|
||||
if cb_name != ''
|
||||
execute('call '.cb_name.'()')
|
||||
endif
|
||||
elseif exists('g:Transparent_enable_func')
|
||||
if type(g:Transparent_enable_func) != v:t_func
|
||||
echoerr 'g:Transparent_enable_func is not a function'
|
||||
endif
|
||||
call g:Transparent_enable_func()
|
||||
else
|
||||
call s:applyTransparent()
|
||||
augroup SetTransparent
|
||||
autocmd!
|
||||
autocmd ColorScheme * call s:applyTransparent()
|
||||
augroup END
|
||||
endif
|
||||
let s:config[bg].transparent = v:true
|
||||
function! theme#save() abort
|
||||
try
|
||||
call mkdir(fnamemodify(s:path, ':h'), 'p')
|
||||
call writefile([json_encode(s:config)], s:path)
|
||||
catch
|
||||
" A read-only home directory should not prevent Vim from exiting cleanly.
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! theme#disableTransparent() abort
|
||||
augroup SetTransparent
|
||||
autocmd!
|
||||
augroup END
|
||||
let bg = &background
|
||||
let s:config[bg].transparent = v:false
|
||||
let colorscheme_name = utils#colorschemename()
|
||||
if exists('g:'.bg.'_transparent_disable_cb')
|
||||
let cb_name = get(g:, bg.'_transparent_disable_cb', '')
|
||||
if cb_name != ''
|
||||
execute('call '.cb_name.'()')
|
||||
endif
|
||||
elseif exists('g:Transparent_disable_func')
|
||||
if type(g:Transparent_disable_func) != v:t_func
|
||||
echoerr 'g:Transparent_disable_func is not a function'
|
||||
endif
|
||||
call g:Transparent_disable_func()
|
||||
else
|
||||
execute('colorscheme ' . s:config[bg].theme)
|
||||
endif
|
||||
function! theme#apply(name) abort
|
||||
let l:background = &background
|
||||
let l:name = s:Available(a:name) ? a:name
|
||||
\ : (l:background ==# 'dark' ? 'sunbather_dark' : 'sunbather_light')
|
||||
let s:applying = v:true
|
||||
try
|
||||
execute 'colorscheme ' . l:name
|
||||
finally
|
||||
let s:applying = v:false
|
||||
endtry
|
||||
let &background = l:background
|
||||
let s:config.background = l:background
|
||||
let s:config[l:background].theme = l:name
|
||||
call s:ApplyTransparency()
|
||||
endfunction
|
||||
|
||||
" ToggleTransparent background
|
||||
function! theme#toggleTransparent()
|
||||
if s:config[&background].transparent
|
||||
call theme#disableTransparent()
|
||||
else
|
||||
call theme#enableTransparent()
|
||||
endif
|
||||
function! theme#toggleBg() abort
|
||||
let l:background = &background ==# 'dark' ? 'light' : 'dark'
|
||||
let l:theme = s:config[l:background].theme
|
||||
let s:applying = v:true
|
||||
try
|
||||
let &background = l:background
|
||||
finally
|
||||
let s:applying = v:false
|
||||
endtry
|
||||
let s:config.background = l:background
|
||||
call theme#apply(l:theme)
|
||||
endfunction
|
||||
|
||||
" Allow to trigger background
|
||||
function! theme#toggleBg()
|
||||
" Inversion
|
||||
let newbg = &background == "dark" ? 'light' : 'dark'
|
||||
call theme#setColor(newbg)
|
||||
if s:config[&background].transparent
|
||||
call theme#enableTransparent()
|
||||
elseif !s:config[&background].transparent
|
||||
call theme#disableTransparent()
|
||||
endif
|
||||
function! theme#toggleTransparent() abort
|
||||
let s:config[&background].transparent = !s:config[&background].transparent
|
||||
if s:config[&background].transparent
|
||||
call s:ApplyTransparency()
|
||||
else
|
||||
call theme#apply(s:config[&background].theme)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! theme#saveConfig()
|
||||
let p = utils#readvar(s:path)
|
||||
if type(p) != type({})
|
||||
let p = {}
|
||||
endif
|
||||
|
||||
let vim_type = has('nvim') ? 'nvim' : 'vim'
|
||||
|
||||
let config = has_key(p, vim_type) && type(p[vim_type]) == 4
|
||||
\ ? p[vim_type] : {}
|
||||
|
||||
let config = utils#merge(config, s:config)
|
||||
|
||||
" vim and nvim may have diferenrt available plugins
|
||||
let p[vim_type] = config
|
||||
call utils#savevar(p, s:path)
|
||||
function! theme#onColorScheme(name) abort
|
||||
if s:applying
|
||||
return
|
||||
endif
|
||||
if a:name !~# '^sunbather_' && index(['everforest', 'moonfly', 'PaperColor'], a:name) < 0
|
||||
return
|
||||
endif
|
||||
let s:config.background = &background
|
||||
let s:config[&background].theme = a:name
|
||||
call s:ApplyTransparency()
|
||||
endfunction
|
||||
|
||||
function! theme#loadConfig()
|
||||
let result = utils#readvar(s:path)
|
||||
" if it is dictionary
|
||||
let vim_type = has('nvim') ? 'nvim' : 'vim'
|
||||
if type(result) == 4
|
||||
if has_key(result, vim_type)
|
||||
let config = result[vim_type]
|
||||
if type(config) == 4
|
||||
return config
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
function! theme#getHiTerms(group)
|
||||
let output = execute('hi ' . a:group)
|
||||
if stridx(output, 'links to') > 0
|
||||
let higroup = matchstr(output, 'links.to.\?\zs\S\+\ze')
|
||||
return theme#getHiTerms(higroup)
|
||||
endif
|
||||
let list = split(output, '')
|
||||
let dict = {}
|
||||
|
||||
for item in list
|
||||
if stridx(item, '=') > 0
|
||||
let splited = split(item, '=')
|
||||
let dict[splited[0]] = splited[1]
|
||||
endif
|
||||
endfor
|
||||
|
||||
for item in ['guibg', 'ctermbg', 'term', 'cterm', 'guifg', 'ctermfg']
|
||||
if ! has_key(dict, item)
|
||||
let dict[item] = 'NONE'
|
||||
endif
|
||||
endfor
|
||||
return dict
|
||||
endfunction
|
||||
|
||||
function! theme#getHiTerm(group, term)
|
||||
" Store output of group to variable
|
||||
let output = theme#getHiTerms(a:group)
|
||||
return output[a:term]
|
||||
endfunction
|
||||
|
||||
function! s:regiesterThemeFix(Func)
|
||||
call add(s:theme_fix, a:Func)
|
||||
endfunction
|
||||
|
||||
function! s:generalThemeFix()
|
||||
" The following is for getting rid of the vim split bar and match its
|
||||
" and number cols' color with backgroud
|
||||
" if theme#inTransparent()
|
||||
" return
|
||||
" endif
|
||||
if &bg != s:config.background
|
||||
execute('set bg=' . s:config.background)
|
||||
endif
|
||||
|
||||
let normal = theme#getHiTerms('normal')
|
||||
let hiTerms = ' '
|
||||
for term in ['guibg', 'ctermbg', 'term', 'cterm']
|
||||
let hiTerms .= term . '=' . normal[term] . ' '
|
||||
endfor
|
||||
|
||||
for group in s:cleanbg
|
||||
" if s:hiType(group) != 0
|
||||
" continue
|
||||
" endif
|
||||
" transBlendOpt is used to prevent hi from being clear
|
||||
execute('hi! ' . group . hiTerms)
|
||||
endfor
|
||||
|
||||
" highlight cursorline number only
|
||||
" this needs option set cursorlineopt=number
|
||||
if s:hiType('CursorLineNr') == 0
|
||||
hi! CursorLineNr guibg=NONE ctermbg=NONE cterm=bold gui=bold
|
||||
endif
|
||||
|
||||
for Func in s:themefixes
|
||||
call Func()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! theme#Init()
|
||||
if has('termguicolors')
|
||||
set termguicolors
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
set fillchars+=stl:\ ,stlnc:\ ,
|
||||
endif
|
||||
|
||||
let s:config = utils#merge(s:default_config, theme#loadConfig())
|
||||
|
||||
let bg = s:config.background
|
||||
if utils#hascolorscheme(s:config[bg].theme)
|
||||
call theme#setColor(bg)
|
||||
else
|
||||
call theme#setColor(bg, s:config[bg].default)
|
||||
endif
|
||||
|
||||
if s:config[bg].transparent
|
||||
call theme#enableTransparent()
|
||||
else
|
||||
call theme#disableTransparent()
|
||||
endif
|
||||
call s:generalThemeFix()
|
||||
|
||||
if exists('*options#add')
|
||||
let toggle_transparent = { 'desc' : 'Toggle transparent background' }
|
||||
func toggle_transparent.togglefunc(...)
|
||||
call theme#toggleTransparent()
|
||||
endfunc
|
||||
call options#add('toggle_transparent', toggle_transparent)
|
||||
endif
|
||||
|
||||
augroup GeneralTheme
|
||||
autocmd!
|
||||
autocmd ColorScheme * call s:generalThemeFix()
|
||||
autocmd ColorScheme * let s:config.background = &bg | call theme#setColor(&bg, expand('<amatch>'))
|
||||
autocmd VimLeave * call theme#saveConfig()
|
||||
augroup END
|
||||
|
||||
endfunction
|
||||
|
||||
function! theme#getConfig()
|
||||
return s:config
|
||||
function! theme#Init() abort
|
||||
let s:config = s:Load()
|
||||
let &background = get(s:config, 'background', 'dark')
|
||||
call theme#apply(s:config[&background].theme)
|
||||
augroup DotfilesTheme
|
||||
autocmd!
|
||||
autocmd ColorScheme * call theme#onColorScheme(expand('<amatch>'))
|
||||
autocmd VimLeavePre * call theme#save()
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
|
||||
" return a python version available (from 3 to 2)
|
||||
fun! utils#get_usable_py()
|
||||
let py = ''
|
||||
if executable('python3')
|
||||
let py = 'python3'
|
||||
elseif executable('python2')
|
||||
let py = 'python2'
|
||||
elseif executable('python')
|
||||
let py = 'python'
|
||||
endif
|
||||
return py
|
||||
endfun
|
||||
|
||||
" Check if plugin exists
|
||||
function! utils#hasplug(plug_name, ...)
|
||||
let plug_dir_name = get(a:, 1, a:plug_name) " optional argument for the name of plug's folder
|
||||
if has_key(g:plugs, a:plug_name) && isdirectory(g:plugin_dir . "/" . plug_dir_name)
|
||||
if has_key(g:plugs[a:plug_name], 'for') || has_key(g:plugs[a:plug_name], 'on')
|
||||
if (has_key(g:plugs[a:plug_name], 'for') && len(g:plugs[a:plug_name]['for']) == 0) ||
|
||||
\ (has_key(g:plugs[a:plug_name], 'on') && len(g:plugs[a:plug_name]['on']) == 0)
|
||||
return v:false
|
||||
endif
|
||||
endif
|
||||
return v:true
|
||||
endif
|
||||
return v:false
|
||||
endfunction
|
||||
|
||||
" This function is used to save a variable to a file
|
||||
function! utils#savevar(var, file)
|
||||
let serialized = string(a:var)
|
||||
call writefile([serialized], a:file)
|
||||
endfun
|
||||
|
||||
" This function is used to retrieve a variable from a file
|
||||
" only first line is count
|
||||
function! utils#readvar(file)
|
||||
if !filereadable(a:file)
|
||||
return v:null
|
||||
endif
|
||||
let serialized = readfile(a:file)
|
||||
if(len(serialized) == 0)
|
||||
return v:null
|
||||
endif
|
||||
execute "let result = " . serialized[0]
|
||||
return result
|
||||
endfun
|
||||
|
||||
" Merge two dictionaries, also recursively merging nested keys.
|
||||
" Use extend() if you don't need to merge nested keys.
|
||||
fun! utils#merge(defaults, override)
|
||||
let l:new = copy(a:defaults)
|
||||
for [l:k, l:v] in items(a:override)
|
||||
let l:new[l:k] = (type(l:v) is v:t_dict && type(get(l:new, l:k)) is v:t_dict)
|
||||
\ ? utils#merge(l:new[l:k], l:v)
|
||||
\ : l:v
|
||||
endfor
|
||||
return l:new
|
||||
endfun
|
||||
|
||||
"Remove all trailing whitespace by pressing <leader>ws
|
||||
fun! utils#trimwhitespace()
|
||||
let l:save = winsaveview()
|
||||
keeppatterns %s/\s*\r\=$//e
|
||||
call winrestview(l:save)
|
||||
endfun
|
||||
|
||||
function! utils#hascolorscheme(name)
|
||||
let scheme = a:name
|
||||
let colors = globpath(&runtimepath, printf('colors/%s.vim', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
let colors += globpath(&packpath, printf('pack/*/start/*/colors/%s.vim', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
let colors += globpath(&packpath, printf('pack/*/opt/*/colors/%s.vim', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
if has('nvim')
|
||||
let colors = globpath(&runtimepath, printf('colors/%s.lua', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
let colors += globpath(&packpath, printf('pack/*/start/*/colors/%s.lua', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
let colors += globpath(&packpath, printf('pack/*/opt/*/colors/%s.lua', scheme), 1, 1)
|
||||
if len(colors) > 0 | return 1 | endif
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" get current colorscheme name
|
||||
" return default if not found
|
||||
function! utils#colorschemename()
|
||||
return execute('colo')[1:]
|
||||
try
|
||||
return g:colors_name
|
||||
catch /^Vim:E121/
|
||||
return "default"
|
||||
catch /.*/
|
||||
return "default"
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" debug function print out highlight group of cursor position
|
||||
function! utils#showHiGroup(...)
|
||||
if !exists("*synstack")
|
||||
return
|
||||
endif
|
||||
let l = a:0 == 2 ? a:1 : line('.')
|
||||
let c = a:0 == 2 ? a:2 : col('.')
|
||||
echo map(synstack(l, c), 'synIDattr(v:val, "name")')
|
||||
|
||||
:echo "hi<" . synIDattr(synID(l,c,1),"name") . '> trans<'
|
||||
\ . synIDattr(synID(l,c,0),"name") . "> lo<"
|
||||
\ . synIDattr(synIDtrans(synID(l,c,1)),"name") . ">"
|
||||
|
||||
endfunc
|
||||
|
||||
" get highlight group information and return as dictionary
|
||||
function! utils#getHi(group)
|
||||
let output = execute('hi ' . a:group)
|
||||
let list = split(output, '\s\+')
|
||||
let dict = {}
|
||||
for item in list
|
||||
if match(item, '=') > 0
|
||||
let splited = split(item, '=')
|
||||
let dict[splited[0]] = splited[1]
|
||||
endif
|
||||
endfor
|
||||
return dict
|
||||
endfunction
|
||||
|
||||
function! utils#isTransparent()
|
||||
let dict = utils#getHi('Normal')
|
||||
let isGui = &termguicolors
|
||||
if isGui
|
||||
if !has_key(dict, 'guibg')
|
||||
return 1
|
||||
endif
|
||||
elseif !isGui
|
||||
if !has_key(dict, 'ctermfg')
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:scratch()
|
||||
split
|
||||
noswapfile hide enew
|
||||
setlocal buftype=nofile
|
||||
setlocal bufhidden=hide
|
||||
setlocal nobuflisted
|
||||
endfunction
|
||||
|
||||
" search highlight group with pattern
|
||||
function! utils#searchHi(pattern)
|
||||
execute("filter /" . a:pattern . "/ highlight")
|
||||
" color not working
|
||||
" let temp_reg = @"
|
||||
" redir @"
|
||||
" silent! execute("filter /" . a:pattern . "/ highlight")
|
||||
" redir END
|
||||
" let output = copy(@")
|
||||
" let @" = temp_reg
|
||||
" call s:scratch()
|
||||
" put! =output
|
||||
endfunc
|
||||
|
||||
function! utils#swapword()
|
||||
let word = expand("<cword>")
|
||||
let l1 = g:swap_dict[0]
|
||||
let l2 = g:swap_dict[1]
|
||||
let inx = index(l1, word)
|
||||
if inx != -1
|
||||
let newword = l2[inx]
|
||||
else
|
||||
let inx = index(l2, word)
|
||||
if inx != -1
|
||||
let newword = l1[inx]
|
||||
endif
|
||||
endif
|
||||
if inx != -1
|
||||
execute "normal ciw" . newword . "\<Esc>"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! utils#files(...)
|
||||
if a:0 > 0
|
||||
let path = a:1
|
||||
else
|
||||
let path = getcwd()
|
||||
endif
|
||||
let files = glob(path . '/**', 1, 1, 1)
|
||||
return files
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user