mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
nvim/typst: lazyload snippets only once
This commit is contained in:
parent
b9fae994cb
commit
5f34897169
1 changed files with 34 additions and 30 deletions
|
|
@ -2,35 +2,39 @@ vim.bo.shiftwidth = 2
|
||||||
vim.bo.tabstop = 2
|
vim.bo.tabstop = 2
|
||||||
vim.bo.textwidth = 100
|
vim.bo.textwidth = 100
|
||||||
|
|
||||||
vim.keymap.set("n", "<leader>f", function()
|
local once = require("once")
|
||||||
local saved = vim.fn.winsaveview()
|
|
||||||
vim.cmd([[silent exec "%!typstyle -c 100"]])
|
|
||||||
vim.fn.winrestview(saved)
|
|
||||||
end, { desc = "ft(typst): Format with typstyle" })
|
|
||||||
|
|
||||||
do
|
once.test_and_load("ft_typst", function()
|
||||||
local luasnip = require("luasnip")
|
vim.keymap.set("n", "<leader>f", function()
|
||||||
local s = luasnip.snippet
|
local saved = vim.fn.winsaveview()
|
||||||
local t = luasnip.text_node
|
vim.cmd([[silent exec "%!typstyle -c 100"]])
|
||||||
local cr = function() return t { "", "" } end
|
vim.fn.winrestview(saved)
|
||||||
local i = luasnip.insert_node
|
end, { desc = "ft(typst): Format with typstyle" })
|
||||||
local f = luasnip.function_node
|
|
||||||
|
|
||||||
local function show_date_typst_entry() return os.date('"%Y-%m-%d %H:%M:%S"') end
|
do
|
||||||
luasnip.add_snippets("typst", {
|
local luasnip = require("luasnip")
|
||||||
s("entry", {
|
local s = luasnip.snippet
|
||||||
t("#entry("),
|
local t = luasnip.text_node
|
||||||
f(show_date_typst_entry),
|
local cr = function() return t { "", "" } end
|
||||||
t { ")[", "" },
|
local i = luasnip.insert_node
|
||||||
t(" "),
|
local f = luasnip.function_node
|
||||||
i(0),
|
|
||||||
t { "", "]" },
|
local function show_date_typst_entry() return os.date('"%Y-%m-%d %H:%M:%S"') end
|
||||||
}),
|
luasnip.add_snippets("typst", {
|
||||||
s("lang", {
|
s("entry", {
|
||||||
t('#set text(lang: "'),
|
t("#entry("),
|
||||||
i(0),
|
f(show_date_typst_entry),
|
||||||
t('")'),
|
t { ")[", "" },
|
||||||
cr(),
|
t(" "),
|
||||||
}),
|
i(0),
|
||||||
})
|
t { "", "]" },
|
||||||
end
|
}),
|
||||||
|
s("lang", {
|
||||||
|
t('#set text(lang: "'),
|
||||||
|
i(0),
|
||||||
|
t('")'),
|
||||||
|
cr(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue