diff options
author | LostNeophyte <[email protected]> | 2023-02-18 08:55:05 +0100 |
---|---|---|
committer | LostNeophyte <[email protected]> | 2023-02-18 08:55:05 +0100 |
commit | 8f70ecd882cf44567ddbffb469373501492938f9 (patch) | |
tree | 1498fd1de08c1aec46fa628701e1b5e9a47c4e3b /lua/lvim/builtin/autopairs.lua | |
parent | 3144585515000a1c3064c6129ded74f662598de1 (diff) |
refactor(builtins): move builtins to lvim/builtinrefactor/builtins
Diffstat (limited to 'lua/lvim/builtin/autopairs.lua')
-rw-r--r-- | lua/lvim/builtin/autopairs.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lua/lvim/builtin/autopairs.lua b/lua/lvim/builtin/autopairs.lua new file mode 100644 index 00000000..97f405be --- /dev/null +++ b/lua/lvim/builtin/autopairs.lua @@ -0,0 +1,82 @@ +local M = {} + +function M.config() + lvim.builtin.autopairs = { + active = true, + ---@usage modifies the function or method delimiter by filetypes + map_char = { + all = "(", + tex = "{", + }, + ---@usage check bracket in same line + enable_check_bracket_line = false, + ---@usage check treesitter + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], "%s+", ""), + enable_moveright = true, + ---@usage disable when recording or executing a macro + disable_in_macro = false, + ---@usage add bracket pairs after quote + enable_afterquote = true, + ---@usage map the <BS> key + map_bs = true, + ---@usage map <c-w> to delete a pair if possible + map_c_w = false, + ---@usage disable when insert after visual block mode + disable_in_visualblock = false, + ---@usage change default fast_wrap + fast_wrap = { + map = "<M-e>", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "Search", + highlight_grey = "Comment", + }, + } +end + +local function on_confirm_done(...) + require("nvim-autopairs.completion.cmp").on_confirm_done()(...) +end + +M.setup = function() + local status_ok, autopairs = pcall(require, "nvim-autopairs") + if not status_ok then + return + end + + autopairs.setup { + check_ts = lvim.builtin.autopairs.check_ts, + enable_check_bracket_line = lvim.builtin.autopairs.enable_check_bracket_line, + ts_config = lvim.builtin.autopairs.ts_config, + disable_filetype = lvim.builtin.autopairs.disable_filetype, + disable_in_macro = lvim.builtin.autopairs.disable_in_macro, + ignored_next_char = lvim.builtin.autopairs.ignored_next_char, + enable_moveright = lvim.builtin.autopairs.enable_moveright, + enable_afterquote = lvim.builtin.autopairs.enable_afterquote, + map_c_w = lvim.builtin.autopairs.map_c_w, + map_bs = lvim.builtin.autopairs.map_bs, + disable_in_visualblock = lvim.builtin.autopairs.disable_in_visualblock, + fast_wrap = lvim.builtin.autopairs.fast_wrap, + } + + pcall(function() + require "nvim-autopairs.completion.cmp" + require("cmp").event:off("confirm_done", on_confirm_done) + require("cmp").event:on("confirm_done", on_confirm_done) + end) + + return autopairs +end + +return M |