aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2024-02-20 23:58:52 +0200
committersrdusr <trevorgray@srdusr.com>2024-02-20 23:58:52 +0200
commitcc7e3b0729b57c0319cb537c38642294d07c465a (patch)
tree43e443109a16eeb14ff8267fd81a393c31a6cf78 /lua/plugins
parent6af1d0d7b18ecd4f771b8aa1d96dfcbe00355ead (diff)
downloaddotfiles-cc7e3b0729b57c0319cb537c38642294d07c465a.tar.gz
dotfiles-cc7e3b0729b57c0319cb537c38642294d07c465a.zip
Autopairs for vimtex
Diffstat (limited to 'lua/plugins')
-rw-r--r--lua/plugins/autopairs.lua99
1 files changed, 72 insertions, 27 deletions
diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua
index 90c6d35..90b62b1 100644
--- a/lua/plugins/autopairs.lua
+++ b/lua/plugins/autopairs.lua
@@ -1,42 +1,87 @@
-local status_ok, npairs = pcall(require, "nvim-autopairs")
+local status_ok, autopairs = pcall(require, "nvim-autopairs")
if not status_ok then
return
end
-npairs.setup {
+autopairs.setup({
check_ts = true,
ts_config = {
lua = { "string", "source" },
javascript = { "string", "template_string" },
java = false,
},
- map = "<M-e>",
- pairs_map = {
-['<'] = '>',
-},
+ map = "<M-e>",
+ pairs_map = {
+ ["<"] = ">",
+ },
disable_filetype = { "TelescopePrompt", "spectre_panel" },
disable_in_macro = true,
disable_in_visualblock = true,
enable_moveright = true,
- enable_afterquote = true, -- add bracket pairs after quote
- enable_check_bracket_line = false, --- check bracket in same line
- enable_bracket_in_quote = true, --
- break_undo = true, -- switch for basic rule break undo sequence
- fast_wrap = {
- chars = { "{", "[", "(", '"', "'" },
- pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
- offset = 0, -- Offset from pattern match
- end_key = "$",
- keys = "qwertyuiopzxcvbnmasdfghjkl",
- check_comma = true,
- highlight = "PmenuSel",
- highlight_grey = "LineNr",
- },
-}
+ enable_afterquote = true, -- add bracket pairs after quote
+ enable_check_bracket_line = false, --- check bracket in same line
+ enable_bracket_in_quote = true, --
+ break_undo = true, -- switch for basic rule break undo sequence
+ --fast_wrap = {
+ -- chars = { "{", "[", "(", '"', "'" },
+ -- pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
+ -- offset = 0, -- Offset from pattern match
+ -- end_key = "$",
+ -- keys = "qwertyuiopzxcvbnmasdfghjkl",
+ -- check_comma = true,
+ -- highlight = "PmenuSel",
+ -- highlight_grey = "LineNr",
+ --},
+})
+local Rule = require("nvim-autopairs.rule")
-local cmp_autopairs = require "nvim-autopairs.completion.cmp"
-local cmp_status_ok, cmp = pcall(require, "cmp")
-if not cmp_status_ok then
- return
-end
-cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } })
+local cond = require("nvim-autopairs.conds")
+
+autopairs.add_rules({
+ Rule("`", "'", "tex"),
+ Rule("$", "$", "tex"),
+ Rule(" ", " ")
+ :with_pair(function(opts)
+ local pair = opts.line:sub(opts.col, opts.col + 1)
+ return vim.tbl_contains({ "$$", "()", "{}", "[]", "<>" }, pair)
+ end)
+ :with_move(cond.none())
+ :with_cr(cond.none())
+ :with_del(function(opts)
+ local col = vim.api.nvim_win_get_cursor(0)[2]
+ local context = opts.line:sub(col - 1, col + 2)
+ return vim.tbl_contains({ "$ $", "( )", "{ }", "[ ]", "< >" }, context)
+ end),
+ Rule("$ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("[ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("{ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("( ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("< ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+})
+
+autopairs.get_rule("$"):with_move(function(opts)
+ return opts.char == opts.next_char:sub(1, 1)
+end)
+
+-- import nvim-cmp plugin (completions plugin)
+local cmp = require("cmp")
+
+-- import nvim-autopairs completion functionality
+local cmp_autopairs = require("nvim-autopairs.completion.cmp")
+
+-- make autopairs and completion work together
+cmp.event:on(
+ "confirm_done",
+ cmp_autopairs.on_confirm_done({
+ filetypes = {
+ tex = false, -- Disable for tex
+ },
+ })
+)
+
+--local cmp_autopairs = require "nvim-autopairs.completion.cmp"
+--local cmp_status_ok, cmp = pcall(require, "cmp")
+--if not cmp_status_ok then
+-- return
+--end
+--cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } })