Konfekt/FastFold

Reloading a file with expanded folds breaks them

haasn opened this issue · 10 comments

haasn commented

If I make changes to a file outside of vim and reload that file, FastFold only correctly updates if all my folds are closed. If I have any expanded, something breaks and all of my folds start and stop at completely wrong positions.

This work-around seems to alleviate the problem:

au BufReadPre * setlocal foldmethod=syntax

That way vim will reload the folds correctly, before FastFold gets a chance to “cache” the wrong values.

Do you have autoread set? Or do you manually reread the file in by :edit?

Ok, tentatively added your BufReadPre autocmd to handle this. Could you try?

Does BufRead work ? Why is it BufReadPre? Skimming through the autocmd triggers, there does not seem to be one expressly designed for reloading a buffer.

haasn commented

Do you have autoread set? Or do you manually reread the file in by :edit?

I have autoread set and update the files with :checktime. The way I am reproducing this is by running git commands from outside vim.

Does BufRead work ?

Yes. I only made it BufReadPre beacuse I didn't really look into it much, and just figured doing it this way would make sure it's set to ‘syntax’ during the moment vim actually loads the file (and then evaluates the folds), and before any of what fastfold was doing.

Skimming through the autocmd triggers, there does not seem to be one expressly designed for reloading a buffer.

I got the same impression from #vim.

Thanks for clearinf that up. So is it fixed?

haasn commented

In master I get

E201: *ReadPre autocommands must not change current buffer                                                                           E321: Could not reload "video.c"
E201: *ReadPre autocommands must not change current buffer
E321: Could not reload "video.h"
E201: *ReadPre autocommands must not change current buffer
E321: Could not reload "user_shaders.c"
E201: *ReadPre autocommands must not change current buffer
E321: Could not reload "utils.c"
E201: *ReadPre autocommands must not change current buffer
E321: Could not reload "command.c"
E201: *ReadPre autocommands must not change current buffer
E321: Could not reload "input.rst"

Hm. Please check again with BufRead. Cannot reproduce though when using :checktime after changinf outside of Vim. Also, FastFold does not change any buffer contents. If this doesn't fix it, please provide steps to reproduce with a minimal vimrc.

haasn commented

That seems to have fixed it.

Edit: Spoke too soon. Crash is gone but it still does not update folds properly. I'll try producing a minimal sample later, need sleep first.

Strange. What FastFold now does is recomputing folds after the buffer was read in again by the BufRead trigger. So if you hit zuz say to update them manually, are folds fine ?

But have some sleep first.

Refined the autocmd and it works here. With the exception of pandoc markdown files whose fold method switches from expr to syntax. But Otherwise it is fine.

Please make sure for FastFold tô function correctly, that the checktime autocmd is Nested.