Ajout de la commande Tpl
This commit is contained in:
parent
50128c28c7
commit
2dcd24a5ef
5
lua/tpl/init.lua
Normal file
5
lua/tpl/init.lua
Normal file
@ -0,0 +1,5 @@
|
||||
local header = require('tpl.tpl')
|
||||
|
||||
return {
|
||||
header = header
|
||||
}
|
31
lua/tpl/tpl.lua
Normal file
31
lua/tpl/tpl.lua
Normal file
@ -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
|
@ -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!
|
||||
|
Loading…
x
Reference in New Issue
Block a user