fix(indents): delegate indents for code blocks to treesitter instead of vim#1120
fix(indents): delegate indents for code blocks to treesitter instead of vim#1120dtvillafana wants to merge 1 commit intonvim-orgmode:masterfrom
Conversation
|
If you use nvim-treesitter indentexpr for a filetype that is being used in the code block, it should pull that up automatically. |
|
Ah, so this is really an error on my end... |
|
If your |
|
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: |
|
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 |
|
Currently, it's all from treesitter (unless overriden by LSP for some filetypes). in my init.lua it's set this way: -- Enable features via autocommands for modern nvim-treesitter
vim.api.nvim_create_autocmd("FileType", {
group = augroup,
pattern = "*",
callback = function()
pcall(vim.treesitter.start)
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
which is then later overrode by this as shown previously: vim.api.nvim_create_autocmd("FileType", {
pattern = "org",
group = vim.api.nvim_create_augroup("org_indent_fix", { clear = true }),
callback = function()
-- OrgIndent handles visual indentation; for = formatting, use orgmode's indent
local ok, orgmode = pcall(require, "orgmode")
if ok then
vim.bo.indentexpr = "v:lua.require('orgmode.org.indent').indentexpr()"
end
end,
})But for whatever reason, the indentation for code blocks in org files still does not pick up an injected indentexpr (without the patch I've made), I am not smart enough to figure out why. I'm beginning to think this may be a lazy-loading issue, or an ordering issue, but again I'm not sure. 🤷♂️ |
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:
Conventional Commits
specification (e.g.,
feat: add new feature,fix: correct bug,docs: update documentation).make test.