Ændrede diverse ting, især tilføjede jeg en masse lua-snippets
This commit is contained in:
parent
3e9363b016
commit
b1b7a050da
14 changed files with 428 additions and 19 deletions
14
luasnippets/all.lua
Normal file
14
luasnippets/all.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
return {
|
||||
s({ trig = "lolol" }, { t("LuaSnip test") }),
|
||||
}
|
||||
35
luasnippets/lua.lua
Normal file
35
luasnippets/lua.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
return {
|
||||
-- Snippet snippets
|
||||
s(
|
||||
{ trig = "asm", descr = "Autosnippet in math environment" },
|
||||
fmta(
|
||||
[[asm("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
s(
|
||||
{ trig = "as", descr = "Autosnippet (own defined function)" },
|
||||
fmta(
|
||||
[[as("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
s(
|
||||
{ trig = "ast", descr = "Autosnippet in text mode" },
|
||||
fmta(
|
||||
[[ast("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
}
|
||||
30
luasnippets/tex/commands.lua
Normal file
30
luasnippets/tex/commands.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
|
||||
-- from nvim/lua/
|
||||
local helpers = require("luasnip-helpers")
|
||||
local as = helpers.as
|
||||
local ast = helpers.ast
|
||||
return {
|
||||
-- Fonts
|
||||
ast("ttt", fmta("\\texttt{<>}", { i(1) })),
|
||||
-- asm("rm", fmta("\\mathrm{<>}", { i(1) })),
|
||||
ast("tbf", fmta("\\textbf{<>}", { i(1) })),
|
||||
ast("tsf", fmta("\\textsf{<>}", { i(1) })),
|
||||
ast("tit", fmta("\\textit{<>}", { i(1) })),
|
||||
-- Idk, maybe emph can be used in mathmode?
|
||||
ast("emp", fmta("\\emph{<>}", { i(1) })),
|
||||
-- These two normally not needed, as you would define "\R = \mathbb{R}",
|
||||
-- and so on.
|
||||
-- as("bb", fmta("\\mathbb{<>}", { i(1) })),
|
||||
-- as("cal", fmta("\\mathcal{<>}", { i(1) })),
|
||||
}
|
||||
91
luasnippets/tex/environments.lua
Normal file
91
luasnippets/tex/environments.lua
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local rep = require("luasnip.extras").rep
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
--
|
||||
-- AutoSnippet function "as":
|
||||
local function as(trigger, nodes, opts)
|
||||
opts = opts or {}
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
if type(trigger) == "table" then
|
||||
trigger.snippetType = "autosnippet"
|
||||
else
|
||||
trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
end
|
||||
return s(trigger, nodes, opts)
|
||||
end
|
||||
|
||||
return {
|
||||
as(
|
||||
"eq",
|
||||
fmta(
|
||||
[[
|
||||
\[
|
||||
<>
|
||||
\]
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"\\[",
|
||||
fmta(
|
||||
[[
|
||||
\[
|
||||
<>
|
||||
\]
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"beg",
|
||||
fmta(
|
||||
[[
|
||||
\begin{<>}
|
||||
<>
|
||||
\end{<>}
|
||||
]],
|
||||
{ i(1), i(2), rep(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"als",
|
||||
fmta(
|
||||
[[
|
||||
\begin{align*}
|
||||
<>
|
||||
\end{align*}
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"ali",
|
||||
fmta(
|
||||
[[
|
||||
\begin{align}
|
||||
<>
|
||||
\end{align}
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
}
|
||||
82
luasnippets/tex/math.lua
Normal file
82
luasnippets/tex/math.lua
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
|
||||
-- from nvim/lua/
|
||||
local helpers = require("luasnip-helpers")
|
||||
-- Autosnippet, only for math environments
|
||||
local asm = helpers.asm
|
||||
return {
|
||||
-- Greek letters
|
||||
asm(";a", { t("\\alpha") }),
|
||||
asm(";b", { t("\\beta") }),
|
||||
asm(";g", { t("\\gamma") }),
|
||||
asm(";G", { t("\\Gamma") }),
|
||||
asm(";d", { t("\\delta") }),
|
||||
asm(";D", { t("\\Delta") }),
|
||||
-- Next two are swapped on purpose - always use varepsilon!
|
||||
asm(";e", { t("\\varepsilon") }),
|
||||
asm(";ve", { t("\\epsilon") }),
|
||||
asm(";z", { t("\\zeta") }),
|
||||
asm(";t", { t("\\theta") }),
|
||||
asm(";vt", { t("\\vartheta") }),
|
||||
asm(";T", { t("\\Theta") }),
|
||||
asm(";i", { t("\\iota") }),
|
||||
asm(";k", { t("\\kappa") }),
|
||||
asm(";l", { t("\\lambda") }),
|
||||
asm(";L", { t("\\Lambda") }),
|
||||
asm(";m", { t("\\mu") }),
|
||||
asm(";n", { t("\\nu") }),
|
||||
asm(";x", { t("\\xi") }),
|
||||
asm(";X", { t("\\Xi") }),
|
||||
asm(";pi", { t("\\pi") }),
|
||||
asm(";Pi", { t("\\Pi") }),
|
||||
asm(";r", { t("\\rho") }),
|
||||
asm(";vr", { t("\\varrho") }),
|
||||
asm(";s", { t("\\sigma") }),
|
||||
asm(";S", { t("\\Sigma") }),
|
||||
asm(";t", { t("\\tau") }),
|
||||
asm(";u", { t("\\upsilon") }),
|
||||
asm(";U", { t("\\Upsilon") }),
|
||||
asm(";ph", { t("\\phi") }),
|
||||
-- Could be ";vph", but two letters seems nicer
|
||||
asm(";vp", { t("\\varphi") }),
|
||||
asm(";Ph", { t("\\Phi") }),
|
||||
asm(";c", { t("\\chi") }),
|
||||
asm(";ps", { t("\\psi") }),
|
||||
asm(";Ps", { t("\\Psi") }),
|
||||
asm(";o", { t("\\omega") }),
|
||||
asm(";O", { t("\\Omega") }),
|
||||
|
||||
asm("ff", fmta("\\frac{<>}{<>}", { i(1), i(2) })),
|
||||
asm("tf", fmta("\\tfrac{<>}{<>}", { i(1), i(2) })),
|
||||
|
||||
asm({ trig = "__", wordTrig = false }, fmta("_{<>}", { i(1) })),
|
||||
asm({ trig = "^^", wordTrig = false }, fmta("^{<>}", { i(1) })),
|
||||
|
||||
-- Math fonts (in this document, so they only trigger in math environments)
|
||||
-- See https://tex.stackexchange.com/questions/58098/what-are-all-the-font-styles-i-can-use-in-math-mode
|
||||
asm("rm", fmta("\\mathrm{<>}", { i(1) })),
|
||||
asm("bf", fmta("\\boldsymbol{<>}", { i(1) })),
|
||||
asm("sf", fmta("\\mathsf{<>}", { i(1) })),
|
||||
asm("it", fmta("\\mathit{<>}", { i(1) })),
|
||||
asm("tt", fmta("\\mathtt{<>}", { i(1) })),
|
||||
-- These two normally not needed, as you would define "\R = \mathbb{R}",
|
||||
-- and so on.
|
||||
-- asm("bb", fmta("\\mathbb{<>}", { i(1) })),
|
||||
asm("cal", fmta("\\mathcal{<>}", { i(1) })),
|
||||
|
||||
-- Delimeters (in math). NEED CORRESPONDING DEFINITIONS IN PREAMBLE
|
||||
asm("pp", fmta("\\lr{<>}", { i(1) })),
|
||||
asm("ss", fmta("\\lrs{<>}", { i(1) })),
|
||||
asm("cc", fmta("\\lrc{<>}", { i(1) })),
|
||||
asm("sq", fmta("\\sqrt{<>}", { i(1) })),
|
||||
}
|
||||
37
luasnippets/tex/misc.lua
Normal file
37
luasnippets/tex/misc.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
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 d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
-- local in_mathzone = function()
|
||||
-- return vim.fn["vimtex#syntax#in_mathzone"]() == 1
|
||||
-- end
|
||||
-- AutoSnippet function "as":
|
||||
local function as(trigger, nodes, opts)
|
||||
-- Only trigger commands in mathzones
|
||||
opts = opts or {}
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
if type(trigger) == "table" then
|
||||
trigger.snippetType = "autosnippet"
|
||||
else
|
||||
trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
end
|
||||
return s(trigger, nodes, opts)
|
||||
end
|
||||
|
||||
return {
|
||||
as({ trig = "{{", wordTrig = false }, fmta("{<>}", { i(1) })),
|
||||
as({ trig = "[[", wordTrig = false }, fmta("[<>]", { i(1) })),
|
||||
as({ trig = "((", wordTrig = false }, fmta("(<>)", { i(1) })),
|
||||
as({ trig = "{}", wordTrig = false }, fmta("{<>}", { i(1) })),
|
||||
as({ trig = "[]", wordTrig = false }, fmta("[<>]", { i(1) })),
|
||||
as({ trig = "()", wordTrig = false }, fmta("(<>)", { i(1) })),
|
||||
as("mm", fmta("$<>$", { i(1) })),
|
||||
as("$$", fmta("$<>$", { i(1) })),
|
||||
}
|
||||
0
luasnippets/tex/templates.lua
Normal file
0
luasnippets/tex/templates.lua
Normal file
Loading…
Add table
Add a link
Reference in a new issue