local puk = require 'std.puk' local dbg = require 'std.dbg' local map = require 'std.map' local user_command = require 'std.user_command' local format = function() require 'conform'.format({ async = false, lsp_fallback = true }, function(err) if err and dbg.get() then vim.print('Format failed', err) end end) end map.N { description = 'Format buffer', category = 'format', keys = '=', command = format, } user_command.Format 'Format the current buffer' (format) vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" puk.defer 'conform' (function(conform) conform.setup { formatters_by_ft = { toml = { 'taplo' }, sh = { 'shfmt' }, just = { 'just' }, zig = { 'zigfmt' }, markdown = { 'mdslw' }, -- Use the “*” file type to run formatters on all file types. ['*'] = { 'injected', 'typos' }, -- Use the “_” file type to run formatters on file types that don't -- have other formatters configured. ['_'] = { 'trim_whitespace', 'trim_newlines' }, }, formatters = { mdslw = { prepend_args = { '--stdin-filepath', '$FILENAME' }, }, }, log_level = dbg.get() and vim.log.levels.TRACE or vim.log.levels.INFO, } end)