tangled
alpha
login
or
join now
boltless.me
/
nvim_rocks
0
fork
atom
neovim configuration using rocks.nvim plugin manager
0
fork
atom
overview
issues
pulls
pipelines
feat(snippets): cool ranged-tag snippets
boltless.me
10 months ago
f09d1e84
6b53d151
verified
This commit was signed with the committer's
known signature
.
boltless.me
SSH Key Fingerprint:
SHA256:2RJEzZAkDasLTx4PI9wgenxutg9oQkR9LGk+9pzW3hM=
+29
-6
1 changed file
expand all
collapse all
unified
split
lua
snippets
norg.lua
+29
-6
lua/snippets/norg.lua
···
6
6
local i = ls.insert_node
7
7
local f = ls.function_node
8
8
local d = ls.dynamic_node
9
9
+
local t = ls.text_node
9
10
local k = require("luasnip.nodes.key_indexer").new_key
10
11
local rep = require("luasnip.extras").rep
11
12
local fmt = require("luasnip.extras.fmt").fmt
···
20
21
local function btime_fn()
21
22
local path = vim.fn.expand("%")
22
23
local stat = vim.uv.fs_stat(path)
23
23
-
local btime = stat.birthtime or stat.mtime
24
24
-
btime = btime.sec
24
24
+
assert(stat)
25
25
+
local btime = (stat.birthtime or stat.mtime).sec
25
26
return os.date(DATE_FORMAT, btime)
26
27
end
27
28
28
29
local function mtime_fn()
29
30
local path = vim.fn.expand("%")
30
31
local stat = vim.uv.fs_stat(path)
31
31
-
local mtime = stat.mtime
32
32
-
mtime = mtime.sec
32
32
+
assert(stat)
33
33
+
local mtime = stat.mtime.sec
33
34
return os.date(DATE_FORMAT, mtime)
34
35
end
35
36
···
61
62
d(1, file_index_fn),
62
63
f(btime_fn),
63
64
f(mtime_fn),
64
64
-
-- t"",
65
65
-
-- t"",
66
65
}
67
66
)),
67
67
+
-- cool ranged-tag snippet
68
68
+
s(
69
69
+
{ trig = "(@+)([a-z\\-]+)", regTrig = true, wordTrig = false, name = "Dynamic Code Trigger" },
70
70
+
{
71
71
+
f(function(_, snip)
72
72
+
return snip.captures[1]
73
73
+
end, {}, { key = "prefix" }),
74
74
+
f(function(_, snip)
75
75
+
return snip.captures[2]
76
76
+
end),
77
77
+
i(1),
78
78
+
t{"", ""},
79
79
+
f(function(_, snip)
80
80
+
local current_line = snip.env.TM_CURRENT_LINE
81
81
+
local trigger_column = current_line:find(snip.trigger, 1, true)
82
82
+
return string.rep(" ", trigger_column - 1)
83
83
+
end, {}, { key = "indent" }),
84
84
+
i(2),
85
85
+
t{"", ""},
86
86
+
rep(k("indent")),
87
87
+
rep(k("prefix")),
88
88
+
t{"end", ""},
89
89
+
}
90
90
+
),
68
91
})