summary refs log tree commit diff
path: root/.vim/snippets/all.lua
blob: 0bcba0820ce6a632456515e10218206cf1ce37ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---@diagnostic disable: undefined-global
local events = require('luasnip.util.events')

local fromglob = function(pattern, opts)
  local choices = {}
  for _, path in ipairs(vim.fn.glob(pattern, false, true, false)) do
    choices[#choices + 1] = f(function(_, _, uargs)
      return vim.fn.readfile(uargs)
    end, {}, { user_args = { path } })
  end
  return sn(nil, { c(1, choices, opts) })
end

local commentwrap = function(opts)
  return vim.tbl_extend('error', opts or {}, {
    callbacks = {
      [-1] = {
        [events.leave] = function(node)
          local start_ln = node:get_buf_position()[1] + 1
          local end_ln = start_ln + #node:get_text() - 1
          require('vim._comment').toggle_lines(start_ln, end_ln)
        end,
      },
    },
  })
end

return {
  -- mini symbols
  s('check', t([[]])),
  s('cross', t([[]])),
  s('...', t([[]])),

  s(
    'memail',
    c(1, {
      t([[robert@gnzler.de]]),
      t([[robert@gnzler.io]]),
    })
  ),
  s('mename', t([[Robert Günzler]])),
  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(
    { trig = 'license' },
    d(1, function()
      local pattern = vim.fn.stdpath('config') .. '/snippets/license_*.txt'
      return fromglob(pattern, { name = 'LICENSE templates' })
    end, nil)
  ),

  s(
    { trig = 'spdx' },
    d(1, function()
      local pattern = vim.fn.stdpath('config') .. '/snippets/spdx_*.txt'
      return fromglob(pattern, { name = 'SPDX header templates' })
    end),
    commentwrap(nil)
  ),

  s(
    { trig = 'todo' },
    isn(1, {
      c(1, {
        sn(nil, { i(1, 'TODO') }),
        sn(nil, { i(1, 'NOTE') }),
        sn(nil, { i(1, 'XXX') }),
      }),
      c(2, {
        sn(nil, { i(1) }),
        sn(nil, { t('('), i(1, 'robertgzr'), t(')') }),
      }),
      t(': '),
      i(3, 'your comment here'),
    }, ''),
    commentwrap(nil)
  ),

  s(
    { trig = '#!/bin' },
    d(1, function()
      local pattern = vim.fn.stdpath('config') .. '/snippets/sh_*.txt'
      return fromglob(pattern, { name = 'Shell script template' })
    end, {}),
    {
      callbacks = {
        [-1] = {
          [events.pre_expand] = function()
            vim.opt_local.filetype = 'sh'
          end,
        },
      },
    }
  ),
}