nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.03k stars 134 forks source link

Aliasing code block's language name for better highlight (treesitter's language name may not the same with emac's counterpart) #451

Closed milanglacier closed 5 months ago

milanglacier commented 1 year ago

Does this feature exist in Emacs orgmode core?

Yes

Orgmode link

https://orgmode.org/manual/Editing-Source-Code.html

see org-src-lang-modes

However, note that org-src-lang-modes has no effect for org-babel, to successfully execute code block, the language name must exactly the same with what pre-defined by emacs -orgmode.

Feature value

No response

Additional context

AFAIK orgmode-nvim uses treesitter injection to highlight code block. However the problem is that the language name of the code block must be exactly the same with the treesitter counterpart (for example r in treesitter and R in emacs). However, many of the counterpart are not the same with the language name in emacs. In emacs you can configure org-src-lang-modes to alias language name for highlight.

But for org-babel, you cannot do that. A code block that can be successfully executed by Org-babel must have the same language name pre-defined by orgmode: https://orgmode.org/worg/org-contrib/babel/languages/index.html otherwise it will issue an error: "org-babel-execute-src-block: No org-babel-execute function for xxx!"

Thus I think it would be better if language code block can be aliased in nvim-orgmode.

gerritvreeman commented 1 year ago

Perhaps relevant: https://github.com/neovim/neovim/pull/18317

kristijanhusak commented 1 year ago

Perhaps relevant: neovim/neovim#18317

I think we will have to wait for this to be done before we proceed

gerritvreeman commented 1 year ago

It looks like this is actually possible with captures: reddit link

For org, adding this to my after/queries/org/injections.scm file aliases py to python:

(block
  parameter: (expr) @_lang
    (#match? @_lang "^[pP][yY]$")
  (contents) @python
)
milanglacier commented 5 months ago

nvim treesitter has implemented this feature for markdown:

https://github.com/nvim-treesitter/nvim-treesitter/pull/4659

perhaps the samething can be done for org?

kristijanhusak commented 5 months ago

Added the same values that were introduced in that PR d2fde796eec52d9ecc4ac045a6d1b3bff83cbfe7