Closed tomtomjhj closed 3 years ago
Thank you very much. Sounds and looks sensible. BufEnter comes before BufWinEnter. Since we want to remove the erroneous w:lastfdm
as soon as possible, it looks more appropriate an autocmd event.
That makes sense. Fixed.
Suppose I'm editing buffer 1 on window 1 with
fdm=expr
,b:lastfdm='expr'
,w:lastfdm='expr'
. Then, I run:sp file
to create window 2 and buffer 2 whoseFileType
doessetl fdm=manual
. But when a window is created for a new buffer, the current buffer duringWinEnter
is buffer 2, not 1. Here is the snippet to demonstrate it:Result:
Because of this, the
WinEnter
autocmd setsw:lastfdm
of window 2 to'expr'
, which does not match the intendedfdm=manual
of the buffer 2. This makes the manual folds get removed whenUpdateWin()
is called, because it callsLeaveWin()
that setsfdm
tow:lastfdm
(='expr'
).To fix this issue, we should first classify
WinEnter
based on the events fired before/after it:WinNew
, not followed byBufWinEnter
(e.g.:sp
)WinNew
, beforeBufWinEnter
for the same buffer (e.g.:sp %
)WinNew
, beforeBufWinEnter
for a different buffer (e.g.:new
,:sp file
)WinLeave
(e.g.<C-w><C-w>
)We only need to fix 3's behavior. The solution is to check if the
bufnr()
atWinEnter
andBufWinEnter
are different, and if that's the case, undo the effect ofWinEnter
by removingw:lastfdm
.