From c2c85d70eee71b335f89c1d7d6c5ebcf1b7c602d Mon Sep 17 00:00:00 2001 From: diniamo Date: Tue, 25 Jun 2024 09:23:35 +0200 Subject: [PATCH] modules/nvim-cmp: add edge case for autopairs in cr mapping --- .../autopairs/nvim-autopairs/config.nix | 3 +-- .../plugins/completion/nvim-cmp/config.nix | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/plugins/autopairs/nvim-autopairs/config.nix b/modules/plugins/autopairs/nvim-autopairs/config.nix index 4058590..4123c6a 100644 --- a/modules/plugins/autopairs/nvim-autopairs/config.nix +++ b/modules/plugins/autopairs/nvim-autopairs/config.nix @@ -4,7 +4,6 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.strings) optionalString; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; @@ -14,7 +13,7 @@ in { vim.startPlugins = ["nvim-autopairs"]; vim.luaConfigRC.autopairs = entryAnywhere '' - require("nvim-autopairs").setup{} + require("nvim-autopairs").setup({ map_cr = ${toLuaObject (!config.vim.autocomplete.enable)} }) ''; }; } diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index dcd58b1..9e27607 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -61,15 +61,19 @@ in { (mkSetLuaBinding mappings.complete '' require('cmp').complete '') - (mkSetLuaBinding mappings.confirm '' - function() - if not require('cmp').confirm({ select = true }) then - local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true) - - vim.fn.feedkeys(termcode, 'n') + (let + defaultKeys = + if config.vim.autopairs.enable + then "require('nvim-autopairs').autopairs_cr()" + else "vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)"; + in + mkSetLuaBinding mappings.confirm '' + function() + if not require('cmp').confirm({ select = true }) then + vim.fn.feedkeys(${defaultKeys}, 'n') + end end - end - '') + '') (mkSetLuaBinding mappings.next '' function() local has_words_before = function()