Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions plugin/fastfold.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =~# '\<jump\>'
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 =~# '\<jump\>'
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()
Expand Down