summary refs log tree commit diff
path: root/.vim/snippets
diff options
context:
space:
mode:
Diffstat (limited to '.vim/snippets')
-rw-r--r--.vim/snippets/all.lua94
-rw-r--r--.vim/snippets/gitcommit.lua7
-rw-r--r--.vim/snippets/go.lua19
-rw-r--r--.vim/snippets/lua.lua27
4 files changed, 88 insertions, 59 deletions
diff --git a/.vim/snippets/all.lua b/.vim/snippets/all.lua
index ba26a8f..b4fa8c3 100644
--- a/.vim/snippets/all.lua
+++ b/.vim/snippets/all.lua
@@ -1,46 +1,63 @@
+---@diagnostic disable: undefined-global
 
 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)))
+    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
+      f(function()
+        return os.date('%Y-%m-%d')
+      end, {}), -- time
     }),
   })
-  for _, n in ipairs(wrapped) do table.insert(nodes, n) end
+  for _, n in ipairs(wrapped) do
+    table.insert(nodes, n)
+  end
   table.insert(nodes, t(': '))
   return comment(nodes)
 end
 
-local from_file = function(path, vargs)
-  return d(1, function(_, _, _, ...)
-    local lines = {}
-    for line in io.lines(path) do table.insert(lines, line) end
-    return sn(nil, fmt(table.concat(lines, "\n"), ...))
-  end, {}, { user_args = {vargs}})
-end
-
 return {
   s('me', user_email),
   s('date', exec([[date --rfc-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, {})),
+  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('warn', todo_comment({ 'WARN', 'XXX' })),
+  s('fix', todo_comment({ 'FIX', 'FIXME', 'ISSUE', 'BUG' })),
 
-  s({trig='#!', name='Shell script skeleton'},
-    fmt([=[
+  s(
+    { trig = '#!', name = 'Shell script skeleton' },
+    fmt(
+      [=[
       #!/bin/sh
 
       set -e
@@ -50,33 +67,32 @@ return {
       	exit 0
       }}
 
-    ]=], {i(1, 'what does this script do')}),
+    ]=],
+      { i(1, 'what does this script do') }
+    ),
     {
       callbacks = {
         [-1] = {
-          [events.enter] = function(_, _) vim.opt_local.filetype = 'sh' end
-        }
-      }
+          [events.enter] = function(_, _)
+            vim.opt_local.filetype = 'sh'
+          end,
+        },
+      },
     }
   ),
 
-  -- licenses (full-text)
-  s({trig='license-mit', name='MIT license'}, from_file(
-      vim.fn.stdpath('config') .. '/snippets/.licenses/mit',
-      {
-        year = f(function() return os.date('%Y') end, {}),
-        copyright = sn(1, user_email),
-      })
-  ),
-  s({trig='license-gpl-3.0', name='GPL-3.0 license'}, from_file(
-      vim.fn.stdpath('config') .. '/snippets/.licenses/gpl-3.0', {})),
-  s({trig='license-agpl-3.0', name='AGPL-3.0 license'}, from_file(
-      vim.fn.stdpath('config') .. '/snippets/.licenses/agpl-3.0', {})),
-  s({trig='license-cc0-1.0', name='CC-Zero-1.0 license'}, from_file(
-      vim.fn.stdpath('config') .. '/snippets/.licenses/cc0-1.0', {})),
   -- licenses (SPDX header)
-  s({trig='spdx-mit', name='MIT license'}, comment({t([[SPDX-License-Identifier: MIT]])})),
-  s({trig='spdx-gpl-3.0', name='MIT license'}, comment({t([[SPDX-License-Identifier: GPL-3.0]])})),
-  s({trig='spdx-agpl-3.0', name='MIT license'}, comment({t([[SPDX-License-Identifier: AGPL-3.0]])})),
-  s({trig='spdx-cc0-1.0', name='MIT license'}, comment({t([[SPDX-License-Identifier: CC0-1.0]])})),
+  s({ trig = 'spdx-mit', name = 'MIT license' }, comment({ t([[SPDX-License-Identifier: MIT]]) })),
+  s(
+    { trig = 'spdx-gpl-3.0', name = 'MIT license' },
+    comment({ t([[SPDX-License-Identifier: GPL-3.0]]) })
+  ),
+  s(
+    { trig = 'spdx-agpl-3.0', name = 'MIT license' },
+    comment({ t([[SPDX-License-Identifier: AGPL-3.0]]) })
+  ),
+  s(
+    { trig = 'spdx-cc0-1.0', name = 'MIT license' },
+    comment({ t([[SPDX-License-Identifier: CC0-1.0]]) })
+  ),
 }
diff --git a/.vim/snippets/gitcommit.lua b/.vim/snippets/gitcommit.lua
index c6153a3..8e8e18f 100644
--- a/.vim/snippets/gitcommit.lua
+++ b/.vim/snippets/gitcommit.lua
@@ -1,5 +1,6 @@
+---@diagnostic disable: undefined-global
 return {
-  s('sign'  , fmt([[Signed-off-by: {}]], {sn(1, user_email)})),
-  s('change', fmt([[Change-type: {}]], {c(1, {t('patch'), t('minor'), t('major')})})),
-  s('coauth', fmt([[Co-authored-by: {}]], {i(1)})),
+  s('sign', fmt([[Signed-off-by: {}]], { sn(1, user_email) })),
+  s('change', fmt([[Change-type: {}]], { c(1, { t('patch'), t('minor'), t('major') }) })),
+  s('coauth', fmt([[Co-authored-by: {}]], { i(1) })),
 }
diff --git a/.vim/snippets/go.lua b/.vim/snippets/go.lua
index ee63158..7b3bb71 100644
--- a/.vim/snippets/go.lua
+++ b/.vim/snippets/go.lua
@@ -1,15 +1,21 @@
 return {
-  s({trig='package main', name='Go skeleton'},
-    fmt([[
+  s(
+    { trig = 'package main', name = 'Go skeleton' },
+    fmt(
+      [[
       package main
 
       func main() {{
       	{}
       }}
-    ]], {i(0, 'println("hello world!")')})
+    ]],
+      { i(0, 'println("hello world!")') }
+    )
   ),
-  s({trig='package test', name='Go test skeleton'},
-    fmt([[
+  s(
+    { trig = 'package test', name = 'Go test skeleton' },
+    fmt(
+      [[
       package main
 
       import (
@@ -19,7 +25,8 @@ return {
       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
index 0d2609a..dc75ec8 100644
--- a/.vim/snippets/lua.lua
+++ b/.vim/snippets/lua.lua
@@ -1,18 +1,23 @@
+---@diagnostic disable: undefined-global
 return {
-  s('use', fmt([[
+  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'),
-    })
+    ]],
+      {
+        i(1, 'username/repo'),
+        c(2, {
+          t(','),
+          t(', disabled = true,'),
+          fmt([[, cmd = {{'{}'}}, module = {{'{}'}},]], { i(1, 'Cmd'), i(2, 'module') }),
+        }),
+        i(3, 'module'),
+      }
+    )
   ),
 }