diff --git a/.config/nvim/lua/plugins/coding.lua b/.config/nvim/lua/plugins/coding.lua index 53e841e..71ac78c 100644 --- a/.config/nvim/lua/plugins/coding.lua +++ b/.config/nvim/lua/plugins/coding.lua @@ -1,6 +1,9 @@ return { { "L3MON4D3/LuaSnip", + opts = { + store_selection_keys = "", + }, config = function(_, opts) require("luasnip").setup(opts) diff --git a/.config/nvim/lua/snippets/fish.lua b/.config/nvim/lua/snippets/fish.lua index 5dedef3..538edc7 100644 --- a/.config/nvim/lua/snippets/fish.lua +++ b/.config/nvim/lua/snippets/fish.lua @@ -7,7 +7,7 @@ local fmt = require("luasnip.extras.fmt").fmt local fill = require("snippets.helpers").fill return { - s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "#% -" } })), + s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "#%- " } })), s({ trig = "#!", desc = "shebang" }, t("#!/usr/bin/env fish")), diff --git a/.config/nvim/lua/snippets/gitconfig.lua b/.config/nvim/lua/snippets/gitconfig.lua new file mode 100644 index 0000000..088e0ef --- /dev/null +++ b/.config/nvim/lua/snippets/gitconfig.lua @@ -0,0 +1,8 @@ +local ls = require("luasnip") +local s = ls.snippet +local f = ls.function_node +local helpers = require("snippets.helpers") + +return { + s({ trig = "dc", desc = "divider comment" }, f(helpers.fill, {}, { user_args = { "#%- " } })), +} diff --git a/.config/nvim/lua/snippets/helpers.lua b/.config/nvim/lua/snippets/helpers.lua index 30992fb..951fd61 100644 --- a/.config/nvim/lua/snippets/helpers.lua +++ b/.config/nvim/lua/snippets/helpers.lua @@ -1,13 +1,22 @@ +local ls = require("luasnip") +local sn = ls.snippet_node +local i = ls.insert_node + local M = {} -M.fill = function(_, _, args) +M.fill = function(_, parent, args) + local title = "" local chars = {} + if #parent.snippet.env.LS_SELECT_RAW > 0 then + title = print(parent.snippet.env.LS_SELECT_RAW) .. " " + end + for str in string.gmatch(args, "([^%%]+)") do table.insert(chars, str) end - local snip = chars[1] + local snip = chars[1] .. " " .. title local _, c = unpack(vim.api.nvim_win_get_cursor(0)) @@ -18,4 +27,12 @@ M.fill = function(_, _, args) return snip end +M.get_visual = function(_, parent) + if #parent.snippet.env.LS_SELECT_RAW > 0 then + return sn(nil, i(1, parent.snippet.env.LS_SELECT_RAW)) + else -- If LS_SELECT_RAW is empty, return a blank insert node + return sn(nil, i(1)) + end +end + return M diff --git a/.config/nvim/lua/snippets/lua.lua b/.config/nvim/lua/snippets/lua.lua index 99364e0..1fb0ca2 100644 --- a/.config/nvim/lua/snippets/lua.lua +++ b/.config/nvim/lua/snippets/lua.lua @@ -4,5 +4,5 @@ local f = ls.function_node local fill = require("snippets.helpers").fill return { - s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "--% --" } })), + s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "--%-- " } })), }