Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement region markers for code folding #5

Closed
gilbertginsberg opened this issue Dec 23, 2017 · 5 comments
Closed

Implement region markers for code folding #5

gilbertginsberg opened this issue Dec 23, 2017 · 5 comments

Comments

@gilbertginsberg
Copy link

gilbertginsberg commented Dec 23, 2017

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

@Lencerf
Copy link
Owner

Lencerf commented Dec 25, 2017

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.

@gilbertginsberg
Copy link
Author

gilbertginsberg commented Dec 25, 2017

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.

@floriskruisselbrink
Copy link

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?

@gilbertginsberg
Copy link
Author

gilbertginsberg commented Jan 2, 2018

@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.

zahanm pushed a commit to zahanm/vscode-beancount that referenced this issue Jan 5, 2019
beancount does fine with indented `pushtag` and `option` directives, but
this extensions syntax didn't recognize it

why indent? for folding, as outlined in Lencerf#5
I prefer indenting over the `;#region` syntax since it's more editor
independant

test plan:
I used it locally with my own file and syntax highlighting looked fine
with the indentation
@akshaysalunke13
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants