Closed timsofteng closed 3 years ago
Please write step by step procedure to reproduce the situation.
fern
.:w
.I could not reproduce. Please make a minimal vimrc to reproduce.
Hi this bug happen to me i use
" first i open fern
:Fern . -drawer -reveal=% -toggle<CR>
" then rename with
nmap <buffer> cw <Plug>(fern-action-rename:split)
" after i press :w<cr> it will override the content to my current file open.
" I think it should override to my fern drawner buffer.
" sometime it work perfect but sometime this bug happen to me.
https://user-images.githubusercontent.com/7578110/116677018-e595f080-a9d1-11eb-9366-a1aa2394309d.mp4
Please make a minimal vimrc and minimal descriptive steps to reproduce. https://github.com/lambdalisue/fern.vim/wiki/Minimal-vimrc#with-native-vimneovim
https://gist.github.com/windwp/be22ae313538e1d6743de0d21dfaadeb
hi it is my vimrc.min
the first time
I press <c-b>
rename with cw
and save <c-s>
.
It work correct . I close fern with <c-b>
and reopen fern again with<c-b>
on second time it override my buffer.
https://user-images.githubusercontent.com/7578110/116766278-d9527780-aa53-11eb-92c4-7bb30db0d7cf.mp4
Thank.
I'm sorry but I don't think it's minimal. Please make it minimal.
https://gist.github.com/windwp/be22ae313538e1d6743de0d21dfaadeb I update it It still happen on the second time rename.
Thanks. It seems minimal enough 👍 I'll try it on my environment within few days but let me know your environment in case (OS, Vim or Neovim? and which version or etc.)
Thanks. I could reproduce the issue. I'll investigate it.
It seems foldmethod=expr
is the reason. It happens on Vim (8.2.2681) and Neovim (0.5.0-dev)
vimrc
if exists('+compatible') && &compatible
set nocompatible
endif
" Disable Vim's native pack feature
set packpath=
" Clone https://github.com/lambdalisue/fern.vim in somewhere
" and specify that directory to the below
"
set runtimepath^=~/ghq/github.com/lambdalisue/fern.vim
filetype plugin indent on
syntax on
"----------------------------------------------------------------
" Add extra settings here to reproduce the issue...
set foldmethod=expr
"----------------------------------------------------------------
echomsg "Custom minimal vimrc has loaded"
procedure
nvim -u ~/.vim/vimrc.min
:Fern . -drawer
:q
:Fern . -drawer
README.md
then hit R
Hello.md
then :w
https://user-images.githubusercontent.com/546312/116803675-c1165180-ab54-11eb-98d6-147c1788b565.mp4
*'foldexpr'* *'fde'*
'foldexpr' 'fde' string (default: "0")
local to window
The expression used for when 'foldmethod' is "expr". It is evaluated
for each line to obtain its fold level. See |fold-expr|.
The expression will be evaluated in the |sandbox| if set from a
modeline, see |sandbox-option|.
This option can't be set from a |modeline| when the 'diff' option is
on or the 'modelineexpr' option is off.
It is not allowed to change text or jump to another window while
evaluating 'foldexpr' |textlock|.
So fern might update buffer while foldexpr is running?
yeah i think it is a problem i set it because nvim-treesitter use it to fold.
I'm not sure but it seems find_win_for_curbuf()
does NOT change the curwin
on our case while
nvim_buf_set_lines
on https://github.com/lambdalisue/fern.vim/blob/master/autoload/fern/internal/buffer.vim#L8 fix issue on NeovimI'm trying to create a minimal reproducing procedure to report this as a bug on Vim/Neovim but it's quite difficult....
bufhidden=wipe
on fern buffer solve this issue somehow. Of course., it cannot be a solution for this issue while bufhidden=wipe
has a lot of side effects.
I use setlocal foldmethod=manual to fern and fern-replacer and it work. Thank.
OK. I've worked on this for more than 4 hours but I couldn't find a way to reproduce the same issue without fern.vim to report it on Vim/Neovim... So I gave up on the solution that @windwp showed.
What I've founds are
foldmethod=expr
is required to reproducesetbufline()
must be closed (hide, unload, delete but wipe)setbufline()
must be called from BufWriteCmd
But it seems above conditions are not enough...
I tried with something like...
if exists('+compatible') && &compatible
set nocompatible
endif
" Disable Vim's native pack feature
set packpath=
filetype plugin indent on
syntax on
"----------------------------------------------------------------
" Add extra settings here to reproduce the issue...
set foldmethod=expr
function! Test() abort
edit A
vsplit | edit B
setlocal buftype=nofile bufhidden=hide
close
vsplit | edit B
wincmd p
split | edit C
setlocal buftype=acwrite bufhidden=wipe
autocmd BufWriteCmd <buffer> call s:BufWriteCmd()
endfunction
function! s:BufWriteCmd() abort
call timer_start(0, { -> setbufline('B', 1, ['Hello']) })
endfunction
call Test()
"----------------------------------------------------------------
echomsg "Custom minimal vimrc has loaded"
If Hello
appears on buffer A or C, that mean the script reproduce the issue.
Fixed by #334. Thanks for detailed report and solution @windwp
Hey. When I rename file and try to open it than fern open just empty buffer. But if I try to open it second time it opens. Look at the screencast please.
https://user-images.githubusercontent.com/51912173/115755929-8c610800-a3a6-11eb-966e-2daffc025c81.mp4