Last active
August 27, 2019 05:01
-
-
Save qstrahl/43601b42630414c12d13efc37426631a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Quick Vimade-like fading plugin I hacked onto the end of my theme. | |
" Probably won't look any good in your terminal without some tweaks. | |
" It should gray-out all but the active buffer. Split and see. | |
" Actual effect probably depends entirely on your colorscheme. | |
" Might be nvim only, I dunno. If vim has NormalNC hlgroup, :+1: | |
" Detects diffs, too. Or at least it should. | |
" | |
" This method requires you to explicitly define each hlgroup. | |
" I'm sure a more reflective approach could be devised. I'll keep at it. | |
" You might have to clear some highlights too, I dunno. | |
hi! ActiveNormal cterm=italic ctermfg=8 ctermbg=none | |
hi! ActiveNormalNC cterm=italic ctermfg=8 ctermbg=none | |
hi! ActiveDiffAdd cterm=none ctermfg=2 ctermbg=none | |
hi! ActiveDiffChange cterm=none ctermfg=8 ctermbg=none | |
hi! ActiveDiffDelete cterm=none ctermfg=0 ctermbg=none | |
hi! ActiveDiffText cterm=none ctermfg=5 ctermbg=none | |
let s:masked_hls = ['NormalNC', 'DiffAdd', 'DiffChange', 'DiffDelete', 'DiffText'] | |
let s:active = [] | |
let s:inactive = [] | |
for s:hl in s:masked_hls | |
let s:active += [s:hl . ':Active' . s:hl] | |
let s:inactive += [s:hl . ':Inactive' . s:hl] | |
exe 'hi! clear' s:hl | |
exe 'hi! Inactive' . s:hl 'cterm=italic ctermfg=7 ctermbg=0' | |
endfor | |
" Normal is anything but. | |
hi! InactiveNormal cterm=none ctermfg=none ctermbg=none | |
let s:active += ['Normal:ActiveNormal'] | |
let s:inactive += ['Normal:InactiveNormal'] | |
let s:masks = s:active + s:inactive | |
function! s:mask_diffs () | |
let l:wins = gettabinfo(tabpagenr())[0].windows | |
let l:diff = getwinvar(winnr(), '&diff') | |
for l:win in l:wins | |
let l:winhl = getwinvar(l:win, '&winhl') | |
let l:winhls = split(l:winhl, ',') | |
call filter(l:winhls, {i, hl -> !count(s:masks, hl)}) | |
let l:diffing = l:diff && getwinvar(l:win, '&diff') | |
let l:winhls += l:diffing ? s:active : s:inactive | |
let l:winhl = join(l:winhls, ',') | |
call setwinvar(l:win, '&winhl', l:winhl) | |
endfor | |
endfunction | |
function! s:own_syntax (leaving) | |
let l:syncmd = 'ownsyntax' . ' 0'[a:leaving || &l:diff] | |
exe l:syncmd | |
if &l:diff | |
let l:rest = winrestcmd() | |
let l:view = winsaveview() | |
let l:home = winnr() | |
let l:wins = range(1, winnr('$')) | |
call filter(l:wins, {i, w -> getwinvar(w, '&diff')}) | |
for l:win in l:wins | |
noautocmd exe l:win 'wincmd w' | |
exe l:syncmd | |
endfor | |
noautocmd exe l:home 'wincmd w' | |
noautocmd exe l:rest | |
noautocmd call winrestview(l:view) | |
endif | |
endfunction | |
augroup MagiColor | |
autocmd! | |
autocmd! BufWinLeave,BufEnter * call s:mask_diffs() | |
autocmd! OptionSet diff call s:mask_diffs() | |
autocmd! BufWinEnter,WinEnter * call s:mask_diffs() | call s:own_syntax(0) | |
autocmd! WinLeave * call s:own_syntax(1) | |
augroup end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment