Skip to content

Comments

fix(indent): improve indentation#1766

Open
austinliuigi wants to merge 3 commits intonvim-neorg:mainfrom
austinliuigi:fix/indent
Open

fix(indent): improve indentation#1766
austinliuigi wants to merge 3 commits intonvim-neorg:mainfrom
austinliuigi:fix/indent

Conversation

@austinliuigi
Copy link
Contributor

This PR fixes some issues with the indentexpr provided by the indent module, primarily with how it handles code blocks. To be honest, I made these changes a while ago and left it alone after getting it to work how I liked because I was busy with other things. So I forgot the exact behavior of the issues I was fixing... But a rough recollection is

  • treesitter indentation didn't work well for me (it would dedent too much I think?)
  • manual indentation in non-treesitter language code blocks would automatically be removed

Sorry for the little amount of detail. I'm pushing this in case it helps anyone who is frustrated with the behavior of the current indentation. If interested, please try it out :)

@ALVAROPING1
Copy link
Contributor

ALVAROPING1 commented Feb 18, 2026

changing vim.fn["nvim_treesitter#indent"]() to require("nvim-treesitter").indentexpr() breaks support with nvim-treesitter's master branch (only main has .indentexpr()). Is there a reason to change it?

This patch also breaks automatic dedent of the @code ... @end tags

@austinliuigi
Copy link
Contributor Author

changing vim.fn["nvim_treesitter#indent"]() to require("nvim-treesitter").indentexpr() breaks support with nvim-treesitter's master branch (only main has .indentexpr()). Is there a reason to change it?

Okay, my apologies. I forgot exactly why I changed it and it must have been because it wasn't working for me due to using the main branch of nvim-treesitter. I'm not sure how you guys want to handle transitioning from compatibility with the master to compatibility with the main branch of nvim-treesitter, so let me know.

This patch also breaks automatic dedent of the @code ... @end tags

I don't experience this. For example,

@code c
    int main() {
        int i = 10;
        double d = 10.0;
    }
@end

properly dedents to the following after using = on the code block:

@code c
int main() {
    int i = 10;
    double d = 10.0;
}
@end

Did I understand your concern correctly?

@austinliuigi
Copy link
Contributor Author

Sorry, I misunderstood what you meant by the dedenting. Let me update it to dedent the tags properly.

@ALVAROPING1
Copy link
Contributor

changing vim.fn["nvim_treesitter#indent"]() to require("nvim-treesitter").indentexpr() breaks support with nvim-treesitter's master branch (only main has .indentexpr()). Is there a reason to change it?

Okay, my apologies. I forgot exactly why I changed it and it must have been because it wasn't working for me due to using the main branch of nvim-treesitter. I'm not sure how you guys want to handle transitioning from compatibility with the master to compatibility with the main branch of nvim-treesitter, so let me know.

assuming vim.fn["nvim_treesitter#indent"]() doesn't exist on the main branch (i haven't checked), you could do vim.fn["nvim_treesitter#indent"] and vim.fn["nvim_treesitter#indent"]() or require("nvim-treesitter").indentexpr(), that should call the implementation that's detected to exist

@austinliuigi
Copy link
Contributor Author

Let me know if that works for you. I did require("nvim-treesitter").indentexpr and require("nvim-treesitter").indentexpr() or vim.fn["nvim_treesitter#indent"]() because vim.fn["nvim_treesitter#indent"] is a function in lua even though it doesn't exist in vim.

For instance, :lua print(vim.fn.foo) prints a function address, but :lua vim.fn.foo() raises an unknown error function. Just thought that was interesting.

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