From 80b53645cbec7a5f00ebe2d22aebbbf5618d6c53 Mon Sep 17 00:00:00 2001 From: punkfairie <23287005+punkfairie@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:28:09 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(nvim):=20Tweak=20dc=20snippet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/nvim/lua/plugins/coding.lua | 3 +++ .config/nvim/lua/snippets/fish.lua | 2 +- .config/nvim/lua/snippets/gitconfig.lua | 8 ++++++++ .config/nvim/lua/snippets/helpers.lua | 21 +++++++++++++++++++-- .config/nvim/lua/snippets/lua.lua | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .config/nvim/lua/snippets/gitconfig.lua 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 = { "--%-- " } })), }