irongit

filetype configs with named files. has telescope

added keymap functionality

huncholanehuncholaneauthored
parent b6e5808commit 447a5dff010c6928b6aa6fdb5f7b570ba1824434Browse files

1 file changed, +17 -0

+17-0lua/ftconfig/init.lua
@@ -12,9 +12,16 @@ local augroup = vim.api.nvim_create_augroup("ftconfig", { clear = true })
1212 ---@field use string[]
1313 ---@field formatters? table<string, conform.FileFormatterConfig>
1414
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+
1521 ---@class FTSpec
1622 ---@field indent? integer
1723 ---@field conform? FTConformSpec
24+---@field keymaps? FTKeymapOptions[]
1825 ---@field lsp? table<LSPName, any>
1926
2027 ---Loads the config for the given filename
@@ -39,6 +46,16 @@ function M.load_file(filename)
3946 vim.opt_local.softtabstop = indent
4047 end,
4148 })
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
4259 if spec.conform then
4360 local conform_opts =
4461 { formatters_by_ft = { [ft] = spec.conform.use }, formatters = spec.conform.formatters }