wip luasnip framework
parent
a068850c79
commit
9e5678036c
@ -1,37 +0,0 @@
|
|||||||
priority -55
|
|
||||||
|
|
||||||
global !p
|
|
||||||
from vimsnippets import foldmarker, make_box, get_comment_format
|
|
||||||
endglobal
|
|
||||||
|
|
||||||
|
|
||||||
################
|
|
||||||
# ANSI Color Codes #
|
|
||||||
################
|
|
||||||
|
|
||||||
# The table starts with the original 16 colors (0-15).
|
|
||||||
|
|
||||||
# The proceeding 216 colors (16-231) or formed by a 3bpc RGB value offset by
|
|
||||||
# 16, packed into a single value.
|
|
||||||
|
|
||||||
# The final 24 colors (232-256) are grayscale
|
|
||||||
# starting from a shade slighly lighter than black, ranging up to shade slightly
|
|
||||||
# darker than white.
|
|
||||||
|
|
||||||
# Some emulators interpret these steps as linear
|
|
||||||
# increments from (256 / 24) on all three channels, although some emulators may
|
|
||||||
# explicitly define these values.
|
|
||||||
|
|
||||||
snippet ansi_fg "Foreground ANSI 256 Color Code" i
|
|
||||||
\033[38;5;${1:00}m
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet ansi_bg "Background ANSI 256 Color Code" i
|
|
||||||
\033[48;5;${1:00}m
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet ansi_reset "Reset ANSI 256 Color Code" i
|
|
||||||
\033[0m
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
|||||||
|
---@diagnostic disable: unused-local
|
||||||
|
|
||||||
|
local ls = require("luasnip")
|
||||||
|
local s = ls.snippet
|
||||||
|
local sn = ls.snippet_node
|
||||||
|
local t = ls.text_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
local f = ls.function_node
|
||||||
|
local c = ls.choice_node
|
||||||
|
local fmt = require("luasnip.extras.fmt").fmt
|
||||||
|
local rep = require("luasnip.extras").rep
|
||||||
|
-- local isn = ls.indent_snippet_node
|
||||||
|
-- local d = ls.dynamic_node
|
||||||
|
-- local r = ls.restore_node
|
||||||
|
-- local events = require("luasnip.util.events")
|
||||||
|
-- local ai = require("luasnip.nodes.absolute_indexer")
|
||||||
|
-- local extras = require("luasnip.extras")
|
||||||
|
-- local m = extras.m
|
||||||
|
-- local l = extras.l
|
||||||
|
-- local rep = extras.rep
|
||||||
|
-- local postfix = require("luasnip.extras.postfix").postfix
|
||||||
|
--
|
||||||
|
-- add_snippet helper
|
||||||
|
local add_snippet = require("spike.snips").add_snippet
|
||||||
|
|
||||||
|
|
||||||
|
--HACK: remove after testing snippets or it resets all imported snippets
|
||||||
|
-- require("luasnip.session.snippet_collection").clear_snippets "lua"
|
||||||
|
|
||||||
|
add_snippet {
|
||||||
|
lua = {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
local ok, ls = pcall(require, "luasnip")
|
||||||
|
if not ok then return end
|
||||||
|
|
||||||
|
-- luasnip helpers
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---shortcut for ls.add_snippet(ft, {defs})
|
||||||
|
---@param args table arguments in the form {ft, snippet_defs}
|
||||||
|
M.add_snippet = function(args)
|
||||||
|
for ft,sn_defs in pairs(args) do
|
||||||
|
ls.add_snippets(ft, sn_defs, {override_priority=2000})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return M
|
@ -0,0 +1,20 @@
|
|||||||
|
---@diagnostic disable: undefined-global
|
||||||
|
|
||||||
|
return {
|
||||||
|
-- s("sniptest", {
|
||||||
|
-- t"hello snippet"
|
||||||
|
-- })
|
||||||
|
--
|
||||||
|
|
||||||
|
-- choice nodes
|
||||||
|
s("choice", fmt("{} my {}",{
|
||||||
|
c(2, {t("hello"), t("hi")}),
|
||||||
|
c(1, {t"bob", t"alice"})
|
||||||
|
})
|
||||||
|
),
|
||||||
|
|
||||||
|
-- function node
|
||||||
|
s("pwd", f(function()
|
||||||
|
return vim.fn.getcwd()
|
||||||
|
end))
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
---@diagnostic disable: unused-local, undefined-global
|
||||||
|
|
||||||
|
return {
|
||||||
|
-- s("testgo", {
|
||||||
|
-- t"Hello go snippet"
|
||||||
|
-- })
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
---@diagnostic disable: undefined-global
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
s("testluasnip", {
|
||||||
|
t"Hello lua snippet"
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
-- repeat nodes
|
||||||
|
-- TODO: split dot and pull last name
|
||||||
|
s("req", fmt("local {} = require('{}')", {
|
||||||
|
i(1, "default"),
|
||||||
|
rep(1)
|
||||||
|
}) ),
|
||||||
|
|
||||||
|
s("ifreq", fmt([[
|
||||||
|
local ok, {} = pcall(require, "{}")
|
||||||
|
if not ok then
|
||||||
|
vim.notify("missing module {}", vim.log.levels.WARN)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
{}
|
||||||
|
]], {
|
||||||
|
i(1),
|
||||||
|
rep(1),
|
||||||
|
rep(1),
|
||||||
|
i(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue