From 14bad1f3cde4f44ec27981b36394061eab7b3947 Mon Sep 17 00:00:00 2001 From: TANIGUCHI Masaya Date: Sat, 7 Aug 2021 00:29:27 +0900 Subject: [PATCH] Add exclude_filetypes --- README.md | 6 ++++++ lua/nvim-autopairs/conds.lua | 13 ++++++++++++- tests/nvim-autopairs_spec.lua | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 104088d..cbab5f9 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,12 @@ npairs.add_rules({ .."viwU" end) }) + +-- you can exclude filetypes +npairs.add_rule( + Rule("$$","$$") + :with_pair(cond.exclude_filetypes({"lua"})) +) --- check ./lua/nvim-autopairs/rules/basic.lua ``` diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index 886bde3..d723454 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -8,7 +8,6 @@ local cond = {} -- true when it is correct -- nil when it is not determine - cond.none = function() return function() return false end end @@ -199,4 +198,16 @@ cond.is_end_line = function() end end +cond.exclude_filetypes = function(filetypes) + return function(opts) + log.debug('exclude_filetypes') + for _, filetype in pairs(filetypes) do + if vim.bo.filetype == filetype then + return false + end + end + return true + end +end + return cond diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index 3d1e1ef..2c95eb2 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -378,6 +378,26 @@ local data = { before = [[Vec| ]], after = [[Vec<|> ]], }, + { + setup_func = function() + npairs.add_rule(Rule("!", "!"):with_pair(cond.exclude_filetypes({"lua"}))) + end, + name="disable pairs in lua", + filetype="lua", + key="!", + before = [[x| ]], + after = [[x!| ]] + }, + { + setup_func = function() + npairs.add_rule(Rule("!", "!"):with_pair(cond.exclude_filetypes({"lua"}))) + end, + name="enable pairs in html", + filetype="html", + key="!", + before = [[x| ]], + after = [[x!|! ]] + }, } local run_data = {}