From 056873faeffc7bc65096b74aefebedb8cf42235e Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 28 Sep 2022 18:51:57 +0200 Subject: vim/snips: refactor luasnip config --- .vim/snippets/all.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++ .vim/snippets/gitcommit.lua | 4 ++++ .vim/snippets/go.lua | 28 ++++++++++++++++++++++++ .vim/snippets/lua.lua | 18 +++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 .vim/snippets/all.lua create mode 100644 .vim/snippets/gitcommit.lua create mode 100644 .vim/snippets/go.lua create mode 100644 .vim/snippets/lua.lua (limited to '.vim/snippets') diff --git a/.vim/snippets/all.lua b/.vim/snippets/all.lua new file mode 100644 index 0000000..a8157cc --- /dev/null +++ b/.vim/snippets/all.lua @@ -0,0 +1,53 @@ + +local todo_comment = function(key) + local nodes = {} + if type(key) == 'string' then + table.insert(nodes, t(key)) + elseif type(key) == 'table' then + table.insert(nodes, c(1, vim.tbl_map(function(e) return t(e) end, key))) + end + local wrapped = autowrap(t('('), t(')'), { + c(#nodes, { + t(''), -- bare + sn(1, user_email), + f(function() return os.date('%Y-%m-%d') end, {}), -- time + }), + }) + for _, n in ipairs(wrapped) do table.insert(nodes, n) end + table.insert(nodes, t(': ')) + return comment(nodes) +end + +return { + s('me', user_email), + s('today', f(function() return os.date('%Y-%m-%d') end, {})), + s('now' , f(function() return os.date('%Y-%m-%dT%H:%M:%SZ') end, {})), + + -- todo comments + s('todo', todo_comment('TODO')), + s('note', todo_comment('NOTE')), + s('hack', todo_comment('HACK')), + s('warn', todo_comment({'WARN', 'XXX'})), + s('fix' , todo_comment({'FIX', 'FIXME', 'ISSUE', 'BUG'})), + + s({trig='#!', name='Shell script skeleton'}, + fmt([=[ + #!/bin/sh + + set -e + [ -n "$DEBUG" ] && set -x + [ -n "$DESC" ] && desc() {{ + printf "{}" + exit 0 + }} + + ]=], {i(1, 'what does this script do')}), + { + callbacks = { + [-1] = { + [events.enter] = function(_, _) vim.opt_local.filetype = 'sh' end + } + } + } + ), +} diff --git a/.vim/snippets/gitcommit.lua b/.vim/snippets/gitcommit.lua new file mode 100644 index 0000000..fd96216 --- /dev/null +++ b/.vim/snippets/gitcommit.lua @@ -0,0 +1,4 @@ +return { + s('sign' , fmt([[Signed-off-by: {}]], {sn(1, user_email)})), + s('change', fmt([[Change-type: {}]], {c(1, {t('patch'), t('minor'), t('major')}) })), +} diff --git a/.vim/snippets/go.lua b/.vim/snippets/go.lua new file mode 100644 index 0000000..ee63158 --- /dev/null +++ b/.vim/snippets/go.lua @@ -0,0 +1,28 @@ +return { + s({trig='package main', name='Go skeleton'}, + fmt([[ + package main + + func main() {{ + {} + }} + ]], {i(0, 'println("hello world!")')}) + ), + s({trig='package test', name='Go test skeleton'}, + fmt([[ + package main + + import ( + "testing" + ) + + func Test{}(t *testing.T) {{ + {} + }} + ]], { + i(1, 'Foobar'), + i(0, 't.Logf("Hello world")'), + } + ) + ), +} diff --git a/.vim/snippets/lua.lua b/.vim/snippets/lua.lua new file mode 100644 index 0000000..0d2609a --- /dev/null +++ b/.vim/snippets/lua.lua @@ -0,0 +1,18 @@ +return { + s('use', fmt([[ + use {{'{}'{} -- {{{{{{ + config = function() + require('{}').setup {{}} + end}} -- }}}}}} + ]], { + i(1, 'username/repo'), + c(2, { + t(','), + t(', disabled = true,'), + fmt([[, cmd = {{'{}'}}, module = {{'{}'}},]], + {i(1, 'Cmd'), i(2, 'module')}) + }), + i(3, 'module'), + }) + ), +} -- cgit 1.4.1