filetype configs with named files. has telescope
added keymap functionality
1 file changed, +17 -0
+17-0lua/ftconfig/init.lua
| @@ -12,9 +12,16 @@ local augroup = vim.api.nvim_create_augroup("ftconfig", { clear = true }) | ||
| 12 | 12 | ---@field use string[] |
| 13 | 13 | ---@field formatters? table<string, conform.FileFormatterConfig> |
| 14 | 14 | |
| 15 | +---@class FTKeymapOptions | |
| 16 | +---@field [1] string # mode | |
| 17 | +---@field [2] string # lhs | |
| 18 | +---@field [3] string|fun(args:vim.api.keyset.create_autocmd.callback_args) # rhs | |
| 19 | +---@field [4]? vim.keymap.set.Opts | |
| 20 | + | |
| 15 | 21 | ---@class FTSpec |
| 16 | 22 | ---@field indent? integer |
| 17 | 23 | ---@field conform? FTConformSpec |
| 24 | +---@field keymaps? FTKeymapOptions[] | |
| 18 | 25 | ---@field lsp? table<LSPName, any> |
| 19 | 26 | |
| 20 | 27 | ---Loads the config for the given filename |
| @@ -39,6 +46,16 @@ function M.load_file(filename) | ||
| 39 | 46 | vim.opt_local.softtabstop = indent |
| 40 | 47 | end, |
| 41 | 48 | }) |
| 49 | + for _, k in ipairs(spec.keymaps or {}) do | |
| 50 | + vim.api.nvim_create_autocmd("FileType", { | |
| 51 | + pattern = ft, | |
| 52 | + callback = function(args) | |
| 53 | + local opts = k[4] or {} | |
| 54 | + opts.buffer = args.buf | |
| 55 | + vim.keymap.set(k[1], k[2], k[3], opts) | |
| 56 | + end, | |
| 57 | + }) | |
| 58 | + end | |
| 42 | 59 | if spec.conform then |
| 43 | 60 | local conform_opts = |
| 44 | 61 | { formatters_by_ft = { [ft] = spec.conform.use }, formatters = spec.conform.formatters } |