@@ -4,40 +4,48 @@ local defaults = require("nvim-paredit.defaults")
4
4
local config = require (" nvim-paredit.config" )
5
5
local lang = require (" nvim-paredit.lang" )
6
6
7
- local M = {
8
- api = require (" nvim-paredit.api" ),
9
- wrap = require (" nvim-paredit.api.wrap" ),
10
- cursor = require (" nvim-paredit.api.cursor" ),
11
- }
12
-
13
7
local function setup_keybingings (filetype , buf )
14
- local filetypes = config .config .filetypes
8
+ local whitelist = config .config .filetypes
15
9
local keys = config .config .keys
16
10
17
- if common .included_in_table (filetypes , filetype ) then
18
- keybindings .setup_keybindings ({
19
- keys = keys ,
20
- buf = buf ,
21
- })
11
+ if whitelist and not common .included_in_table (whitelist , filetype ) then
12
+ return
22
13
end
14
+
15
+ if not common .included_in_table (lang .filetypes (), filetype ) then
16
+ return
17
+ end
18
+
19
+ keybindings .setup_keybindings ({
20
+ keys = keys ,
21
+ buf = buf ,
22
+ })
23
23
end
24
24
25
+ local function add_language_extension (ft , api )
26
+ lang .add_language_extension (ft , api )
27
+
28
+ if vim .bo .filetype == ft then
29
+ setup_keybingings (ft , vim .api .nvim_get_current_buf ())
30
+ end
31
+ end
32
+
33
+ local M = {
34
+ api = require (" nvim-paredit.api" ),
35
+ wrap = require (" nvim-paredit.api.wrap" ),
36
+ cursor = require (" nvim-paredit.api.cursor" ),
37
+ extension = {
38
+ add_language_extension = add_language_extension ,
39
+ },
40
+ }
41
+
25
42
function M .setup (opts )
26
43
opts = opts or {}
27
44
28
45
for filetype , api in pairs (opts .extensions or {}) do
29
46
lang .add_language_extension (filetype , api )
30
47
end
31
48
32
- local filetypes
33
- if type (opts .filetypes ) == " table" then
34
- -- substract langs form opts.filetypes to avoid
35
- -- binding keymaps to unsupported buffers
36
- filetypes = common .intersection (opts .filetypes , lang .filetypes ())
37
- else
38
- filetypes = lang .filetypes ()
39
- end
40
-
41
49
local keys = opts .keys or {}
42
50
43
51
if type (opts .use_default_keys ) ~= " boolean" or opts .use_default_keys then
@@ -46,7 +54,6 @@ function M.setup(opts)
46
54
47
55
config .update_config (defaults .defaults )
48
56
config .update_config (common .merge (opts , {
49
- filetypes = filetypes ,
50
57
keys = keys ,
51
58
}))
52
59
0 commit comments