Skip to content

Commit

Permalink
feat: add ability to configure filetypes with vim.filetype.add
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Mar 1, 2024
1 parent 526e827 commit 51ac59f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ local opts = {
desc = "Reload AstroNvim (Experimental)",
},
},
-- passed to `vim.filetype.add`
filetypes = {
-- see `:h vim.filetype.add` for usage
extension = {
foo = "fooscript",
},
filename = {
[".foorc"] = "fooscript",
},
pattern = {
[".*/etc/foo/.*"] = "fooscript",
},
},
-- Configuration of vim mappings to create
mappings = {
-- map mode (:h map-modes)
Expand Down
21 changes: 21 additions & 0 deletions lua/astrocore/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@
---}
---```
---@field commands table<string,AstroCoreCommand|false>?
---Configuration of filetypes, simply runs `vim.filetype.add`
---
---See `:h vim.filetype.add` for details on usage
---
---Example:
---
---```lua
---filetypes = { -- parameter to `vim.filetype.add`
--- extension = {
--- foo = "fooscript"
--- },
--- filename = {
--- [".foorc"] = "fooscript"
--- },
--- pattern = {
--- [".*/etc/foo/.*"] = "fooscript",
--- }
---}
---```
---@field filetypes vim.filetype.add.filetypes?
---Configuration of vim mappings to create.
---The first key into the table is the vim map mode (`:h map-modes`), and the value is a table of entries to be passed to `vim.keymap.set` (`:h vim.keymap.set`):
--- - The key is the first parameter or the vim mode (only a single mode supported) and the value is a table of keymaps within that mode:
Expand Down Expand Up @@ -260,6 +280,7 @@
---@type AstroCoreOpts
local M = {
autocmds = {},
filetypes = {},
commands = {},
mappings = {},
on_keys = {},
Expand Down
3 changes: 3 additions & 0 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ function M.setup(opts)
end
end

-- vim.filetype
if M.config.filetypes then vim.filetype.add(M.config.filetypes) end

-- on_key hooks
for namespace, funcs in pairs(M.config.on_keys) do
if funcs then
Expand Down

0 comments on commit 51ac59f

Please sign in to comment.