summaryrefslogtreecommitdiff
path: root/script/core/snippet.lua
blob: 7532ce9b34368c4c5ec47820c8734e960bda348c (plain)
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
local snippet = {}

local function add(cate, key, label)
    return function (text)
        if not snippet[cate] then
            snippet[cate] = {}
        end
        if not snippet[cate][key] then
            snippet[cate][key] = {}
        end
        snippet[cate][key][#snippet[cate][key]+1] = {
            label = label,
            text = text,
        }
    end
end

add('key', 'do', 'do .. end') [[
do
    $0
end]]

add('key', 'elseif', 'elseif .. then')
[[elseif ${1:true} then]]

add('key', 'for', 'for .. in') [[
for ${1:key, value} in ${2:pairs(t)} do
    $0
end]]

add('key', 'for', 'for i = ..') [[
for ${1:i} = ${2:1}, ${3:10, 2} do
    $0
end]]

add('key', 'function', 'function ()') [[
function $1(${2:arg1, arg2, arg3})
    $0
end]]

add('key', 'local', 'local function') [[
local function ${1:name}(${2:arg1, arg2, arg3})
    $0
end]]

add('key', 'if', 'if .. then') [[
if ${1:true} then
    $0
end]]

add('key', 'repeat', 'repeat .. until') [[
repeat
    $0
until ${1:true}]]

add('key', 'while', 'while .. do') [[
while ${1:true} do
    $0
end]]

add('key', 'return', 'do return end') 
[[do return ${1:true} end]]

return snippet