neovim configuration using rocks.nvim plugin manager

feat(snippets): cool ranged-tag snippets

boltless.me f09d1e84 6b53d151

verified
+29 -6
+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 + 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 - local btime = stat.birthtime or stat.mtime 24 - btime = btime.sec 24 + assert(stat) 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 - local mtime = stat.mtime 32 - mtime = mtime.sec 32 + assert(stat) 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 - -- t"", 65 - -- t"", 66 65 } 67 66 )), 67 + -- cool ranged-tag snippet 68 + s( 69 + { trig = "(@+)([a-z\\-]+)", regTrig = true, wordTrig = false, name = "Dynamic Code Trigger" }, 70 + { 71 + f(function(_, snip) 72 + return snip.captures[1] 73 + end, {}, { key = "prefix" }), 74 + f(function(_, snip) 75 + return snip.captures[2] 76 + end), 77 + i(1), 78 + t{"", ""}, 79 + f(function(_, snip) 80 + local current_line = snip.env.TM_CURRENT_LINE 81 + local trigger_column = current_line:find(snip.trigger, 1, true) 82 + return string.rep(" ", trigger_column - 1) 83 + end, {}, { key = "indent" }), 84 + i(2), 85 + t{"", ""}, 86 + rep(k("indent")), 87 + rep(k("prefix")), 88 + t{"end", ""}, 89 + } 90 + ), 68 91 })