Skip to content

Commit ab44891

Browse files
committed
fix: use win_execute()
* The current implementation of `s:WinDo()` fails at avoiding some side effects. Specifically, `:windo` and `:wincmd w` trigger `CursorMoved` even if `noautocmd` is used (both in Vim and Nvim ≥ 0.10). So use `win_execute()` if it's available. * With `win_execute()`, setting fdm itself doesn't seem to trigger recomputation of fold. Querying the foldlevel seems to be sufficient for triggerring fold recomputation.
1 parent ab3d199 commit ab44891

1 file changed

Lines changed: 36 additions & 27 deletions

File tree

plugin/fastfold.vim

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,42 @@ function! s:LeaveWin()
6868
endif
6969
endfunction
7070

71-
" Like windo but restore the current buffer.
72-
" See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position
73-
function! s:WinDo( command )
74-
" avoid errors in CmdWin
75-
if exists('*getcmdwintype') && !empty(getcmdwintype())
76-
return
77-
endif
78-
" Work around Vim bug.
79-
" See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg
80-
let curaltwin = winnr('#') ? winnr('#') : 1
81-
let currwin=winnr()
82-
if &scrollopt =~# '\<jump\>'
83-
set scrollopt-=jump
84-
let l:restore = 'set scrollopt+=jump'
85-
endif
86-
" Work around Vim bug.
87-
" See https://github.com/vim/vim/issues/4622#issuecomment-508985573
88-
let l:currwinwidth = &winwidth
89-
let &winwidth = &winminwidth > 0 ? &winminwidth : 1
90-
silent! execute 'keepjumps noautocmd windo ' . a:command
91-
silent! execute 'noautocmd ' . curaltwin . 'wincmd w'
92-
silent! execute 'noautocmd ' . currwin . 'wincmd w'
93-
if exists('l:restore')
94-
exe l:restore
95-
endif
96-
let &winwidth = l:currwinwidth
97-
endfunction
71+
" Like :windo, but restores the current window and avoids side effects.
72+
if exists('*win_execute')
73+
function! s:WinDo( command )
74+
for w in range(1, winnr('$'))
75+
" query foldlevel to trigger recomputation of folds
76+
call win_execute(win_getid(w), a:command . ' | if !s:Skip() | call foldlevel(1) | endif', 'silent!')
77+
endfor
78+
endfunction
79+
else
80+
" See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position
81+
function! s:WinDo( command )
82+
" avoid errors in CmdWin
83+
if exists('*getcmdwintype') && !empty(getcmdwintype())
84+
return
85+
endif
86+
" Work around Vim bug.
87+
" See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg
88+
let curaltwin = winnr('#') ? winnr('#') : 1
89+
let currwin=winnr()
90+
if &scrollopt =~# '\<jump\>'
91+
set scrollopt-=jump
92+
let l:restore = 'set scrollopt+=jump'
93+
endif
94+
" Work around Vim bug.
95+
" See https://github.com/vim/vim/issues/4622#issuecomment-508985573
96+
let l:currwinwidth = &winwidth
97+
let &winwidth = &winminwidth > 0 ? &winminwidth : 1
98+
silent! execute 'keepjumps noautocmd windo ' . a:command
99+
silent! execute 'noautocmd ' . curaltwin . 'wincmd w'
100+
silent! execute 'noautocmd ' . currwin . 'wincmd w'
101+
if exists('l:restore')
102+
exe l:restore
103+
endif
104+
let &winwidth = l:currwinwidth
105+
endfunction
106+
endif
98107

99108
" WinEnter then TabEnter then BufEnter then BufWinEnter
100109
function! s:UpdateWin()

0 commit comments

Comments
 (0)