summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/autopairs.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/core/autopairs.lua')
-rw-r--r--.config/nvim/lua/core/autopairs.lua52
1 files changed, 30 insertions, 22 deletions
diff --git a/.config/nvim/lua/core/autopairs.lua b/.config/nvim/lua/core/autopairs.lua
index f8bdfd1..8ea3094 100644
--- a/.config/nvim/lua/core/autopairs.lua
+++ b/.config/nvim/lua/core/autopairs.lua
@@ -20,36 +20,44 @@ function M.config()
end
M.setup = function()
- -- skip it, if you use another global object
- _G.MUtils = {}
local autopairs = require "nvim-autopairs"
local Rule = require "nvim-autopairs.rule"
-
- vim.g.completion_confirm_key = ""
- MUtils.completion_confirm = function()
- if vim.fn.pumvisible() ~= 0 then
- if vim.fn.complete_info()["selected"] ~= -1 then
- return vim.fn["compe#confirm"](autopairs.esc "<cr>")
- else
- return autopairs.esc "<cr>"
- end
- else
- return autopairs.autopairs_cr()
- end
- end
-
- if package.loaded["compe"] then
- require("nvim-autopairs.completion.compe").setup {
- map_cr = options.builtin.autopairs.map_cr,
- map_complete = options.builtin.autopairs.map_complete,
- }
- end
+ local cond = require "nvim-autopairs.conds"
autopairs.setup {
check_ts = options.builtin.autopairs.check_ts,
ts_config = options.builtin.autopairs.ts_config,
}
+ -- vim.g.completion_confirm_key = ""
+
+ autopairs.add_rule(Rule("$$", "$$", "tex"))
+ autopairs.add_rules {
+ Rule("$", "$", { "tex", "latex" }) -- don't add a pair if the next character is %
+ :with_pair(cond.not_after_regex_check "%%") -- don't add a pair if the previous character is xxx
+ :with_pair(cond.not_before_regex_check("xxx", 3)) -- don't move right when repeat character
+ :with_move(cond.none()) -- don't delete if the next character is xx
+ :with_del(cond.not_after_regex_check "xx") -- disable add newline when press <cr>
+ :with_cr(cond.none()),
+ }
+ autopairs.add_rules {
+ Rule("$$", "$$", "tex"):with_pair(function(opts)
+ print(vim.inspect(opts))
+ if opts.line == "aa $$" then
+ -- don't add pair on that line
+ return false
+ end
+ end),
+ }
+
+ if package.loaded["cmp"] then
+ require("nvim-autopairs.completion.cmp").setup {
+ map_cr = true, -- map <CR> on insert mode
+ map_complete = true, -- it will auto insert `(` after select function or method item
+ auto_select = true, -- automatically select the first item
+ }
+ end
+
require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
local ts_conds = require "nvim-autopairs.ts-conds"