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

Initial basic Org markup support thanks to tree-sitter-org #1845

Merged
merged 6 commits into from
Mar 20, 2022
Merged

Initial basic Org markup support thanks to tree-sitter-org #1845

merged 6 commits into from
Mar 20, 2022

Conversation

zetashift
Copy link
Contributor

@zetashift zetashift commented Mar 19, 2022

Using (and many thanks to):
https://github.com/milisims/tree-sitter-org
https://github.com/nvim-orgmode/orgmode/tree/master/queries/org

And the-mikedavis from the matrix chat. I think I need to add a few more things like docs, but I would like to first know and what I can add and what I can improve?
Ideally I'd want the headers to be a different colors each(I think this is a theming thing though) and property drawers to be colored different as well. Not entirely sure how to go about it?

@the-mikedavis
Copy link
Member

This is looking good! For the docs, you'll need to run cargo xtask docgen and commit the changes. These queries will allow the headers to be highlighted differently but whether they'll be different colors is up to whichever theme you use. Here's a theme that has different colors set up.

@zetashift
Copy link
Contributor Author

Alright pretty happy with this, I kind of want to have different highlights for TODO and DONE etc, but a tree-sitter parser shouldn't be responsible for that.

Also wanted a different query for links, but I couldn't find the query for that.

image

An example org file: https://writequit.org/denver-emacs/presentations/files/example.org.html

@zetashift zetashift marked this pull request as ready for review March 20, 2022 14:47
@the-mikedavis
Copy link
Member

Giving this a try locally, I see that some markup is more difficult to highlight than I expected.

/foo bar baz/

won't match the

((expr) @markup.italic
 (#match? @markup.italic "/.*/"))

pattern because it gets parsed as three separate expr nodes. We could highlight a case like this with

(((expr) @markup.italic @_start
  (expr)* @markup.italic
  (expr) @markup.italic @_end)
 (#match? @_start "^/")
 (#match? @_end "/$"))

but I tried that locally and it degrades highlighting performance really bad. I think for now these queries are the best we can do. We could try out another parser, but milisims' seems like the best option of the available parsers. Ideally this parser should be refactored so it would parse markup into named nodes instead of leaving it to the queries. (I bet that this would be a pretty large refactor of the grammar though.)

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, just some nits about the formatting 👍

runtime/queries/org/highlights.scm Outdated Show resolved Hide resolved
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@the-mikedavis the-mikedavis changed the title Inital basic Org markup support thanks to tree-sitter-org Initial basic Org markup support thanks to tree-sitter-org Mar 20, 2022
@the-mikedavis the-mikedavis merged commit 7eb013c into helix-editor:master Mar 20, 2022
@edrex edrex mentioned this pull request May 17, 2023
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

Successfully merging this pull request may close these issues.

2 participants