irongit

filetype configs with named files. has telescope

made a command to edit filetype configs

huncholanehuncholaneauthored
parent 2c1bd0fcommit 971f9027a0dc3c8220c26f1c2fd444f2ca830bb9Browse files

3 files changed, +33 -11

+12-0lua/ftconfig/commands.lua
@@ -0,0 +1,12 @@
1+vim.api.nvim_create_user_command("FT", function(args)
2+ require("ftconfig").edit_filetype(args.fargs[1])
3+end, {
4+ nargs = 1,
5+ desc = "Edit or create config for given filetype",
6+ complete = function(lead, _, _)
7+ local options = vim.fn.getcompletion("", "filetype")
8+ return vim.tbl_filter(function(item)
9+ return vim.startswith(item, lead)
10+ end, options)
11+ end,
12+})
+21-11lua/ftconfig/init.lua
@@ -1,6 +1,7 @@
11 local M = {}
22
33 M.ftdir = vim.fn.stdpath("config") .. "/lua/ftconfig"
4+M.filetypes = {}
45
56 if vim.fn.isdirectory(M.ftdir) == 0 then
67 vim.fn.mkdir(M.ftdir, "p")
@@ -8,12 +9,6 @@ end
89
910 local augroup = vim.api.nvim_create_augroup("ftconfig", { clear = true })
1011
11-function M.files()
12- return vim.fn.readdir(M.ftdir, function(file)
13- return file:match("%.lua$") and 1 or 0
14- end)
15-end
16-
1712 ---@class FTConformSpec
1813 ---@field use string[]
1914 ---@field formatters? conform.FileFormatterConfig[]
@@ -23,9 +18,11 @@ end
2318 ---@field conform? FTConformSpec
2419 ---@field lsp? table<LSPName, any>
2520
26----builds config for filetype
27----@param ft string
28-function M.setup_ft(ft)
21+---Loads the config for the given filename
22+---@param filename string
23+function M.load_file(filename)
24+ local ft = vim.fn.fnamemodify(filename, ":r")
25+ table.insert(M.filetypes, ft)
2926 local mod = "ftconfig." .. ft
3027 local ok, spec = pcall(require, mod)
3128 if not ok then
@@ -52,10 +49,23 @@ function M.setup_ft(ft)
5249 end
5350 end
5451
52+---creates a new filetype and begins to edit it
53+---@param ft string
54+function M.edit_filetype(ft)
55+ local filename = M.ftdir .. "/" .. ft .. ".lua"
56+ if vim.fn.filereadable(filename) == 0 then
57+ table.insert(M.filetypes, ft)
58+ end
59+ vim.cmd("edit " .. M.ftdir .. "/" .. ft .. ".lua")
60+end
61+
5562 function M.setup()
56- for _, file in ipairs(M.files()) do
57- M.setup_ft(vim.fn.fnamemodify(file, ":r"))
63+ for _, file in ipairs(vim.fn.readdir(M.ftdir)) do
64+ if file:match("%.lua") then
65+ M.load_file(file)
66+ end
5867 end
68+ require("ftconfig.commands")
5969 end
6070
6171 return M
+0-0lua/ftconfig/telescope/_extensions/ftconfig.lua

No content changes (mode or rename only).