TaDaa / vimade

An eye friendly plugin that fades your inactive buffers and preserves your syntax highlighting!
MIT License
486 stars 8 forks source link

Add option to fade all inactive windows #17

Open hupfdule opened 5 years ago

hupfdule commented 5 years ago

At the moment windows containing the active buffer are all unfaded. Is there a reason why no option/command exists to fade inactive windows containing the active buffer?

It would be nice to have such an option.

TaDaa commented 5 years ago

Currently there is no option. I did try to add this feature when I was originally making the plugin, but bumped into performance issues (Vimade highlights for the current window would need to be recomputed on keystroke). Even though Vimade only computes highlights for text shown on the screen (plus a buffer area for scrolling), the vim syntax functions can still feel slow when called on keystroke.

However, it may be possible with a small a degree of error, if vimade works backwards and forwards from the current change until the syntax matches with the previous state. The downside would be that some highlights for these windows may be incorrect, but more than likely it would be acceptable. Same technique could be applied to achieve limelight fading that preserves syntax highlighting. I'll give it a go when I have some free time and post back.

Other alternative solutions: -Add an indicator for the inactive windows so that they can be distinguished. -Fade all of the text in inactive windows to gray without preserving syntax highlighting (not my first choice)

jeetsukumaran commented 4 years ago

+1. To me, the purpose of this is to be able to instantly (or with low background mental processing) see the viewport I am working on. I often have multiple viewports on the same buffer. Being able to identify the active viewpoint is more important than being able to identify the active buffer.

I would love to see this implemented even if it comes at a cost of no syntax highlighting in the faded buffers. Perhaps as an option until some other approach is developed?

TaDaa commented 4 years ago

half working neovim solution below for this, I don't use it myself so there might be a couple issues with it... I would like to work on actually supporting this at some point but I'd really like to support the feature through matchaddpos as it allows covering text objects generated by other plugins).

Adding the feature itself will require a good amount of performance considerations, but I do think its possible still on higher end machines, just need to find the time. I do like your idea of scrapping syntax highlighting esp for a short term / first step solution

let g:vimade.enablebasegroups=0

augroup SemiDimPerWin
au!
au WinLeave * call OnWinLeave()
au WinEnter * call OnWinEnter()
au BufLeave * call OnBufLeave()
au BufEnter * call OnBufEnter()
augroup END

function! OnBufEnter ()
    let b:buf_left=0
endfunction
function! OnBufLeave ()
    let b:buf_left=1
    call OnWinEnter()
endfunction
function! OnWinEnter ()
    if exists('b:old_syntax')
        execute 'set syntax='.b:old_syntax
        setlocal winhighlight=
    elseif &syntax
        let w:old_syntax=&syntax
    endif
endfunction
function! OnWinLeave ()
    if exists('b:buf_left') && b:buf_left == 1
        return
    endif
    let b:old_syntax=&syntax
    ownsyntax
    set syntax=
    setlocal winhighlight=Normal:vimade_0
endfunction

Can also do this with syntax highlighting using code below, but performance may be an issue -- probably some side effects as well like signs dimming when they shouldn't -- honestly though it seems to perform better than I had expected

augroup SemiDimPerWin
au!
au WinLeave * call OnWinLeave()
au WinEnter * call OnWinEnter()
au! TextChangedI,TextChanged * call UpdateBufferAsync()
augroup END

function! OnWinEnter ()
    VimadeFadeActive
    VimadeWinDisable
endfunction
function! OnWinLeave ()
    VimadeWinEnable
endfunction

function! UpdateBufferAsync ()
    if exists('g:update_vimade')
        return
    endif
    let g:update_vimade = timer_start(1, 'DoUpdateBuffer') "change the timer value from 1 to whatever to help with performance
endfunction

function! DoUpdateBuffer (w)
    unlet g:update_vimade
    call vimade#BufDisable()
    call vimade#BufEnable()
endfunction
jeetsukumaran commented 4 years ago

THANKS!

Both of these work fine! The syntax highlighting does not seem to have a noticeable performance annoyance for me, even on a full-screen 4K window. Love it! Really appreciate you work.