filetype configs with named files. has telescope
made a command to edit filetype configs
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 @@ | ||
| 1 | 1 | local M = {} |
| 2 | 2 | |
| 3 | 3 | M.ftdir = vim.fn.stdpath("config") .. "/lua/ftconfig" |
| 4 | +M.filetypes = {} | |
| 4 | 5 | |
| 5 | 6 | if vim.fn.isdirectory(M.ftdir) == 0 then |
| 6 | 7 | vim.fn.mkdir(M.ftdir, "p") |
| @@ -8,12 +9,6 @@ end | ||
| 8 | 9 | |
| 9 | 10 | local augroup = vim.api.nvim_create_augroup("ftconfig", { clear = true }) |
| 10 | 11 | |
| 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 | - | |
| 17 | 12 | ---@class FTConformSpec |
| 18 | 13 | ---@field use string[] |
| 19 | 14 | ---@field formatters? conform.FileFormatterConfig[] |
| @@ -23,9 +18,11 @@ end | ||
| 23 | 18 | ---@field conform? FTConformSpec |
| 24 | 19 | ---@field lsp? table<LSPName, any> |
| 25 | 20 | |
| 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) | |
| 29 | 26 | local mod = "ftconfig." .. ft |
| 30 | 27 | local ok, spec = pcall(require, mod) |
| 31 | 28 | if not ok then |
| @@ -52,10 +49,23 @@ function M.setup_ft(ft) | ||
| 52 | 49 | end |
| 53 | 50 | end |
| 54 | 51 | |
| 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 | + | |
| 55 | 62 | 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 | |
| 58 | 67 | end |
| 68 | + require("ftconfig.commands") | |
| 59 | 69 | end |
| 60 | 70 | |
| 61 | 71 | return M |
+0-0lua/ftconfig/telescope/_extensions/ftconfig.lua
No content changes (mode or rename only).