2024-04-16 11:27:49 +08:00
|
|
|
vim.api.nvim_create_user_command('Format', function(opts)
|
|
|
|
require('format').format(opts.bang, opts.args, opts.line1, opts.line2)
|
|
|
|
end, {
|
|
|
|
nargs = '*',
|
|
|
|
range = '%',
|
|
|
|
bang = true,
|
2024-04-16 13:54:12 +08:00
|
|
|
bar = true,
|
|
|
|
complete = function(_, line)
|
|
|
|
local ft = vim.o.filetype
|
|
|
|
local l = vim.split(line, '%s+')
|
|
|
|
local ok, default = pcall(require, 'format.ft.' .. ft)
|
|
|
|
if ok then
|
|
|
|
return vim.tbl_filter(function(val)
|
|
|
|
return vim.startswith(val, l[#l])
|
|
|
|
end, default.enabled())
|
|
|
|
else
|
|
|
|
end
|
|
|
|
end,
|
2024-04-16 11:27:49 +08:00
|
|
|
})
|
2024-12-20 08:22:44 +08:00
|
|
|
|