add option enable_check_bracket_line

This commit is contained in:
windwp 2021-06-02 08:43:48 +07:00
parent b5816204bd
commit d7f2976b55
4 changed files with 29 additions and 6 deletions

View File

@ -17,6 +17,7 @@ local default = {
check_ts = false,
enable_moveright = true,
enable_afterquote = true,
enable_check_bracket_line = true,
ts_config = {
lua = {'string', 'source'},
javascript = {'string', 'template_string'}

View File

@ -55,6 +55,7 @@ end
cond.not_after_regex_check = function(regex, length)
length = length or 1
return function(opts)
if not regex then return end
log.debug('not_after_regex_check')
local str = utils.text_sub_char(opts.line, opts.col + 1, length)
if str:match(regex) then

View File

@ -10,6 +10,17 @@ local function setup(opt)
:with_pair(cond.not_after_regex_check(opt.ignored_next_char))
:with_pair(cond.not_add_quote_inside_quote())
end
local bracket = function(...)
print(opt.enable_check_bracket_line)
print(vim.inspect(opt))
if opt.enable_check_bracket_line == true then
return basic(...)
:with_pair(cond.check_is_bracket_line())
end
return basic(...)
end
local rules = {
Rule("<!--", "-->", 'html'):with_cr(cond.none()),
Rule("```", "```", { 'markdown', 'vimwiki' }),
@ -22,12 +33,9 @@ local function setup(opt)
:with_pair(cond.not_before_regex_check("%w")) ,
basic("`", "`"),
basic('"', '"'),
basic("(", ")")
:with_pair(cond.check_is_bracket_line()),
basic("[", "]")
:with_pair(cond.check_is_bracket_line()),
basic("{", "}")
:with_pair(cond.check_is_bracket_line()),
bracket("(", ")"),
bracket("[", "]"),
bracket("{", "}"),
Rule(">", "<",
{ 'html', 'typescript', 'typescriptreact', 'svelte', 'vue', 'xml'})
:only_cr()

View File

@ -373,5 +373,18 @@ describe('autopairs ', function()
},
}
Test(run_data)
npairs.setup({
enable_check_bracket_line=false
})
run_data = {
{
name = "test disable check bracket line" ,
filetype = "latex",
key = [[(]],
before = [[(|))) ]],
after = [[((|)))) ]],
},
}
Test(run_data)
end)