diff options
| author | Robert Günzler <r@gnzler.io> | 2022-09-28 18:51:57 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2022-09-28 18:51:57 +0200 |
| commit | 056873faeffc7bc65096b74aefebedb8cf42235e (patch) | |
| tree | cacd02ac87e563919562c3bbf4de33a82b3b0ada /.vim/snippets/all.lua | |
| parent | c10ecbc16dec71108748f192b5579a23b75651b9 (diff) | |
vim/snips: refactor luasnip config
Diffstat (limited to '.vim/snippets/all.lua')
| -rw-r--r-- | .vim/snippets/all.lua | 53 |
1 files changed, 53 insertions, 0 deletions
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 + } + } + } + ), +} |