diff --git a/plugin/fastfold.vim b/plugin/fastfold.vim index d0d5d6b..b08356b 100644 --- a/plugin/fastfold.vim +++ b/plugin/fastfold.vim @@ -68,33 +68,42 @@ function! s:LeaveWin() endif endfunction -" Like windo but restore the current buffer. -" See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position -function! s:WinDo( command ) - " avoid errors in CmdWin - if exists('*getcmdwintype') && !empty(getcmdwintype()) - return - endif - " Work around Vim bug. - " See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg - let curaltwin = winnr('#') ? winnr('#') : 1 - let currwin=winnr() - if &scrollopt =~# '\' - set scrollopt-=jump - let l:restore = 'set scrollopt+=jump' - endif - " Work around Vim bug. - " See https://github.com/vim/vim/issues/4622#issuecomment-508985573 - let l:currwinwidth = &winwidth - let &winwidth = &winminwidth > 0 ? &winminwidth : 1 - silent! execute 'keepjumps noautocmd windo ' . a:command - silent! execute 'noautocmd ' . curaltwin . 'wincmd w' - silent! execute 'noautocmd ' . currwin . 'wincmd w' - if exists('l:restore') - exe l:restore - endif - let &winwidth = l:currwinwidth -endfunction +" Like :windo, but restores the current window and avoids side effects. +if exists('*win_execute') + function! s:WinDo( command ) + for w in range(1, winnr('$')) + " query foldlevel to trigger recomputation of folds + call win_execute(win_getid(w), a:command . ' | if !s:Skip() | call foldlevel(1) | endif', 'silent!') + endfor + endfunction +else + " See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position + function! s:WinDo( command ) + " avoid errors in CmdWin + if exists('*getcmdwintype') && !empty(getcmdwintype()) + return + endif + " Work around Vim bug. + " See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg + let curaltwin = winnr('#') ? winnr('#') : 1 + let currwin=winnr() + if &scrollopt =~# '\' + set scrollopt-=jump + let l:restore = 'set scrollopt+=jump' + endif + " Work around Vim bug. + " See https://github.com/vim/vim/issues/4622#issuecomment-508985573 + let l:currwinwidth = &winwidth + let &winwidth = &winminwidth > 0 ? &winminwidth : 1 + silent! execute 'keepjumps noautocmd windo ' . a:command + silent! execute 'noautocmd ' . curaltwin . 'wincmd w' + silent! execute 'noautocmd ' . currwin . 'wincmd w' + if exists('l:restore') + exe l:restore + endif + let &winwidth = l:currwinwidth + endfunction +endif " WinEnter then TabEnter then BufEnter then BufWinEnter function! s:UpdateWin()