FastFold icon indicating copy to clipboard operation
FastFold copied to clipboard

Reloading a file with expanded folds breaks them

Open haasn opened this issue 9 years ago • 10 comments

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.

haasn avatar Jun 11 '16 06:06 haasn

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.

Konfekt avatar Jun 11 '16 09:06 Konfekt

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.

haasn avatar Jun 11 '16 09:06 haasn

Thanks for clearinf that up. So is it fixed?

Konfekt avatar Jun 11 '16 10:06 Konfekt

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"

haasn avatar Jun 11 '16 10:06 haasn

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.

Konfekt avatar Jun 11 '16 11:06 Konfekt

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.

haasn avatar Jun 11 '16 11:06 haasn

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 ?

Konfekt avatar Jun 11 '16 14:06 Konfekt

But have some sleep first.

Konfekt avatar Jun 11 '16 14:06 Konfekt

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.

Konfekt avatar Jun 13 '16 12:06 Konfekt

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

Konfekt avatar Jun 13 '16 13:06 Konfekt