stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.55k stars 135 forks source link

feature request(djlint): respect editorconfig/local buffer `tabstop` #457

Closed mangkoran closed 1 week ago

mangkoran commented 3 weeks ago

Did you check existing requests?

Describe the feature

djlint could format buffer with indent config based on editorconfig/local buffer tabstop

Provide background

I found that djlint supports indent config argument. It would be nice if this could be incorporated to conform config so that it could run djlint with config based on local buffer tabstop which is set based on editorconfig.

What is the significance of this feature?

nice to have

Additional details

I found a bit similar feature in markdown-toc config that could respect local buffer tabstop (although it's just check whether it's space or tab).

I would like to try to implement this feature so any guidance/suggestion is welcome.

Additionally, I think this feature could be implemented to all formatters that support indent config like this (however I have no idea what the formatters are).

mangkoran commented 3 weeks ago

I tried the following config (I use LazyVim) and it works.

  {
    "stevearc/conform.nvim",
    opts = {
      formatters_by_ft = {
        htmldjango = { "djlint" },
      },
      formatters = {
        djlint = {
          args = function(self, ctx)
            local indent = vim.bo[ctx.buf].tabstop or 4
            return { "-", "--reformat", "--indent", indent }
          end,
        },
      },
    },
  },
stevearc commented 2 weeks ago

This looks like it would make a reasonable pull request