marshallward / vim-restructuredtext

Syntax file for reStructuredText on Vim.
26 stars 12 forks source link

Folding support. #27

Closed anntzer closed 6 years ago

anntzer commented 6 years ago

the vimscript version!

The slightly horrible looking regex is just the alternation between the two regexes that define rstSection (with the groups renumbered as needed).

This requires vim>=7.3.627 (https://github.com/vim/vim/commit/07e31c571a13855cf67c69f3a676038510141699) so that :s/.../\=.../gn works; OTOH I believe this will just fail gracefully by not finding any folds for older versions.

Edit: Actually the use of function... closure means that this requires vim>=8; this could be rewritten to use function... dict (which is supported since much longer) but I can't say I really care enough about old vims :-)

marshallward commented 6 years ago

Just managed to test this out (sorry for taking so long), and it does appear to work to some degree, but the folded line title will occasionally get changed from the section name to a 0. Do you know what could be causing this?

marshallward commented 6 years ago

Also it doesn't seem to be handling subsections very well, is that right?

anntzer commented 6 years ago

Can you post a failing example?

marshallward commented 6 years ago

It's hard to reproduce, but it seems to happen whenever I edit the section name.

I could post an example, but it seems to happen everywhere for me.

If you can't reproduce it though then I'll see if it's something odd on my end.

anntzer commented 6 years ago

Did you fetch the latest version? I did force-push a few times, and some of the old versions were buggy, so you may have been trying an old version.

marshallward commented 6 years ago

AFAIK it's the same, but I only see one commit in the PR and it's from a week ago, am I looking in the wrong place?

anntzer commented 6 years ago

Ah, I see, funny stuff happens when editing. Will have a look...

Edit: in fact this was easy to fix -- I just needed to also make sure the fold cache is present before computing the fold texts...

Subsections should be handled just fine, the fold text is intentionally indented.

anntzer commented 6 years ago

Updated to support vim>=7.3.867 (which introduced the TextChanged event).

marshallward commented 6 years ago

Sorry I never noticed the edited comment and the updated version. I will give it a try right now.

marshallward commented 6 years ago

Whatever problems that I had seem to have gone away and appears to work well now.

Just to make sure, this only works on top-level sections, right? Subsections are folded into the sections?

anntzer commented 6 years ago

Subsections should be recursively folded under sections ("works for me...").

marshallward commented 6 years ago

Great, amazing job on this BTW :)

marshallward commented 6 years ago

Just letting you know that I am adding your contact details (based on git logs) to the autoload file. No idea how Bram feels about adding these to the repo, but we'll see how it goes.