Skip to content

Commit 68f0e5c

Browse files
authored
feat: add an enabled configuration function for more control of buffer attachement (#499)
1 parent 3d02855 commit 68f0e5c

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use {
4646

4747
``` lua
4848
{
49+
enabled = function(bufnr) return true end, -- control if auto-pairs should be enabled when attaching to a buffer
4950
disable_filetype = { "TelescopePrompt", "spectre_panel" },
5051
disable_in_macro = true, -- disable when recording or executing a macro
5152
disable_in_visualblock = false, -- disable when insert after visual block mode

doc/nvim-autopairs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ DEFAULT VALUES *nvim-autopairs-default-values*
5959

6060
>
6161
{
62+
enabled = function(bufnr) return true end, -- control if auto-pairs should be enabled when attaching to a buffer
6263
disable_filetype = { "TelescopePrompt", "spectre_panel" }
6364
disable_in_macro = true -- disable when recording or executing a macro
6465
disable_in_visualblock = false -- disable when insert after visual block mode

lua/nvim-autopairs.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local default = {
1616
map_c_h = false,
1717
map_c_w = false,
1818
map_cr = true,
19+
enabled = nil,
1920
disable_filetype = { 'TelescopePrompt', 'spectre_panel' },
2021
disable_in_macro = true,
2122
disable_in_visualblock = false,
@@ -194,7 +195,10 @@ local function is_disable()
194195
return true
195196
end
196197

197-
if utils.check_filetype(M.config.disable_filetype, vim.bo.filetype) then
198+
if
199+
utils.check_filetype(M.config.disable_filetype, vim.bo.filetype)
200+
or (M.config.enabled and not M.config.enabled(api.nvim_get_current_buf()))
201+
then
198202
del_keymaps()
199203
M.set_buf_rule({}, 0)
200204
return true

0 commit comments

Comments
 (0)