diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-09-20 17:15:10 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-09-27 09:06:36 +0200 |
| commit | 216f43fb934f292ed20014018b00e4e0fd6bef6e (patch) | |
| tree | 1cfbd39c0b077fb267ed17b41b45664d4690105f /init.lua | |
| download | vis-snippets-216f43fb934f292ed20014018b00e4e0fd6bef6e.tar.gz vis-snippets-216f43fb934f292ed20014018b00e4e0fd6bef6e.zip | |
rough initial commit
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..b3f06c6 --- /dev/null +++ b/init.lua @@ -0,0 +1,23 @@ +local M = {snippets={}} + +local source_str = debug.getinfo(1, 'S').source:sub(2) +local script_path = source_str:match('(.*/)') +local snippets_path = script_path .. 'snippets' + +vis:command_register('snippet', function(argv, _, win, _, _) + local snippet = argv[1] + if not snippet then return end + local pos = win.selection.pos + if not M.snippets[snippet] then + local snippet_path = snippets_path .. '/' .. argv[1] + local file = io.open(snippet_path, "rb") -- r read mode and b binary mode + if not file then return end + local content = file:read("*a") + file:close() + win.file:insert(pos, content) + else + win.file:insert(pos, M.snippets[snippet]) + end +end, 'Insert a snippet after the primary selection') + +return M |
