diff --git a/lua/tpl/init.lua b/lua/tpl/init.lua new file mode 100644 index 0000000..7719e1a --- /dev/null +++ b/lua/tpl/init.lua @@ -0,0 +1,5 @@ +local header = require('tpl.tpl') + +return { + header = header +} diff --git a/lua/tpl/tpl.lua b/lua/tpl/tpl.lua new file mode 100644 index 0000000..c3b8a15 --- /dev/null +++ b/lua/tpl/tpl.lua @@ -0,0 +1,31 @@ +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 diff --git a/plugin/crown.vim b/plugin/crown.vim index ff8b88a..b7c1816 100644 --- a/plugin/crown.vim +++ b/plugin/crown.vim @@ -9,16 +9,18 @@ function! ReloadPlugin() " Attention à ne pas mettre d'espace devant lua et EOF lua << EOF + print("Reload") for k in pairs(package.loaded) do - if k:match("^greetings") - then package.loaded[k] = nil + if k:match("^greetings") or k:match("^tpl") then + print(k) + package.loaded[k] = nil end end - require("greetings") EOF endfunction command! Greet lua require'greetings'.greet() +command! Tpl lua require'tpl'.header() augroup ReloadingGroup autocmd!