crown/lua/tpl/tpl.lua
2022-01-27 15:29:17 +01:00

32 lines
731 B
Lua

local function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
local function get_lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
local function header()
local filetype = vim.api.nvim_buf_get_option(0, 'filetype')
if filetype ~= "" then
if file_exists('data/tpl/header-' .. filetype .. '.tpl') then
local lines = get_lines_from('data/tpl/header-' .. filetype .. '.tpl')
vim.api.nvim_put(lines, "l", false, true)
else
print("Pas de fichier pour ce filetype")
end
else
print("Pas de filetype")
end
end
return header