Skip to content

fix(indents): delegate indents for code blocks to treesitter instead of vim#1120

Open
dtvillafana wants to merge 1 commit intonvim-orgmode:masterfrom
dtvillafana:indents
Open

fix(indents): delegate indents for code blocks to treesitter instead of vim#1120
dtvillafana wants to merge 1 commit intonvim-orgmode:masterfrom
dtvillafana:indents

Conversation

@dtvillafana
Copy link

@dtvillafana dtvillafana commented Mar 20, 2026

Summary

delegate indents for code blocks to treesitter instead of vim.
This fixes the issue where code blocks are incorrectly formatted for languages that vim does not have indents set up for.

The issue I was having was that the code blocks were not getting formatted according to the injections.scm that is already in the repo.

Related Issues

Related #

Closes #

Changes

delegate indents for code blocks to treesitter instead of vim

Checklist

I confirm that I have:

  • Followed the
    Conventional Commits
    specification
    (e.g., feat: add new feature, fix: correct bug,
    docs: update documentation).
  • My PR title also follows the conventional commits specification.
  • Updated relevant documentation, if necessary.
  • Thoroughly tested my changes.
  • Added tests (if applicable) and verified existing tests pass with
    make test.
  • Checked for breaking changes and documented them, if any.

@dtvillafana dtvillafana marked this pull request as ready for review March 20, 2026 05:37
@kristijanhusak
Copy link
Member

If you use nvim-treesitter indentexpr for a filetype that is being used in the code block, it should pull that up automatically.

@dtvillafana
Copy link
Author

dtvillafana commented Mar 20, 2026

Ah, so this is really an error on my end...
Even so, should it explicitly delegate it?
If it does, it would improve the "out of the box" experience for those who haven't fully configured their indent expressions.

@kristijanhusak
Copy link
Member

If your indentexpr is correctly set, then yeah. First line in the if statement picks up the indentexpr.
How are you setting your indentexpr?

@dtvillafana
Copy link
Author

in my config (generated by nixvim):

vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"

then later on:

vim.api.nvim_create_autocmd('FileType', {
   pattern = 'org',
   group = vim.api.nvim_create_augroup('org_indent_fix', { clear = true }),
   callback = function()
     local ok, orgmode = pcall(require, 'orgmode')
     if ok then
         vim.bo.indentexpr = "v:lua.require('orgmode.org.indent').indentexpr()"
     end
   end,
})

maybe whatever version of treesitter/org grammar I was using was bad...

relevant files in my config if you wanted to look:

@kristijanhusak
Copy link
Member

You shouldn't need to do this for org, it should automatically happen from here.

What I meant is how do you set indentexpr in your other filetypes, like the ones that you use in your code blocks. For example, if you use lua in your code blocks, how do you set indentexpr for lua?

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