Lencerf/vscode-beancount

Implement region markers for code folding

gilbertginsberg opened this issue · 5 comments

Would it be possible to implement region markers for code folding (and thus better beancount doc organization) in VS Code?

For instance: https://code.visualstudio.com/updates/v1_17#_editor

I do not quiet understand what is your need. The syntax of beancount is simple and I do not know where we will need to fold codes. Can you provide an example of codes needed to be folded? Also what do the codes look like after they are folded? Thank you.

What I had in mind was the following, but specifically for the beancount language:

screen shot 2017-12-25 at 11 05 13 am

To allow you to structure your beancount file a la "org-mode." One example where code folding might be of use is if you break down transactions, say, by Country. And you want to keep them separate, in their own country list. After folding, it might look something like this:

screen shot 2017-12-25 at 11 15 24 am

All that said, I actually found a way to use VSCode's built-in folding functionality to make this work.

Thanks for hearing me out, and thanks for the extension.

Sorry to comment on a closed issue, but I'm really curious how you got it to work with VSCode's built-in folding without a change to the beancount plugin?

@vloris: VS Code uses indentation to define folding regions. VS Code explains it as such:

"Folding regions are evaluated based on the indentation of lines. A folding region starts when a line has a smaller indent than one or more following lines, and ends when there is a line with the same or smaller indent." More here: https://code.visualstudio.com/docs/editor/codebasics#_folding

So, say you have something like this:

1: No folding
screen shot 2018-01-02 at 12 05 17 pm

If you move your mouse over the gutter on the left and click the square with the dash in the center, that'll fold the conent below (when things are folded a + will appear). If you click the top one (the one next to "Some header), everything below will be folded:

2: Top-level Folding
screen shot 2018-01-02 at 12 05 44 pm

Or if you click the second one, only what's below will be folded:

3: Nested folding
screen shot 2018-01-02 at 12 05 52 pm

Which means, you can use this to your benefit whilst still abiding by beancount's syntax constraints (and so your beancount file passes bean-check).

If you're aiming for more nested regions, you could do something like this which is a bit hacky but effective nonetheless:

screen shot 2018-01-02 at 12 10 54 pm

You can comment out the — US which beancount doesn't recognize, while at the same time taking advantage of VS Code's built-in folding.

I'm sure there might be better ways to handle this, but for now, this kind of code folding is sufficient for my purposes. Cheers.

I'm unable to achieve folding like this in my accounts file.
image