summaryrefslogtreecommitdiffstats
path: root/lua/Snippets
diff options
context:
space:
mode:
authorNanderty <psopka@sopka.ch>2023-03-26 16:04:40 +0200
committerNanderty <psopka@sopka.ch>2023-03-26 16:04:40 +0200
commitef44657937474145403c2b441b862035914d6a44 (patch)
treecefeca8f30c2b8b16dd7b7ed877310a0f181fba0 /lua/Snippets
parent063c2d97218cdabe0634054a8038cd6b5c9a9a12 (diff)
downloadneovim-config-ef44657937474145403c2b441b862035914d6a44.tar.gz
neovim-config-ef44657937474145403c2b441b862035914d6a44.tar.bz2
neovim-config-ef44657937474145403c2b441b862035914d6a44.zip
Snippets
Diffstat (limited to 'lua/Snippets')
-rw-r--r--lua/Snippets/luasniphelpers.lua9
-rw-r--r--lua/Snippets/luasniphelperslatex.lua26
-rw-r--r--lua/Snippets/tex/environments.lua49
-rw-r--r--lua/Snippets/tex/general.lua23
-rw-r--r--lua/Snippets/tex/greek.lua17
-rw-r--r--lua/Snippets/tex/math.lua29
6 files changed, 153 insertions, 0 deletions
diff --git a/lua/Snippets/luasniphelpers.lua b/lua/Snippets/luasniphelpers.lua
new file mode 100644
index 0000000..5aa3e44
--- /dev/null
+++ b/lua/Snippets/luasniphelpers.lua
@@ -0,0 +1,9 @@
+local M = {}
+
+local ls = require("luasnip")
+local sn = ls.snippet_node
+local i = ls.insert_node
+
+M.line_begin = require("luasnip.extras.expand_conditions").line_begin
+
+return M
diff --git a/lua/Snippets/luasniphelperslatex.lua b/lua/Snippets/luasniphelperslatex.lua
new file mode 100644
index 0000000..a31e714
--- /dev/null
+++ b/lua/Snippets/luasniphelperslatex.lua
@@ -0,0 +1,26 @@
+local M = {}
+
+M.in_mathzone = function()
+ return vim.fn['vimtex#syntax#in_mathzone']() == 1
+end
+M.in_text = function()
+ return not tex_utils.in_mathzone()
+end
+M.in_comment = function()
+ return vim.fn['vimtex#syntax#in_comment']() == 1
+end
+M.in_env = function(name)
+ local is_inside = vim.fn['vimtex#env#is_inside'](name)
+ return (is_inside[1] > 0 and is_inside[2] > 0)
+end
+M.in_equation = function()
+ return tex_utils.in_env('equation')
+end
+M.in_itemize = function()
+ return tex_utils.in_env('itemize')
+end
+M.in_tikz = function()
+ return tex_utils.in_env('tikzpicture')
+end
+
+return M
diff --git a/lua/Snippets/tex/environments.lua b/lua/Snippets/tex/environments.lua
new file mode 100644
index 0000000..fd19387
--- /dev/null
+++ b/lua/Snippets/tex/environments.lua
@@ -0,0 +1,49 @@
+local helper = require('Snippets.luasniphelpers')
+local helper = require('Snippets.luasniphelpers')
+
+return {
+ -- variable environment
+ s({ trig = 'beg', snippetType = 'autosnippet' },
+ fmta(
+ [[
+\begin{<>}
+ <>
+\end{<>}
+]],
+ {
+ i(1),
+ i(2),
+ rep(1),
+ }
+ ),
+ { condition = helper.line_begin }
+ ),
+ -- enumerate environment
+ s({ trig = 'enu', snippetType = 'autosnippet' },
+ fmta(
+ [[
+\begin{enumerate*}
+ \item <>
+\end{enumerate*}
+]],
+ {
+ i(1),
+ }
+ ),
+ { condition = helper.line_begin }
+ ),
+ -- align environment
+ s({ trig = 'ali', snippetType = 'autosnippet' },
+ fmta(
+ [[
+\begin{align*}
+ <>
+\end{align*}
+]],
+ {
+ i(1),
+ }
+ ),
+ { condition = helper.line_begin }
+ ),
+}
diff --git a/lua/Snippets/tex/general.lua b/lua/Snippets/tex/general.lua
new file mode 100644
index 0000000..ebe76fe
--- /dev/null
+++ b/lua/Snippets/tex/general.lua
@@ -0,0 +1,23 @@
+local tex = require('Snippets.luasniphelperslatex')
+local helper = require('Snippets.luasniphelpers')
+
+return {
+ s({ trig = "sec", snippetType = "autosnippet" },
+ fmta(
+ '\\section*{<>}',
+ {
+ i(1),
+ }
+ ),
+ { condition = line_begin }
+ ),
+ s({ trig = "hh", snippetType = "autosnippet" },
+ fmta(
+ '\\SI{<>}{<>}',
+ {
+ i(1),
+ i(2),
+ }
+ )
+ ),
+}
diff --git a/lua/Snippets/tex/greek.lua b/lua/Snippets/tex/greek.lua
new file mode 100644
index 0000000..f47cdac
--- /dev/null
+++ b/lua/Snippets/tex/greek.lua
@@ -0,0 +1,17 @@
+local tex = require('Snippets.luasniphelperslatex')
+local helper = require('Snippets.luasniphelpers')
+
+return {
+ s({ trig = "pi", snippetType = "autosnippet" },
+ {
+ t("\\pi"),
+ },
+ { condition = tex.in_mathzone }
+ ),
+ s({ trig = "0eps", snippetType = "autosnippet" },
+ {
+ t("\\epsilon_0"),
+ },
+ { condition = tex.in_mathzone }
+ ),
+}
diff --git a/lua/Snippets/tex/math.lua b/lua/Snippets/tex/math.lua
new file mode 100644
index 0000000..670ed80
--- /dev/null
+++ b/lua/Snippets/tex/math.lua
@@ -0,0 +1,29 @@
+local tex = require('Snippets.luasniphelperslatex')
+local helper = require('Snippets.luasniphelpers')
+
+return {
+ s({ trig = '/', snippetType = 'autosnippet' },
+ fmta(
+ '\\frac{<>}{<>}',
+ {
+ i(1),
+ i(2),
+ }
+ ),
+ { condition = tex.in_mathzone }
+ ),
+ s({ trig = "in", snippetType = "autosnippet" },
+ fmta(
+ '\\int_{<>}^{<>}',
+ {
+ i(1),
+ i(2),
+ }
+ ),
+ { condition = tex.in_mathzone }
+ ),
+ s({ trig = 'df', snippetType = 'autosnippet' },
+ { t('\\diff ') },
+ { condition = tex.in_mathzone }
+ ),
+}