From c019c9a5a710b6a60ca88cbda53c2912ba647f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Vigil=20V=C3=A1squez?= Date: Sun, 28 Jan 2024 12:52:24 -0300 Subject: [PATCH 1/2] feat: remove need of specifying patterns Related to #41 --- lua/esqueleto/autocmd.lua | 15 ++++++++++++++- lua/esqueleto/config.lua | 8 ++++---- lua/esqueleto/utils.lua | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lua/esqueleto/autocmd.lua b/lua/esqueleto/autocmd.lua index 09fdc3f..64da2b4 100644 --- a/lua/esqueleto/autocmd.lua +++ b/lua/esqueleto/autocmd.lua @@ -11,12 +11,25 @@ M.createautocmd = function(opts) { clear = true } ) + 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.print(getpatterns()) + vim.api.nvim_create_autocmd( { "BufWinEnter", "BufReadPost", "FileType" }, { group = group, desc = "esqueleto.nvim :: Insert template", - pattern = opts.patterns, + pattern = getpatterns(), callback = function() local filepath = vim.fn.expand("%") local emptyfile = vim.fn.getfsize(filepath) < 4 diff --git a/lua/esqueleto/config.lua b/lua/esqueleto/config.lua index b9f4697..7c970d2 100644 --- a/lua/esqueleto/config.lua +++ b/lua/esqueleto/config.lua @@ -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 = { @@ -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' } }, diff --git a/lua/esqueleto/utils.lua b/lua/esqueleto/utils.lua index 41949d1..9c0a893 100644 --- a/lua/esqueleto/utils.lua +++ b/lua/esqueleto/utils.lua @@ -191,6 +191,7 @@ M.inserttemplate = function(opts) elseif vim.tbl_contains(opts.patterns, filetype) then pattern = filetype end + print(pattern) -- Get templates for selected pattern local templates = M.gettemplates(pattern, opts) From 011a210cff69d604de3bac53d9b0f3b7b8096d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Vigil=20V=C3=A1squez?= Date: Mon, 25 Mar 2024 19:02:08 -0300 Subject: [PATCH 2/2] fix: change some things that broke the plugin --- lua/esqueleto/autocmd.lua | 2 +- lua/esqueleto/utils.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/esqueleto/autocmd.lua b/lua/esqueleto/autocmd.lua index 9653d00..f67695b 100644 --- a/lua/esqueleto/autocmd.lua +++ b/lua/esqueleto/autocmd.lua @@ -20,7 +20,7 @@ M.createautocmd = function(opts) end end - vim.api.nvim_create_autocmd({ "BufWinEnter", "BufReadPost", "BufNewFile" }, { + vim.api.nvim_create_autocmd({ "BufNewFile", "BufReadPost", "FileType" }, { group = group, desc = "esqueleto.nvim :: Insert template", pattern = getpatterns(), diff --git a/lua/esqueleto/utils.lua b/lua/esqueleto/utils.lua index caad45d..4d408c3 100644 --- a/lua/esqueleto/utils.lua +++ b/lua/esqueleto/utils.lua @@ -191,7 +191,6 @@ M.inserttemplate = function(opts) elseif vim.tbl_contains(opts.patterns, filetype) then pattern = filetype end - print(pattern) -- Get templates for selected pattern local templates = M.gettemplates(pattern, opts)