From 36c316b53476fff406db292a54f3c88b07b4b944 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 26 Aug 2024 11:07:42 +0200 Subject: nvim: add lua snippets A year later... https://git.yigitsever.com/personal/dotfiles/commit/.config/nvim/my_snippets?id=387e08c52d9752bc839c71119f140ba8435c3d70 --- .config/nvim/lua/luasnippets/PKGBUILD.lua | 36 +++++++++++++++++++ .config/nvim/lua/luasnippets/mail.lua | 36 +++++++++++++++++++ .config/nvim/lua/luasnippets/vimwiki.lua | 60 +++++++++++++++++++++++++++++++ .config/nvim/lua/plugins/cmp.lua | 1 + 4 files changed, 133 insertions(+) create mode 100644 .config/nvim/lua/luasnippets/PKGBUILD.lua create mode 100644 .config/nvim/lua/luasnippets/mail.lua create mode 100644 .config/nvim/lua/luasnippets/vimwiki.lua diff --git a/.config/nvim/lua/luasnippets/PKGBUILD.lua b/.config/nvim/lua/luasnippets/PKGBUILD.lua new file mode 100644 index 0000000..334baf1 --- /dev/null +++ b/.config/nvim/lua/luasnippets/PKGBUILD.lua @@ -0,0 +1,36 @@ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key +local strftime = vim.fn.strftime + +return { + s("m", + { + t("# Maintainer: Yigit Sever ") + } + ) +} diff --git a/.config/nvim/lua/luasnippets/mail.lua b/.config/nvim/lua/luasnippets/mail.lua new file mode 100644 index 0000000..3d60baa --- /dev/null +++ b/.config/nvim/lua/luasnippets/mail.lua @@ -0,0 +1,36 @@ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key +local strftime = vim.fn.strftime + +return { + s("~", + { + t("~yigit") + } + ) +} diff --git a/.config/nvim/lua/luasnippets/vimwiki.lua b/.config/nvim/lua/luasnippets/vimwiki.lua new file mode 100644 index 0000000..c5e8532 --- /dev/null +++ b/.config/nvim/lua/luasnippets/vimwiki.lua @@ -0,0 +1,60 @@ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key +local strftime = vim.fn.strftime + +local function clipboard() + local text = vim.fn.system({ 'wl-paste' }) + local output = string.gsub(text, "^%s*(.-)%s*$", "%1") + return output +end + +return { + s("datasrc", + { + t({ "= " }), i(1), t({ " =", "" }), + t({ "", "== Used By ==", "" }), i(2), + t({ "", "== URL ==", "" }), i(3), + t({ "", "== API ==", "" }), i(4), + t({ "", "=== Example ===", "" }), i(5), + t({ "", "== Cost ==", "" }), i(6), + t({ "", "== Limits ==", "" }), i(0), + } + ), + s("s", + { + t({ "- (" }), + t({ strftime("%F %R") }), + t({ ") " }), + i(1, clipboard()), + t({ " -- " }), + i(2, "Summary") + + } + ) +} + diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 884e778..8e34264 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -176,6 +176,7 @@ return { -- To enable auto expansion enable_autosnippets = true, }) + require("luasnip.loaders.from_lua").lazy_load({ paths = "./lua/luasnippets" }) end }, -- cgit v1.2.3-70-g09d2