about summary refs log tree commit diff stats
path: root/modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-05-28 13:10:42 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-05-28 13:10:42 +0200
commitc9944e92bc1e2bff9071300b25b11642d218f424 (patch)
tree6d6f4d6ffb17381b3cabb5e52ee2b9f594c14513 /modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua
parentpkgs/mpp-searchadd: Make resistent to `beets` auto-migrations on startup (diff)
downloadnixos-config-c9944e92bc1e2bff9071300b25b11642d218f424.zip
treewide: Format
Diffstat (limited to 'modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua')
-rw-r--r--modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua182
1 files changed, 83 insertions, 99 deletions
diff --git a/modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua b/modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua
index 371f5539..8c30063e 100644
--- a/modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua
+++ b/modules/by-name/nv/nvim/plgs/luasnip/snippets/all.lua
@@ -20,21 +20,20 @@ local get_comment_string = function(comment_type)
   local utils = require("Comment.utils")
 
   -- use the `Comments.nvim` API to fetch the comment string for the region (eq. '--%s' or '--[[%s]]' for `lua`)
-  local cstring =
-    calculate_comment_string({ ctype = comment_type; range = utils.get_region(); })
+  local cstring = calculate_comment_string({ ctype = comment_type, range = utils.get_region() })
 
   if cstring == nil then
     -- TODO: Use `vim.bo.commentstring` <2025-05-02>
 
     -- Use some useful default values.
-    return { ["begin"] = "#"; ["end"] = ""; }
+    return { ["begin"] = "#", ["end"] = "" }
   end
 
   -- as we want only the strings themselves and not strings ready for using `format` we want to split the left and right side
   local left, right = utils.unwrap_cstr(cstring)
 
   -- create a `{left, right}` table for it
-  return { ["begin"] = left; ["end"] = right; }
+  return { ["begin"] = left, ["end"] = right }
 end
 
 --- Wraps a table of snippet nodes in two comment function nodes.
@@ -45,18 +44,13 @@ end
 local wrap_snippet_in_comments = function(comment_type, nodes)
   local output = {}
 
-  table.insert(output, ls.function_node(function()
-    return get_comment_string(comment_type)["begin"]
-  end))
-
+  table.insert(output, ls.function_node(function() return get_comment_string(comment_type)["begin"] end))
 
   for _, v in ipairs(nodes) do
     table.insert(output, v)
   end
 
-  table.insert(output, ls.function_node(function()
-    return get_comment_string(comment_type)["end"]
-  end))
+  table.insert(output, ls.function_node(function() return get_comment_string(comment_type)["end"] end))
 
   return output
 end
@@ -91,42 +85,36 @@ local function pair(pair_begin, pair_end, file_types, condition_function)
   -- It would be nice, if it would support both an empty array (`{}`) and nil <2023-08-27>
   -- file_types = file_types or {};
 
-  return ls.snippet(
-    {
-      trig = pair_begin;
-      wordTrig = false;
-      snippetType = "autosnippet";
-    },
-    {
-      ls.text_node({ pair_begin; });
-      ls.dynamic_node(1, get_visual);
-      ls.text_node({ pair_end; });
-    },
-    {
-      condition = function()
-        local filetype_check = true
-
-        if file_types ~= nil then
-          filetype_check = file_types[vim.bo.filetype] or false
-        end
-
-        return (not condition_function(pair_begin, pair_end)) and filetype_check
-      end;
-    }
-  )
+  return ls.snippet({
+    trig = pair_begin,
+    wordTrig = false,
+    snippetType = "autosnippet",
+  }, {
+    ls.text_node({ pair_begin }),
+    ls.dynamic_node(1, get_visual),
+    ls.text_node({ pair_end }),
+  }, {
+    condition = function()
+      local filetype_check = true
+
+      if file_types ~= nil then filetype_check = file_types[vim.bo.filetype] or false end
+
+      return (not condition_function(pair_begin, pair_end)) and filetype_check
+    end,
+  })
 end
 
 local auto_pairs = {
-  pair("(", ")", nil, char_count_same);
-  pair("{", "}", nil, char_count_same);
-  pair("[", "]", nil, char_count_same);
-  pair("<", ">", { ["rust"] = true; ["tex"] = true; }, char_count_same);
-  pair("'", "'", nil, even_count);
-  pair("\"", "\"", nil, even_count);
-  pair("`", "`", nil, even_count);
+  pair("(", ")", nil, char_count_same),
+  pair("{", "}", nil, char_count_same),
+  pair("[", "]", nil, char_count_same),
+  pair("<", ">", { ["rust"] = true, ["tex"] = true }, char_count_same),
+  pair("'", "'", nil, even_count),
+  pair("\"", "\"", nil, even_count),
+  pair("`", "`", nil, even_count),
 }
 
-ls.add_snippets("all", auto_pairs, { type = "snippets"; key = "auto_pairs"; })
+ls.add_snippets("all", auto_pairs, { type = "snippets", key = "auto_pairs" })
 -- }}}
 
 -- todo_comments {{{
@@ -134,9 +122,7 @@ local read_git_config = function(config_value)
   local command = string.format("git config \"%s\"", config_value)
 
   local handle = io.popen(command)
-  if handle == nil then
-    return error(string.format("Failed to call `%s`.", command))
-  end
+  if handle == nil then return error(string.format("Failed to call `%s`.", command)) end
 
   local result = handle:read("*a")
   handle:close()
@@ -199,14 +185,17 @@ local todo_snippet = function(trig, name, comment_type, mark_function)
 
   local date_node, signature_node = mark_function()
 
-  local nodes = fmt("{} {}{}: {} {} {}", wrap_snippet_in_comments(comment_type, {
-    ls.text_node(name);
-    signature_node;
-    ls.insert_node(1, "content");
-    date_node;
-  }))
+  local nodes = fmt(
+    "{} {}{}: {} {} {}",
+    wrap_snippet_in_comments(comment_type, {
+      ls.text_node(name),
+      signature_node,
+      ls.insert_node(1, "content"),
+      date_node,
+    })
+  )
 
-  return ls.snippet(context, nodes, { ctype = comment_type; })
+  return ls.snippet(context, nodes, { ctype = comment_type })
 end
 
 ---@param trigger string: The luasnip trigger
@@ -214,26 +203,18 @@ end
 ---@param name string: All aliases for a name
 ---@return table: All possible snippets build from the marks
 local process_marks = function(trigger, name, comment_type)
-  local username = function()
-    return handle_from_name(read_git_config("user.name"))
-  end
+  local username = function() return handle_from_name(read_git_config("user.name")) end
 
   local marks = {
-    signature = function()
-      return ls.text_node("(" .. username() .. ")"), ls.text_node("")
-    end;
+    signature = function() return ls.text_node("(" .. username() .. ")"), ls.text_node("") end,
 
     date_signature = function()
       return ls.text_node("<" .. os.date("%Y-%m-%d") .. ">"), ls.text_node("(" .. username() .. ")")
-    end;
+    end,
 
-    date = function()
-      return ls.text_node("<" .. os.date("%Y-%m-%d") .. ">"), ls.text_node("")
-    end;
+    date = function() return ls.text_node("<" .. os.date("%Y-%m-%d") .. ">"), ls.text_node("") end,
 
-    empty = function()
-      return ls.text_node(""), ls.text_node("")
-    end;
+    empty = function() return ls.text_node(""), ls.text_node("") end,
   }
 
   local output = {}
@@ -247,20 +228,20 @@ local process_marks = function(trigger, name, comment_type)
 end
 
 local todo_snippet_specs = {
-  { { trig = "todo"; };  { "TODO"; };                                     { ctype = 1; }; };
-  { { trig = "fix"; };   { "FIXME"; "ISSUE"; };                           { ctype = 1; }; };
-  { { trig = "hack"; };  { "HACK"; };                                     { ctype = 1; }; };
-  { { trig = "warn"; };  { "WARNING"; };                                  { ctype = 1; }; };
-  { { trig = "perf"; };  { "PERFORMANCE"; "OPTIMIZE"; };                  { ctype = 1; }; };
-  { { trig = "note"; };  { "NOTE"; "INFO"; };                             { ctype = 1; }; };
+  { { trig = "todo" }, { "TODO" }, { ctype = 1 } },
+  { { trig = "fix" }, { "FIXME", "ISSUE" }, { ctype = 1 } },
+  { { trig = "hack" }, { "HACK" }, { ctype = 1 } },
+  { { trig = "warn" }, { "WARNING" }, { ctype = 1 } },
+  { { trig = "perf" }, { "PERFORMANCE", "OPTIMIZE" }, { ctype = 1 } },
+  { { trig = "note" }, { "NOTE", "INFO" }, { ctype = 1 } },
 
   -- NOTE: Block commented todo-comments
-  { { trig = "todob"; }; { "TODO"; };                                     { ctype = 2; }; };
-  { { trig = "fixb"; };  { "FIXME"; "ISSUE"; };                           { ctype = 2; }; };
-  { { trig = "hackb"; }; { "HACK"; };                                     { ctype = 2; }; };
-  { { trig = "warnb"; }; { "WARNING"; };                                  { ctype = 2; }; };
-  { { trig = "perfb"; }; { "PERF"; "PERFORMANCE"; "OPTIM"; "OPTIMIZE"; }; { ctype = 2; }; };
-  { { trig = "noteb"; }; { "NOTE"; "INFO"; };                             { ctype = 2; }; };
+  { { trig = "todob" }, { "TODO" }, { ctype = 2 } },
+  { { trig = "fixb" }, { "FIXME", "ISSUE" }, { ctype = 2 } },
+  { { trig = "hackb" }, { "HACK" }, { ctype = 2 } },
+  { { trig = "warnb" }, { "WARNING" }, { ctype = 2 } },
+  { { trig = "perfb" }, { "PERF", "PERFORMANCE", "OPTIM", "OPTIMIZE" }, { ctype = 2 } },
+  { { trig = "noteb" }, { "NOTE", "INFO" }, { ctype = 2 } },
 }
 
 local todo_comment_snippets = {}
@@ -271,7 +252,7 @@ for _, v in ipairs(todo_snippet_specs) do
   end
 end
 
-ls.add_snippets("all", todo_comment_snippets, { type = "snippets"; key = "todo_comments"; })
+ls.add_snippets("all", todo_comment_snippets, { type = "snippets", key = "todo_comments" })
 -- }}}
 
 -- spdx snippets {{{
@@ -283,27 +264,30 @@ local generate_spdx_snippet = function(comment_type, spdx_license_expr, trigger)
   context.name = trigger .. " spdx snippet expr"
   context.trig = trigger
 
-
   local nodes = {
-    fmt("{} SPDX-SnippetBegin {}", wrap_snippet_in_comments(comment_type, {}));
+    fmt("{} SPDX-SnippetBegin {}", wrap_snippet_in_comments(comment_type, {})),
 
-    fmt("{} SPDX-SnippetCopyrightText: {} {} <{}> {}",
-        wrap_snippet_in_comments(comment_type, {
-          ls.insert_node(1, "year");
-          ls.insert_node(2, "author");
-          ls.insert_node(3, "email");
-        })
-    );
+    fmt(
+      "{} SPDX-SnippetCopyrightText: {} {} <{}> {}",
+      wrap_snippet_in_comments(comment_type, {
+        ls.insert_node(1, "year"),
+        ls.insert_node(2, "author"),
+        ls.insert_node(3, "email"),
+      })
+    ),
 
-    fmt("{} SPDX-License-Identifier: {} {}", wrap_snippet_in_comments(comment_type, {
-      ls.text_node(spdx_license_expr);
-    }));
+    fmt(
+      "{} SPDX-License-Identifier: {} {}",
+      wrap_snippet_in_comments(comment_type, {
+        ls.text_node(spdx_license_expr),
+      })
+    ),
 
-    { ls.insert_node(4, "content"); };
+    { ls.insert_node(4, "content") },
 
-    fmt("{} SPDX-SnippetEnd {}", wrap_snippet_in_comments(comment_type, {}));
+    fmt("{} SPDX-SnippetEnd {}", wrap_snippet_in_comments(comment_type, {})),
 
-    { ls.insert_node(0); };
+    { ls.insert_node(0) },
   }
 
   local newline_nodes = {}
@@ -313,16 +297,16 @@ local generate_spdx_snippet = function(comment_type, spdx_license_expr, trigger)
     end
 
     -- luasnip requires newlines to be encoded like this:
-    table.insert(newline_nodes, ls.text_node({ ""; ""; }))
+    table.insert(newline_nodes, ls.text_node({ "", "" }))
   end
 
-  return ls.snippet(context, newline_nodes, { ctype = comment_type; })
+  return ls.snippet(context, newline_nodes, { ctype = comment_type })
 end
 
 local spdx = {
-  { trigger = "spdx-AGPL3+"; license = "AGPL-3.0-or-later"; };
-  { trigger = "spdx-GPL3+";  license = "GPL-3.0-or-later"; };
-  { trigger = "spdx-MIT";    license = "MIT"; };
+  { trigger = "spdx-AGPL3+", license = "AGPL-3.0-or-later" },
+  { trigger = "spdx-GPL3+", license = "GPL-3.0-or-later" },
+  { trigger = "spdx-MIT", license = "MIT" },
 }
 
 local spdx_snippets = {}
@@ -334,5 +318,5 @@ for _, value in ipairs(spdx) do
   table.insert(spdx_snippets, snippet)
 end
 
-ls.add_snippets("all", spdx_snippets, { type = "snippets"; key = "spdx_snippets"; })
+ls.add_snippets("all", spdx_snippets, { type = "snippets", key = "spdx_snippets" })
 -- }}}