snaptoken / leg

Tools for making step-by-step code walkthroughs
MIT License
132 stars 2 forks source link

Collapsing non C-style code sections? #3

Open rnorth opened 7 years ago

rnorth commented 7 years ago

The automatic collapsing of unchanged curly brace-wrapped blocks is working well for Java and Groovy code.

I just wondered if it would be possible to add support for collapsing blocks that begin with a trailing :? In our case this would help with YAML-format config files and presumably with Python code as well.

Would you like me to have a go at a PR for this?

I notice https://github.com/yjerem/leg/blob/master/lib/snaptoken/diff.rb#L193 is where the start of section detection happens, based on a trailing brace. I imagine the start detection could be quite easily modified to also detect a trailing colon. Detecting the end of the section would be more challenging, I'd imagine!

What do you think?

paigeruten commented 7 years ago

That sounds good to me! You can go ahead with working on a PR.

You'll probably want to give it a different section type, like :colon instead of :braces. Since both YAML and Python use indentation to denote blocks, maybe the end of the section would be the next line that starts with a non-whitespace character? I don't know, it might not be that simple. Whatever works for your use case should be fine.