Skip to content

Commit

Permalink
fix #347 add get_rules always return table
Browse files Browse the repository at this point in the history
  • Loading branch information
windwp authored and windwp committed Apr 29, 2023
1 parent 463165e commit 1748b0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -342,15 +342,14 @@ Before Input After
require('nvim-autopairs').enable()
require('nvim-autopairs').remove_rule('(') -- remove rule (
require('nvim-autopairs').clear_rules() -- clear all rules
-- get rule " then modify it. It can return a list of rule or just a rule
require('nvim-autopairs').get_rule('"')
require('nvim-autopairs').get_rules('"')
```

* Sample
```lua
-- remove add single quote on filetype scheme or lisp
require("nvim-autopairs").get_rule("'")[1].not_filetypes = { "scheme", "lisp" }
require("nvim-autopairs").get_rule("'")[1]:with_pair(cond.not_after_text("["))
require("nvim-autopairs").get_rules("'")[1].not_filetypes = { "scheme", "lisp" }
require("nvim-autopairs").get_rules("'")[1]:with_pair(cond.not_after_text("["))
```

### FastWrap
Expand Down
12 changes: 8 additions & 4 deletions lua/nvim-autopairs.lua
Expand Up @@ -80,16 +80,20 @@ M.add_rule = function(rule)
end

M.get_rule = function(start_pair)
local tbl = M.get_rule(start_pair)
if #tbl == 1 then
return tbl[1]
end
return tbl
end

M.get_rules = function(start_pair)
local tbl = {}
for _, r in pairs(M.config.rules) do
if r.start_pair == start_pair then
table.insert(tbl, r)
end
end
if #tbl == 1 then
return tbl[1]
end
return tbl
end

M.remove_rule = function(pair)
Expand Down

0 comments on commit 1748b0a

Please sign in to comment.