Skip to content

Instantly share code, notes, and snippets.

@norcalli
Created August 24, 2020 07:12
Show Gist options
  • Save norcalli/67cd0dd97346ef452f08d3d1d00762e3 to your computer and use it in GitHub Desktop.
Save norcalli/67cd0dd97346ef452f08d3d1d00762e3 to your computer and use it in GitHub Desktop.
local snippets = require'snippets'
local U = require'snippets.utils'
local C = require'snippets.common'
local format = string.format
local insert = table.insert
local concat = table.concat
function time_delayed(count)
vim.schedule(function()
local api = vim.api
local row, col = unpack(api.nvim_win_get_cursor(0))
local L = api.nvim_buf_get_lines(0, row-1, row-1+count, false)
api.nvim_buf_set_lines(0, row-1, row+count-1, false, {''})
snippets.expand_at_cursor(concat(L, '\n'))
end)
end
snippets.snippets = {
test = (function()
local S = [[$0# $1 items${|S.b == S.sb and time_delayed(1+(tonumber(S[1]) or 0))}]]
S = U.into_snippet(S)
local function bufnr()
return tostring(vim.api.nvim_get_current_buf())
end
insert(S, C.structure_variable(false, 'sb', R.once(bufnr), -1, function() end))
insert(S, C.structure_variable(false, 'b', bufnr, -1, function() end))
insert(S, C.make_postorder_function_component(function(S)
local L = {}
for i = 1, tonumber(S[1]) or 0 do
L[i] = format("%d. $%d", i, i)
end
return '\n'..concat(L, '\n')
end))
S = U.match_indentation(S)
return S
end)();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment