From 7d1e8075b8f156f3f8c300326abf730a1a8f2875 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 31 May 2021 22:20:30 +0200 Subject: Copying of Luke's dots --- .config/nvim/lua/_autopairs/init.lua | 100 ++++++++++++----------------------- 1 file changed, 34 insertions(+), 66 deletions(-) (limited to '.config/nvim/lua/_autopairs') diff --git a/.config/nvim/lua/_autopairs/init.lua b/.config/nvim/lua/_autopairs/init.lua index 5d0adf8..d9caf22 100644 --- a/.config/nvim/lua/_autopairs/init.lua +++ b/.config/nvim/lua/_autopairs/init.lua @@ -1,77 +1,45 @@ -require('nvim-autopairs').setup() +local remap = vim.api.nvim_set_keymap local npairs = require('nvim-autopairs') +local Rule = require('nvim-autopairs.rule') -local function imap(lhs, rhs, opts) - local options = {noremap = false} - if opts then options = vim.tbl_extend('force', options, opts) end - vim.api.nvim_set_keymap('i', lhs, rhs, options) -end - -_G.MUtils = {} +-- skip it, if you use another global object +_G.MUtils= {} --- TEST vim.g.completion_confirm_key = "" -MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - vim.fn["compe#confirm"]() - -- return npairs.esc("") - return npairs.esc("") - else - vim.defer_fn(function() - vim.fn["compe#confirm"]("") - end, 20) - return npairs.esc("") - end +MUtils.completion_confirm=function() + if vim.fn.pumvisible() ~= 0 then + if vim.fn.complete_info()["selected"] ~= -1 then + return vim.fn["compe#confirm"](npairs.esc("")) else - return npairs.check_break_line_char() + return npairs.esc("") end + else + return npairs.autopairs_cr() + end end --- TEST -MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - vim.fn["compe#confirm"]() - return npairs.esc("") - else - vim.api.nvim_select_popupmenu_item(0, false, false, {}) - vim.fn["compe#confirm"]() - return npairs.esc("") - end - else - return npairs.check_break_line_char() - end -end -MUtils.tab = function() - if vim.fn.pumvisible() ~= 0 then - return npairs.esc("") - else - if vim.fn["vsnip#available"](1) ~= 0 then - vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83)) - return npairs.esc("") - else - return npairs.esc("") - end - end -end +remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) -MUtils.s_tab = function() - if vim.fn.pumvisible() ~= 0 then - return npairs.esc("") - else - if vim.fn["vsnip#jumpable"](-1) ~= 0 then - vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83)) - return npairs.esc("") - else - return npairs.esc("") - end - end -end +npairs.setup({ + check_ts = true, + ts_config = { + lua = {'string'},-- it will not add pair on that treesitter node + javascript = {'template_string'}, + java = false,-- don't check treesitter on java + } +}) + +require('nvim-treesitter.configs').setup { + autopairs = {enable = true} +} + +local ts_conds = require('nvim-autopairs.ts-conds') --- Autocompletion and snippets -vim.api.nvim_set_keymap('i', '', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true}) --- imap("", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true}) -imap("", "v:lua.MUtils.tab()", {expr = true, noremap = true}) -imap("", "v:lua.MUtils.s_tab()", {expr = true, noremap = true}) +-- press % => %% is only inside comment or string +npairs.add_rules({ + Rule("%", "%", "lua") + :with_pair(ts_conds.is_ts_node({'string','comment'})), + Rule("$", "$", "lua") + :with_pair(ts_conds.is_not_ts_node({'function'})) +}) -- cgit v1.2.3-70-g09d2