From 127ed6781be7beb7f549f2741f50783a8533b393 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Wed, 25 Sep 2024 10:58:05 -0400 Subject: [PATCH] fix(tabout-nvim): make `nvim-cmp` optional and add support for `vim.snippet` --- lua/astrocommunity/motion/tabout-nvim/init.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/astrocommunity/motion/tabout-nvim/init.lua b/lua/astrocommunity/motion/tabout-nvim/init.lua index e120d979e..43d7c921f 100644 --- a/lua/astrocommunity/motion/tabout-nvim/init.lua +++ b/lua/astrocommunity/motion/tabout-nvim/init.lua @@ -1,18 +1,25 @@ return { "abecodes/tabout.nvim", event = "InsertEnter", - dependencies = { - "nvim-treesitter/nvim-treesitter", + dependencies = { "nvim-treesitter/nvim-treesitter" }, + specs = { { "hrsh7th/nvim-cmp", + optional = true, opts = function(_, opts) local cmp = require "cmp" + local snippet_jumpable = function() return vim.snippet and vim.snippet.active { direction = 1 } end + local snippet_jump = vim.schedule_wrap(function() vim.snippet.jump(1) end) local luasnip_avail, luasnip = pcall(require, "luasnip") + if luasnip_avail then + snippet_jumpable = luasnip.expand_or_jumpable + snippet_jump = luasnip.expand_or_jump + end opts.mapping[""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip_avail and luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() + elseif vim.api.nvim_get_mode() ~= "c" and snippet_jumpable() then + snippet_jump() elseif not luasnip_avail and pcall(vim.snippet.active, { direction = 1 }) then vim.snippet.jump(1) else