Skip to content

Commit

Permalink
feat: remove need to specify patterns (#53)
Browse files Browse the repository at this point in the history
- **feat: remove need of specifying patterns**
- **fix: change some things that broke the plugin**
  • Loading branch information
cvigilv authored Aug 3, 2024
2 parents 0808d75 + 011a210 commit 741d7b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
25 changes: 16 additions & 9 deletions lua/esqueleto/autocmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ M.createautocmd = function(opts)
-- create autocommands for skeleton insertion
local group = vim.api.nvim_create_augroup("esqueleto", { clear = true })

vim.api.nvim_create_autocmd({ "BufWinEnter", "BufReadPost", "FileType" }, {
local function getpatterns()
if type(opts.patterns) == "function" then
if type(opts.directories) == "table" then
return vim.tbl_map(opts.patterns, opts.directories)
else
return opts.patterns(opts.directories)
end
else
return opts.patterns
end
end

vim.api.nvim_create_autocmd({ "BufNewFile", "BufReadPost", "FileType" }, {
group = group,
desc = "esqueleto.nvim :: Insert template",
pattern = opts.patterns,
pattern = getpatterns(),
callback = function()
if vim.bo.buftype == "nofile" then
return nil
end

if vim.bo.buftype == "nofile" then return nil end
local filepath = vim.fn.expand("%")
local emptyfile = vim.fn.getfsize(filepath) < 4
if emptyfile then
utils.inserttemplate(opts)
end
if emptyfile then utils.inserttemplate(opts) end
end,
})
end
Expand Down
8 changes: 4 additions & 4 deletions lua/esqueleto/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local M = {}

M.default_config = {
autouse = true,
directories = { vim.fn.stdpath("config") .. "/skeletons" },
patterns = {},
directories = { vim.fn.stdpath("config") .. "/skeleton" },
patterns = function(dir) return vim.fn.readdir(dir) end,
wildcards = {
expand = true,
lookup = {
Expand Down Expand Up @@ -48,8 +48,8 @@ M.updateconfig = function(config)
-- Validate setup
vim.validate({
autouse = { config.autouse, 'boolean' },
directories = { config.directories, 'table' },
patterns = { config.patterns, 'table' },
directories = { config.directories, { 'table' } },
patterns = { config.patterns, { 'table', 'function' } },
wildcards = { config.wildcards, "table" },
advanced = { config.advanced, 'table' },
["advanced.ignored"] = { config.advanced.ignored, { 'table', 'function' } },
Expand Down

0 comments on commit 741d7b8

Please sign in to comment.