summaryrefslogtreecommitdiff
path: root/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
commitc80a54e42b52ce297f0f2f71af23c562832025c7 (patch)
treedcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.config/TheSiahxyz/lua/thesiahxyz/snippets
init
Diffstat (limited to 'ar/.config/TheSiahxyz/lua/thesiahxyz/snippets')
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/markdown.lua187
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode1.lua103
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode2.lua104
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/quarto.lua28
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/whichkey.lua18
5 files changed, 440 insertions, 0 deletions
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/markdown.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/markdown.lua
new file mode 100644
index 0000000..7d91fab
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/markdown.lua
@@ -0,0 +1,187 @@
+local ls = require("luasnip")
+
+local s = ls.snippet
+local t = ls.text_node
+local i = ls.insert_node
+local f = ls.function_node
+
+local function clipboard()
+ return vim.fn.getreg("+")
+end
+
+-- #####################################################################
+-- Markdown
+-- #####################################################################
+
+-- Helper function to create code block snippets
+local function create_code_block_snippet(lang)
+ return s(lang, {
+ t({ "```" .. lang, "" }),
+ i(1),
+ t({ "", "```" }),
+ })
+end
+
+-- Define languages for code blocks
+local languages = {
+ "txt",
+ "lua",
+ "sql",
+ "go",
+ "regex",
+ "bash",
+ "markdown",
+ "markdown_inline",
+ "yaml",
+ "json",
+ "jsonc",
+ "cpp",
+ "csv",
+ "java",
+ "javascript",
+ "python",
+ "dockerfile",
+ "html",
+ "css",
+ "templ",
+ "php",
+}
+
+-- Generate snippets for all languages
+local snippets = {}
+
+for _, lang in ipairs(languages) do
+ table.insert(snippets, create_code_block_snippet(lang))
+end
+
+table.insert(
+ snippets,
+ s({
+ trig = "chirpy",
+ name = "Disable markdownlint and prettier for chirpy",
+ }, {
+ t({
+ " ",
+ "<!-- markdownlint-disable -->",
+ "<!-- prettier-ignore-start -->",
+ " ",
+ "<!-- tip=green, info=blue, warning=yellow, danger=red -->",
+ " ",
+ "> ",
+ }),
+ i(1),
+ t({
+ "",
+ "{: .prompt-",
+ }),
+ -- In case you want to add a default value "tip" here, but I'm having
+ -- issues with autosave
+ -- i(2, "tip"),
+ i(2),
+ t({
+ " }",
+ " ",
+ "<!-- prettier-ignore-end -->",
+ "<!-- markdownlint-restore -->",
+ }),
+ })
+)
+
+table.insert(
+ snippets,
+ s({
+ trig = "markdownlint",
+ name = "Add markdownlint disable and restore headings",
+ }, {
+ t({
+ " ",
+ "<!-- markdownlint-disable -->",
+ " ",
+ "> ",
+ }),
+ i(1),
+ t({
+ " ",
+ " ",
+ "<!-- markdownlint-restore -->",
+ }),
+ })
+)
+
+table.insert(
+ snippets,
+ s({
+ trig = "prettierignore",
+ name = "Add prettier ignore start and end headings",
+ }, {
+ t({
+ " ",
+ "<!-- prettier-ignore-start -->",
+ " ",
+ "> ",
+ }),
+ i(1),
+ t({
+ " ",
+ " ",
+ "<!-- prettier-ignore-end -->",
+ }),
+ })
+)
+
+table.insert(
+ snippets,
+ s({
+ trig = "link",
+ name = "Add this -> []()",
+ }, {
+ t("["),
+ i(1),
+ t("]("),
+ i(2),
+ t(")"),
+ })
+)
+
+table.insert(
+ snippets,
+ s({
+ trig = "linkt",
+ name = 'Add this -> [](){:target="_blank"}',
+ }, {
+ t("["),
+ i(1),
+ t("]("),
+ i(2),
+ t('){:target="_blank"}'),
+ })
+)
+
+table.insert(
+ snippets,
+ s({
+ trig = "todo",
+ name = "Add TODO: item",
+ }, {
+ t("<!-- TODO: "),
+ i(1),
+ t(" -->"),
+ })
+)
+
+-- Paste clipboard contents in link section, move cursor to ()
+table.insert(
+ snippets,
+ s({
+ trig = "linkclip",
+ name = "Paste clipboard as .md link",
+ }, {
+ t("["),
+ i(1),
+ t("]("),
+ f(clipboard, {}),
+ t(")"),
+ })
+)
+
+ls.add_snippets("markdown", snippets)
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode1.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode1.lua
new file mode 100644
index 0000000..85da742
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode1.lua
@@ -0,0 +1,103 @@
+local ls = require("luasnip")
+local s = ls.snippet
+local i = ls.insert_node
+local fmt = require("luasnip.extras.fmt").fmt
+local rep = require("luasnip.extras").rep
+local f = ls.function_node -- Import function_node for dynamic content
+
+-- Function to get the filename without the path
+local function get_filename()
+ local filepath = vim.api.nvim_buf_get_name(0)
+ local filename = vim.fn.fnamemodify(filepath, ":t:r") -- Get filename without path and extension
+ return filename:gsub("_", " ") -- Replace underscores with spaces
+end
+
+local neetcode_snippet = s(
+ "neetcode",
+ fmt(
+ [[
+"""
+Question
+
+{1}
+"""
+
+
+from typing import Dict
+
+class Solution:
+ """
+ A class to solve {file_name} from {2}
+ """
+ def {3}(self, {4}) -> {5}:
+ """
+ {file_name} from the input {parameters_type} using a {func_name} approach.
+
+ Args:
+ {parameters_type}: {6}
+
+ Returns:
+ {return_type}: {7}
+ """
+ return {8}
+
+ def print(self, examples: Dict[str, {parameters_type}]) -> None:
+ for name, example in examples.items():
+ result = self.{3}(example)
+ print(f"{{name}}: {{result}}")
+
+ def main(self):
+ cases = {{
+ "case1" : {9},
+ "case2" : {10},
+ "case3" : {11},
+ }}
+
+ self.print(cases)
+
+
+solution = Solution()
+solution.main()
+
+"""
+Solution
+
+url: {12}
+video: {13}
+
+1. {func_name}
+time: {14}
+space: {15}
+code:
+```python
+{16}
+```
+"""
+]],
+ {
+ i(1, '"Describe the question here"'),
+ file_name = f(get_filename), -- Insert the filename dynamicall
+ i(2, '"Describe the class here"'),
+ i(3, '"Function name"'), -- Primary insert node for method name
+ func_name = rep(3), -- Repeat the method name
+ i(4, '"parameters"'),
+ parameters_type = rep(4),
+ i(5, '"return_type"'),
+ return_type = rep(5),
+ i(6, '"parameters_desc"'),
+ i(7, '"return_type_desc"'),
+ i(8, '"return"'),
+ i(9, '"case1"'),
+ i(10, '"case2"'),
+ i(11, '"case3"'),
+ i(12, '"url"'),
+ i(13, '"video"'),
+ i(14, '"time_complexity"'),
+ i(15, '"space_complexity"'),
+ i(16, '"code"'),
+ }
+ )
+)
+
+-- Add the snippets for multiple filetypes
+ls.add_snippets("python", { neetcode_snippet })
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode2.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode2.lua
new file mode 100644
index 0000000..98e7258
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/neetcode2.lua
@@ -0,0 +1,104 @@
+local ls = require("luasnip")
+local s = ls.snippet
+local i = ls.insert_node
+local fmt = require("luasnip.extras.fmt").fmt
+local rep = require("luasnip.extras").rep
+local f = ls.function_node -- Import function_node for dynamic content
+
+-- Function to get the filename without the path
+local function get_filename()
+ local filepath = vim.api.nvim_buf_get_name(0)
+ local filename = vim.fn.fnamemodify(filepath, ":t:r") -- Get filename without path and extension
+ return filename:gsub("_", " ") -- Replace underscores with spaces
+end
+
+local neetcode_snippet = s(
+ "neetcode",
+ fmt(
+ [[
+"""
+Question
+
+{1}
+"""
+
+
+from typing import Dict
+
+class Solution:
+ """
+ A class to solve {file_name} from {2}
+ """
+ def {3}(self, {4}) -> {5}:
+ """
+ {file_name} from the input {parameters_type} using a {func_name} approach.
+
+ Args:
+ {parameters_type}: {6}
+
+ Returns:
+ {return_type}: {7}
+ """
+ return {8}
+
+ def print(self, examples: Dict[str, {parameters_type}]) -> None:
+ for name, (param1, param2) in examples.items():
+ result = self.{3}(param1, param2)
+ print(f"{{name}}: {{result}}")
+
+ def main(self):
+ cases = {{
+ "case1" : ({9}),
+ "case2" : ({10}),
+ "case3" : ({11}),
+ }}
+
+ self.print(cases)
+
+
+
+solution = Solution()
+solution.main()
+
+"""
+Solution
+
+url: {12}
+video: {13}
+
+1. {func_name}
+time: {14}
+space: {15}
+code:
+```python
+{16}
+```
+"""
+]],
+ {
+ i(1, '"Describe the question here"'),
+ file_name = f(get_filename), -- Insert the filename dynamicall
+ i(2, '"Describe the class here"'),
+ i(3, '"Function name"'), -- Primary insert node for method name
+ func_name = rep(3), -- Repeat the method name
+ i(4, '"parameters"'),
+ parameters_type = rep(4),
+ i(5, '"return_type"'),
+ return_type = rep(5),
+ i(6, '"parameters_desc"'),
+ i(7, '"return_type_desc"'),
+ i(8, '"return"'),
+ i(9, '"case1"'),
+ i(10, '"case2"'),
+ i(11, '"case3"'),
+ i(12, '"url"'),
+ i(13, '"video"'),
+ i(14, '"time_complexity"'),
+ i(15, '"space_complexity"'),
+ i(16, '"code"'),
+ }
+ )
+)
+
+-- Add the snippets for multiple filetypes
+ls.add_snippets("python", { neetcode_snippet })
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/quarto.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/quarto.lua
new file mode 100644
index 0000000..74b9fb8
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/quarto.lua
@@ -0,0 +1,28 @@
+local ls = require("luasnip")
+
+local s = ls.snippet
+local i = ls.insert_node
+local t = ls.text_node
+-- local d = ls.dynamic_node
+local c = ls.choice_node
+-- local f = ls.function_node
+-- local r = ls.restore_node
+local fmt = require("luasnip.extras.fmt").fmta
+-- local h = require("thesiahxyz.utils.snippet")
+
+local code_cell_snippet = s(
+ "`",
+ fmt(
+ [[```<lang>
+<last>
+``]],
+ {
+ lang = c(1, { t("python"), t("") }),
+ last = i(0), -- Place cursor here after expanding the snippet
+ }
+ )
+)
+
+-- Add the snippets for multiple filetypes
+ls.add_snippets("markdown", { code_cell_snippet })
+ls.add_snippets("quarto", { code_cell_snippet })
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/whichkey.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/whichkey.lua
new file mode 100644
index 0000000..fab5853
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/snippets/whichkey.lua
@@ -0,0 +1,18 @@
+local ls = require("luasnip")
+
+-- Using parse_snippet instead of fmt to avoid curly brace issues
+local whichkey_snippet = ls.parser.parse_snippet(
+ "whichkey",
+ [[
+init = function()
+ local wk = require("which-key")
+ wk.add({
+ mode = { "n" },
+ { "${1:Key}", group = "${2:Name}" },
+ })
+end,
+]]
+)
+
+-- Add the snippets for the Lua filetype
+ls.add_snippets("lua", { whichkey_snippet })