summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.vim/after/snippets/sh.snippets7
-rw-r--r--.vim/lua/snips.lua64
2 files changed, 45 insertions, 26 deletions
diff --git a/.vim/after/snippets/sh.snippets b/.vim/after/snippets/sh.snippets
index 99b8cb7..8973dd5 100644
--- a/.vim/after/snippets/sh.snippets
+++ b/.vim/after/snippets/sh.snippets
@@ -1,10 +1,3 @@
-snippet skel "skeleton"
-	#!/bin/sh
-	
-	set -e
-	[ -n "$DEBUG" ] && set -x
-	
-	$0
 snippet usage "usage"
 	usage() {
 		printf "usage: %s" "$(basename "\$0")\n"
diff --git a/.vim/lua/snips.lua b/.vim/lua/snips.lua
index c4a58af..32e97d1 100644
--- a/.vim/lua/snips.lua
+++ b/.vim/lua/snips.lua
@@ -3,9 +3,11 @@ local ls = require("luasnip")
 local fmt = require('luasnip.extras.fmt').fmt
 
 local s = ls.s
+local sn = ls.sn
 local t = ls.text_node
 local f = ls.function_node
--- local i = ls.insert_node
+local i = ls.insert_node
+local c = ls.choice_node
 
 local exec = function(command)
   return f(function(_, _, arg)
@@ -18,18 +20,32 @@ local exec = function(command)
   end, {}, { user_args = { command }})
 end
 
+local calculate_commentstring = require('Comment.ft').calculate
+local get_region = require('Comment.utils').get_region
+
+---@param ctype number|(ex.: 1 (line), 2 (block))
+local comment = function(ctype, inner)
+  local get_cstring = function()
+    local cs = calculate_commentstring({ ctype = ctype, range = get_region() }) or ''
+    local tbl = vim.split(cs, '%s', {plain = true, trimempty = true})
+    return (#tbl == 0) and {'', ''}
+      or ((#tbl == 1) and {tbl[1], ''}
+        or {tbl[1], tbl[2]})
+  end
+  return sn(nil, {
+    f(function() return get_cstring()[1] end),
+    t(' '),
+    inner,
+    f(function() return get_cstring()[2] end),
+  })
+end
+
 -- snipmate snippets
-require('luasnip.loaders.from_snipmate').load({ paths = {'~/.config/nvim/after/snippets'} })
+-- require('luasnip.loaders.from_snipmate').load({ paths = {'~/.config/nvim/after/snippets'} })
 
--- luasnip snippets
 ls.add_snippets('all', {
-  s(
-    'sign',
-    t('Robert Günzler <r@gnzler.io>')
-  ),
-
-  s(
-    'me',
+  s('sign', t('Robert Günzler <r@gnzler.io>')),
+  s('me',
     fmt(
       [[{} <{}>]], {
         exec('git config --get user.name'),
@@ -37,14 +53,24 @@ ls.add_snippets('all', {
       }
     )
   ),
+}, { type = 'snippets', key = 'signature_helpers'})
 
-  s(
-    'today',
-    f(function() return os.date('%Y-%m-%d') end, {})
-  ),
+ls.add_snippets('all', {
+  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, {}))
+}, { type = 'snippets', key = 'date_helpers'})
 
-  s(
-    'now',
-    f(function() return os.date('%Y-%m-%dT%H:%M:%SZ') end, {})
-  )
-})
+ls.add_snippets('all', {
+  s({ trig = 'todo', docstring = 'TODO:' }, comment(1, fmt([[{}: ]], { t('TODO') }))),
+  -- s({ trig = 'todo', docstring = '{1:TODO}: {2}' }, comment(1, fmt([[{}: {}]], { c(1, {t('TODO')}), i(2) }))),
+  -- s('note', comment(1, fmt([[NOTE: {}]], { i(0) }))),
+  -- s('hack', comment(1, fmt([[HACK: {}]], { i(0) }))),
+  -- s('warn', comment(1, fmt([[{}: {}]], {
+  --   c(1, {t('WARN'), t('WARNING'), t('XXX')}),
+  --   i(0),
+  -- }))),
+  -- s('fix', comment(1, fmt([[{}: {}]], {
+  --   c(1, {t('FIX'), t('FIXME'), t('ISSUE'), t('BUG')}),
+  --   i(0),
+  -- }))),
+}, { type = 'snippets', key = 'todo_comments'})