about summary refs log tree commit diff stats
path: root/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-08-26 22:52:12 +0200
committerSoispha <soispha@vhack.eu>2023-08-26 22:56:09 +0200
commit4c743a2afb87994be4ff7c2dc76d21c70d31e4de (patch)
tree70922dd5db390641da012085bc674333b53d2ef1 /home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets
parentFix(hm/conf/neovim/plugins/colorscheme): Mk todo,fix,&c comments visible (diff)
downloadnixos-config-4c743a2afb87994be4ff7c2dc76d21c70d31e4de.zip
Style(treewide): Format all lua-files makes lua ➛ nix easier
The files were formatted according to the `.editorconfig` file and with
the formatter from [this](1) repo, as it's the only one that fully
understands all keys in the `.editorconfig` file.

The formatting was chosen in this special (and honestly unconventional)
way because moving code from lua to nix is now easier, as the syntax is
nearly identical in some places.
Diffstat (limited to 'home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets')
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/all.lua66
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/html/html.lua139
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/delimiter.lua47
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/greek.lua173
4 files changed, 165 insertions, 260 deletions
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/all.lua b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/all.lua
index cfb75a68..5ce91a87 100644
--- a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/all.lua
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/all.lua
@@ -1,57 +1,59 @@
 local get_visual = function(args, parent)
-    if (#parent.snippet.env.SELECT_RAW > 0) then
-        return sn(nil, i(1, parent.snippet.env.SELECT_RAW))
-    else
-        return sn(nil, i(1, ''))
-    end
+  if #parent.snippet.env.SELECT_RAW > 0 then
+    return sn(nil, i(1, parent.snippet.env.SELECT_RAW))
+  else
+    return sn(nil, i(1, ""))
+  end
 end
 local function char_count_same(c1, c2)
-    local line = vim.api.nvim_get_current_line()
-    -- '%'-escape chars to force explicit match (gsub accepts patterns).
-    -- second return value is number of substitutions.
-    local _, ct1 = string.gsub(line, '%' .. c1, '')
-    local _, ct2 = string.gsub(line, '%' .. c2, '')
-    return ct1 == ct2
+  local line = vim.api.nvim_get_current_line()
+  -- '%'-escape chars to force explicit match (gsub accepts patterns).
+  -- second return value is number of substitutions.
+  local _, ct1 = string.gsub(line, "%" .. c1, "")
+  local _, ct2 = string.gsub(line, "%" .. c2, "")
+  return ct1 == ct2
 end
 
 local function even_count(c)
-    local line = vim.api.nvim_get_current_line()
-    local _, ct = string.gsub(line, c, '')
-    return ct % 2 == 0
+  local line = vim.api.nvim_get_current_line()
+  local _, ct = string.gsub(line, c, "")
+  return ct % 2 == 0
 end
 
 local function neg(fn, ...)
-    return not fn(...)
+  return not fn(...)
 end
 
 local function part(fn, ...)
-    local args = { ... }
-    return function() return fn(unpack(args)) end
+  local args = { ...; }
+  return function()
+    return fn(unpack(args))
+  end
 end
 
 -- This makes creation of pair-type snippets easier.
 local function pair(pair_begin, pair_end, expand_func, ...)
-    -- triggerd by opening part of pair, wordTrig=false to trigger anywhere.
-    -- ... is used to pass any args following the expand_func to it.
-    return s({ trig = pair_begin, wordTrig = false, snippetType = "autosnippet" }, {
-        t({ pair_begin }), d(1, get_visual), t({ pair_end })
-    }, {
-        condition = part(expand_func, part(..., pair_begin, pair_end))
-    })
+  -- triggerd by opening part of pair, wordTrig=false to trigger anywhere.
+  -- ... is used to pass any args following the expand_func to it.
+  return s(
+    { trig = pair_begin; wordTrig = false; snippetType = "autosnippet"; },
+    { t({ pair_begin; }); d(1, get_visual); t({ pair_end; }); },
+    { condition = part(expand_func, part(..., pair_begin, pair_end)); }
+  )
 end
 
-local maybe = { pair = nil };
+local maybe = { pair = nil; }
 if vim.bo.filetype == "tex" then
-    maybe.pair = pair("<", ">", neg, char_count_same)
+  maybe.pair = pair("<", ">", neg, char_count_same)
 end
 
 local output_table = {
-    pair("(", ")", neg, char_count_same),
-    pair("{", "}", neg, char_count_same),
-    pair("[", "]", neg, char_count_same),
-    pair("'", "'", neg, even_count),
-    pair('"', '"', neg, even_count),
-    pair("`", "`", neg, even_count),
+  pair("(", ")", neg, char_count_same);
+  pair("{", "}", neg, char_count_same);
+  pair("[", "]", neg, char_count_same);
+  pair("'", "'", neg, even_count);
+  pair('"', '"', neg, even_count);
+  pair("`", "`", neg, even_count);
 }
 output_table[#output_table + 1] = maybe.pair
 
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/html/html.lua b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/html/html.lua
index df42314b..c467dd68 100644
--- a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/html/html.lua
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/html/html.lua
@@ -1,5 +1,5 @@
 local get_visual = function(args, parent)
-  if (#parent.snippet.env.SELECT_RAW > 0) then
+  if #parent.snippet.env.SELECT_RAW > 0 then
     return sn(nil, i(1, parent.snippet.env.SELECT_RAW))
   else
     return sn(nil, i(1))
@@ -8,65 +8,68 @@ end
 
 local line_begin = require("luasnip.extras.expand_conditions").line_begin
 
-return
-  {
-    -- HEADER
-    s({trig="h([123456])", regTrig=true, wordTrig=false, snippetType="autosnippet"},
-      fmt(
-        [[
+return {
+  -- HEADER
+  s(
+    {
+      trig = "h([123456])";
+      regTrig = true;
+      wordTrig = false;
+      snippetType = "autosnippet";
+    },
+    fmt(
+      [[
           <h{}>{}</h{}>
         ]],
-        {
-          f( function(_, snip) return snip.captures[1] end ),
-          d(1, get_visual),
-          f( function(_, snip) return snip.captures[1] end ),
-        }
-      ),
-      {condition = line_begin}
+      {
+        f(function(_, snip)
+          return snip.captures[1]
+        end);
+        d(1, get_visual);
+        f(function(_, snip)
+          return snip.captures[1]
+        end);
+      }
     ),
-    -- PARAGRAPH
-    s({trig="pp", snippetType="autosnippet"},
-      fmt(
-        [[
+    { condition = line_begin; }
+  ); -- PARAGRAPH
+  s(
+    { trig = "pp"; snippetType = "autosnippet"; },
+    fmt(
+      [[
           <p>{}</p>
         ]],
-        {
-          d(1, get_visual),
-        }
-      ),
-      {condition = line_begin}
+      { d(1, get_visual); }
     ),
-    -- UNORDERED LIST
-    s({trig="itt", snippetType="autosnippet"},
-      fmt(
-        [[
+    { condition = line_begin; }
+  ); -- UNORDERED LIST
+  s(
+    { trig = "itt"; snippetType = "autosnippet"; },
+    fmt(
+      [[
           <ul>
             <li>{}</li>{}
           </ul>
         ]],
-        {
-          i(1),
-          i(0)
-        }
-      ),
-      {condition = line_begin}
+      { i(1); i(0); }
     ),
-    -- LIST ITEM
-    s({trig="ii", snippetType="autosnippet"},
-      fmt(
-        [[
+    { condition = line_begin; }
+  ); -- LIST ITEM
+  s(
+    { trig = "ii"; snippetType = "autosnippet"; },
+    fmt(
+      [[
             <li>{}</li>
         ]],
-        {
-          d(1, get_visual),
-        }
-      ),
-      {condition = line_begin}
+      { d(1, get_visual); }
     ),
-    -- DOCUMENT TEMPLATE
-    s({trig="base"},
-      fmt(
-        [[
+    { condition = line_begin; }
+  );
+  -- DOCUMENT TEMPLATE
+  s(
+    { trig = "base"; },
+    fmt(
+      [[
         <!doctype HTML>
         <html lang="en">
         <head>
@@ -78,28 +81,28 @@ return
         </body>
         </html>
         ]],
-        {
-          i(1, "FooBar"),
-          i(0)
-        }
-      ),
-      {condition = line_begin}
+      { i(1, "FooBar"); i(0); }
     ),
-    -- ANCHOR TAG
-    s({trig = "([^%l])aa", regTrig = true, wordTrig = false, snippetType="autosnippet"},
-      fmt(
-        [[
+    { condition = line_begin; }
+  ); -- ANCHOR TAG
+  s(
+    {
+      trig = "([^%l])aa";
+      regTrig = true;
+      wordTrig = false;
+      snippetType = "autosnippet";
+    },
+    fmt(
+      [[
           {}<a href="{}">{}</a>
         ]],
-        {
-          f( function(_, snip) return snip.captures[1] end ),
-          i(1),
-          d(2, get_visual),
-        }
-      )
-    ),
-  }
-
-
-
-
+      {
+        f(function(_, snip)
+          return snip.captures[1]
+        end);
+        i(1);
+        d(2, get_visual);
+      }
+    )
+  );
+}
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/delimiter.lua b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/delimiter.lua
index 2e11d43d..e50898fc 100644
--- a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/delimiter.lua
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/delimiter.lua
@@ -1,31 +1,34 @@
 local get_visual = function(args, parent)
-  if (#parent.snippet.env.SELECT_RAW > 0) then
+  if #parent.snippet.env.SELECT_RAW > 0 then
     return sn(nil, i(1, parent.snippet.env.SELECT_RAW))
   else
-    return sn(nil, i(1, ''))
+    return sn(nil, i(1, ""))
   end
 end
 
-local translation_table = {
-    ["("] = ")",
-    ["{"] = "}",
-    ["["] = "]",
-}
+local translation_table = { ["("] = ")"; ["{"] = "}"; ["["] = "]"; }
 
 -- Return snippet tables
-return
-{
-   -- LEFT/RIGHT ALL BRACES
-   s({trig = "([^%a])l([%(%[%{])", regTrig = true, wordTrig = false, snippetType="autosnippet"},
-     fmta(
-       "<>\\left<><>\\right<>",
-       {
-         f( function(_, snip) return snip.captures[1] end ),
-         f( function(_, snip) return snip.captures[2] end ),
-         d(1, get_visual),
-         f( function(_, snip) return translation_table[snip.captures[2]] end ),
-       }
-     )
-   ),
+return {
+  -- LEFT/RIGHT ALL BRACES
+  s(
+    {
+      trig = "([^%a])l([%(%[%{])";
+      regTrig = true;
+      wordTrig = false;
+      snippetType = "autosnippet";
+    },
+    fmta("<>\\left<><>\\right<>", {
+      f(function(_, snip)
+        return snip.captures[1]
+      end);
+      f(function(_, snip)
+        return snip.captures[2]
+      end);
+      d(1, get_visual);
+      f(function(_, snip)
+        return translation_table[snip.captures[2]]
+      end);
+    })
+  );
 }
-
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/greek.lua b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/greek.lua
index 419e47ef..19989093 100644
--- a/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/greek.lua
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/luasnip/lua/snippets/tex/greek.lua
@@ -1,140 +1,37 @@
 -- Return snippet tables
-return
-{
-  s({trig=";a", snippetType="autosnippet"},
-    {
-      t("\\alpha"),
-  }),
-  s({trig=";b", snippetType="autosnippet"},
-    {
-      t("\\beta"),
-  }),
-  s({trig=";g", snippetType="autosnippet"},
-    {
-      t("\\gamma"),
-  }),
-  s({trig=";G", snippetType="autosnippet"},
-    {
-      t("\\Gamma"),
-  }),
-  s({trig=";d", snippetType="autosnippet"},
-    {
-      t("\\delta"),
-  }),
-  s({trig=";D", snippetType="autosnippet"},
-    {
-      t("\\Delta"),
-  }),
-  s({trig=";e", snippetType="autosnippet"},
-    {
-      t("\\epsilon"),
-  }),
-  s({trig=";ve", snippetType="autosnippet"},
-    {
-      t("\\varepsilon"),
-  }),
-  s({trig=";z", snippetType="autosnippet"},
-    {
-      t("\\zeta"),
-  }),
-  s({trig=";h", snippetType="autosnippet"},
-    {
-      t("\\eta"),
-  }),
-  s({trig=";o", snippetType="autosnippet"},
-    {
-      t("\\theta"),
-  }),
-  s({trig=";vo", snippetType="autosnippet"},
-    {
-      t("\\vartheta"),
-  }),
-  s({trig=";O", snippetType="autosnippet"},
-    {
-      t("\\Theta"),
-  }),
-  s({trig=";k", snippetType="autosnippet"},
-    {
-      t("\\kappa"),
-  }),
-  s({trig=";l", snippetType="autosnippet"},
-    {
-      t("\\lambda"),
-  }),
-  s({trig=";L", snippetType="autosnippet"},
-    {
-      t("\\Lambda"),
-  }),
-  s({trig=";m", snippetType="autosnippet"},
-    {
-      t("\\mu"),
-  }),
-  s({trig=";n", snippetType="autosnippet"},
-    {
-      t("\\nu"),
-  }),
-  s({trig=";x", snippetType="autosnippet"},
-    {
-      t("\\xi"),
-  }),
-  s({trig=";X", snippetType="autosnippet"},
-    {
-      t("\\Xi"),
-  }),
-  s({trig=";i", snippetType="autosnippet"},
-    {
-      t("\\pi"),
-  }),
-  s({trig=";I", snippetType="autosnippet"},
-    {
-      t("\\Pi"),
-  }),
-  s({trig=";r", snippetType="autosnippet"},
-    {
-      t("\\rho"),
-  }),
-  s({trig=";s", snippetType="autosnippet"},
-    {
-      t("\\sigma"),
-  }),
-  s({trig=";S", snippetType="autosnippet"},
-    {
-      t("\\Sigma"),
-  }),
-  s({trig=";t", snippetType="autosnippet"},
-    {
-      t("\\tau"),
-  }),
-  s({trig=";f", snippetType="autosnippet"},
-    {
-      t("\\phi"),
-  }),
-  s({trig=";vf", snippetType="autosnippet"},
-    {
-      t("\\varphi"),
-  }),
-  s({trig=";F", snippetType="autosnippet"},
-    {
-      t("\\Phi"),
-  }),
-  s({trig=";c", snippetType="autosnippet"},
-    {
-      t("\\chi"),
-  }),
-  s({trig=";p", snippetType="autosnippet"},
-    {
-      t("\\psi"),
-  }),
-  s({trig=";P", snippetType="autosnippet"},
-    {
-      t("\\Psi"),
-  }),
-  s({trig=";w", snippetType="autosnippet"},
-    {
-      t("\\omega"),
-  }),
-  s({trig=";W", snippetType="autosnippet"},
-    {
-      t("\\Omega"),
-  }),
+return {
+  s({ trig = ";a"; snippetType = "autosnippet"; }, { t("\\alpha"); });
+  s({ trig = ";b"; snippetType = "autosnippet"; }, { t("\\beta"); });
+  s({ trig = ";g"; snippetType = "autosnippet"; }, { t("\\gamma"); });
+  s({ trig = ";G"; snippetType = "autosnippet"; }, { t("\\Gamma"); });
+  s({ trig = ";d"; snippetType = "autosnippet"; }, { t("\\delta"); });
+  s({ trig = ";D"; snippetType = "autosnippet"; }, { t("\\Delta"); });
+  s({ trig = ";e"; snippetType = "autosnippet"; }, { t("\\epsilon"); });
+  s({ trig = ";ve"; snippetType = "autosnippet"; }, { t("\\varepsilon"); });
+  s({ trig = ";z"; snippetType = "autosnippet"; }, { t("\\zeta"); });
+  s({ trig = ";h"; snippetType = "autosnippet"; }, { t("\\eta"); });
+  s({ trig = ";o"; snippetType = "autosnippet"; }, { t("\\theta"); });
+  s({ trig = ";vo"; snippetType = "autosnippet"; }, { t("\\vartheta"); });
+  s({ trig = ";O"; snippetType = "autosnippet"; }, { t("\\Theta"); });
+  s({ trig = ";k"; snippetType = "autosnippet"; }, { t("\\kappa"); });
+  s({ trig = ";l"; snippetType = "autosnippet"; }, { t("\\lambda"); });
+  s({ trig = ";L"; snippetType = "autosnippet"; }, { t("\\Lambda"); });
+  s({ trig = ";m"; snippetType = "autosnippet"; }, { t("\\mu"); });
+  s({ trig = ";n"; snippetType = "autosnippet"; }, { t("\\nu"); });
+  s({ trig = ";x"; snippetType = "autosnippet"; }, { t("\\xi"); });
+  s({ trig = ";X"; snippetType = "autosnippet"; }, { t("\\Xi"); });
+  s({ trig = ";i"; snippetType = "autosnippet"; }, { t("\\pi"); });
+  s({ trig = ";I"; snippetType = "autosnippet"; }, { t("\\Pi"); });
+  s({ trig = ";r"; snippetType = "autosnippet"; }, { t("\\rho"); });
+  s({ trig = ";s"; snippetType = "autosnippet"; }, { t("\\sigma"); });
+  s({ trig = ";S"; snippetType = "autosnippet"; }, { t("\\Sigma"); });
+  s({ trig = ";t"; snippetType = "autosnippet"; }, { t("\\tau"); });
+  s({ trig = ";f"; snippetType = "autosnippet"; }, { t("\\phi"); });
+  s({ trig = ";vf"; snippetType = "autosnippet"; }, { t("\\varphi"); });
+  s({ trig = ";F"; snippetType = "autosnippet"; }, { t("\\Phi"); });
+  s({ trig = ";c"; snippetType = "autosnippet"; }, { t("\\chi"); });
+  s({ trig = ";p"; snippetType = "autosnippet"; }, { t("\\psi"); });
+  s({ trig = ";P"; snippetType = "autosnippet"; }, { t("\\Psi"); });
+  s({ trig = ";w"; snippetType = "autosnippet"; }, { t("\\omega"); });
+  s({ trig = ";W"; snippetType = "autosnippet"; }, { t("\\Omega"); });
 }