diff --git a/bundle/format.nvim/lua/format.lua b/bundle/format.nvim/lua/format.lua index f4c5b61ea..799fa6be4 100644 --- a/bundle/format.nvim/lua/format.lua +++ b/bundle/format.nvim/lua/format.lua @@ -3,6 +3,8 @@ local M = {} local util = require('format.util') local task = require('format.task') +local custom_formatters = {} + function M.format(bang, user_input, start_line, end_line) if not vim.o.modifiable then return util.msg('buffer is not modifiable!') @@ -13,11 +15,16 @@ function M.format(bang, user_input, start_line, end_line) if filetype == '' then return util.msg('format: skip empty filetype') end + local ok, formatter + if custom_formatters[filetype] then + formatter = custom_formatters[filetype] + end - local ok, default_formatter = pcall(require, 'format.ft.' .. filetype) - - if not ok then - return util.msg('no formatter for ' .. filetype) + if not formatter then + ok, formatter = pcall(require, 'format.ft.' .. filetype) + if not ok then + return util.msg('no formatter for ' .. filetype) + end end task.run({ @@ -25,10 +32,15 @@ function M.format(bang, user_input, start_line, end_line) stdin = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line - 1, false), start_line = start_line - 1, end_line = end_line - 1, - formatter = default_formatter + formatter = formatter, }) end -function M.setup(opts) end - +function M.setup(opt) + if opt.custom_formatters and type(opt.custom_formatters) == 'table' then + for k, v in pairs(opt.custom_formatters) do + custom_formatters[k] = v + end + end +end return M