polarmutex/tree-sitter-beancount

Add Markdown and Org mode headers to grammar

Closed this issue · 15 comments

I think it would be great if both markdown and org mode style headers where added to this grammar. Quite a bit of people in the ledger communities use headers to organize their ledgers.

I for one would love to be able to fold my ledger files by the headings as I usually organize my files like this

* 2021 Ledger
** Opening Transactions
** Events
** January
** February
...
** Cash

Using nvim-treesitter and this parser I found I could fold transaction entries but not from the header they were nested under.

just pushed to master some initial support for headers, let me know if there is any issues

awesome I'll take a look tomorrow. Super excited for this.

Just getting around to testing this because I forgot you implemented it :)
Does a change need to occur in nvim-treesitter to use this new folding? When I try to fold in nvim it complains it can't find folds at Org mode headers?

I believe so, we need to change the folds.scm file to add it the headers node name link

Okay I can help out with this. I'll test locally and create a PR with nvim-treesitter

tag this issue or me on the PR and I can give my approval since I am the maintainer on that repo

Change has been merged into nvim-treesitter. There must still be more to do. I am still getting No fold found when folding at headers. I tried also switching to markdown style headers over org mode headers and I get the same result.

I will take a look when I get a chance

Hi folks, I'm sure you're busy and this project and beancount-lsp are amazing. Just wanted to pop in to add that this feature is the one I miss most in switching from vim-beancount to LSP, and was hoping this was still on your radar. Folds by financial year (in my case) are so useful in big ledgers.

I think the issue is that headings are defined up until a newline and don’t contain the content beneath them. So if folding was working right now you would only be folding a single line. @polarmutex to support this properly we would need to change the grammar to make headings a parent node of the tree. At least from little I understand about treesitter.

will look into this when I find the time

I should point out that currently only org mode is supported. The logic might get dicey to support org and markdown. Want more time to play with it and add tests to make sure nothing funny happenes

Sorry for the delay in getting this out. I have a lot of beancount tools I want and so little time to make them.

Org sytle headers is just fine for me.

Forgot to drop in before and say that this is working great for me. I think this can be closed.