orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

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

Open milanglacier opened this issue 2 years ago • 3 comments

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.

milanglacier avatar Nov 22 '22 23:11 milanglacier

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

gerritvreeman avatar Nov 22 '22 23:11 gerritvreeman

Perhaps relevant: neovim/neovim#18317

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

kristijanhusak avatar Nov 26 '22 07:11 kristijanhusak

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
)

gerritvreeman avatar Dec 20 '22 21:12 gerritvreeman

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?

milanglacier avatar May 14 '24 01:05 milanglacier

Added the same values that were introduced in that PR d2fde796eec52d9ecc4ac045a6d1b3bff83cbfe7

kristijanhusak avatar May 19 '24 08:05 kristijanhusak