Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/nobbz/lua/nobbz/helpers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local M = {}

function M.git_root()
local handle = io.popen("git rev-parse --show-toplevel 2> /dev/null")
if not handle then return nil end

local result = handle:read("*a")
handle:close()

result = result:gsub("%s+$", "") -- trim trailing whitespace

if result == "" then
return nil
end

return result
end

return M
23 changes: 16 additions & 7 deletions plugins/nobbz/lua/nobbz/luasnip.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local helpers = require("nobbz.helpers")
local lualoader = require("luasnip.loaders.from_lua")
local luasnip = require("luasnip")
local select = require("luasnip.extras.select_choice")
Expand All @@ -12,12 +13,6 @@ local function cycle()
end
end

WK.add({
{ "<C-e>", luasnip.expand, desc = "expand snippet", mode = { "i", "s", }, },
{ "<C-j>", cycle, desc = "Cycle choices in node", mode = { "i", "s", }, },
{ "<C-S-j>", select, desc = "UI select choices in node", mode = { "i", "s", }, },
})

local function script_path(suffix)
local path = debug.getinfo(2, "S").source:sub(2):match("(.*/)")
if suffix then return path .. suffix end
Expand All @@ -33,6 +28,20 @@ local function list_snips()
vim.print(ft_snips)
end

WK.add({
{ "<C-e>", luasnip.expand, desc = "expand snippet", mode = { "i", "s", }, },
{ "<C-j>", cycle, desc = "Cycle choices in node", mode = { "i", "s", }, },
{ "<C-S-j>", select, desc = "UI select choices in node", mode = { "i", "s", }, },
})

vim.api.nvim_create_user_command("SnipList", list_snips, {})

lualoader.load({ paths = script_path("luasnip"), })
local git_root = helpers.git_root()
local paths = { script_path("luasnip"), }
if git_root then
vim.notify("git root: " .. git_root, vim.log.levels.INFO)
table.insert(paths, git_root .. "/snippets")
end
table.insert(paths, "~/.config/nvim/snippets")

lualoader.load({ paths = paths, })