Skip to content

Commit

Permalink
fix: remove useless validation
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-kotake committed Oct 25, 2024
1 parent 25fa166 commit 8a4d901
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions lua/nvim-chezmoi/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function M.setup(opts)
return vim.api.nvim_create_augroup("nvim-chezmoi_" .. name, {})
end

local autocmd = function(events, group, pattern, callback)
vim.api.nvim_create_autocmd(events, {
group = augroup(group),
pattern = pattern,
local autocmd = function(callback)
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
group = augroup("source-path"),
pattern = config.source_path .. "/*",
callback = callback,
})
end
Expand All @@ -75,34 +75,27 @@ function M.setup(opts)
end

--- Set filetype for source file
autocmd(
{ "BufNewFile", "BufRead" },
"source-path",
config.source_path .. "/*",
function(ev)
user_cmd(
ev.buf,
"ChezmoiDetectFileType",
"Detect the filetype for a source file",
function()
detect_filetype(ev.buf, ev.file)
end
)

user_cmd(
ev.buf,
"ChezmoiExecuteTemplate",
"Preview the file template",
function()
execute_template(ev.buf, ev.file)
end
)
autocmd(function(ev)
user_cmd(
ev.buf,
"ChezmoiDetectFileType",
"Detect the filetype for a source file",
function()
detect_filetype(ev.buf, ev.file)
end
)

if config.edit.detect_filetype then
vim.cmd("ChezmoiDetectFileType")
user_cmd(
ev.buf,
"ChezmoiExecuteTemplate",
"Preview the file template",
function()
execute_template(ev.buf, ev.file)
end
end
)
)

vim.cmd("ChezmoiDetectFileType")
end)

return M
end
Expand Down

0 comments on commit 8a4d901

Please sign in to comment.