Skip to content

Commit 71a7223

Browse files
committed
Cleanup implementation
1 parent 6039cae commit 71a7223

File tree

8 files changed

+186
-243
lines changed

8 files changed

+186
-243
lines changed

lua/nvim-paredit/api/barfing.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function M.barf_forwards(opts)
8181
end
8282
end
8383

84-
indentation.handle_indentation({
84+
local event = {
8585
type = "barf-forwards",
8686
-- stylua: ignore
8787
parent_range = {
@@ -91,7 +91,8 @@ function M.barf_forwards(opts)
9191
reversed = false,
9292
indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour,
9393
lang = lang,
94-
})
94+
}
95+
indentation.handle_indentation(event, opts)
9596
end
9697

9798
function M.barf_backwards(opts)
@@ -161,17 +162,15 @@ function M.barf_backwards(opts)
161162
end
162163
end
163164

164-
indentation.handle_indentation({
165+
local event = {
165166
type = "barf-backwards",
166167
-- stylua: ignore
167168
parent_range = {
168169
end_pos[1], end_pos[2],
169170
edges.right.range[1], edges.right.range[2],
170171
},
171-
reversed = true,
172-
indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour,
173-
lang = lang,
174-
})
172+
}
173+
indentation.handle_indentation(event, opts)
175174
end
176175

177176
return M

lua/nvim-paredit/api/slurping.lua

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,25 @@ local function slurp(opts)
9797
local new_range
9898
if not opts.reversed then
9999
operation_type = "slurp-forwards"
100+
-- stylua: ignore
100101
new_range = {
101-
form_edges.left.range[1],
102-
form_edges.left.range[2],
103-
row,
104-
col,
102+
form_edges.left.range[1], form_edges.left.range[2],
103+
row, col,
105104
}
106105
else
107106
operation_type = "slurp-backwards"
107+
-- stylua: ignore
108108
new_range = {
109-
row,
110-
col,
111-
form_edges.right.range[1],
112-
form_edges.right.range[2],
109+
row, col,
110+
form_edges.right.range[1], form_edges.right.range[2],
113111
}
114112
end
115113

116-
indentation.handle_indentation({
114+
local event = {
117115
type = operation_type,
118116
parent_range = new_range,
119-
reversed = opts.reversed,
120-
indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour,
121-
lang = lang,
122-
})
117+
}
118+
indentation.handle_indentation(event, opts)
123119
end
124120

125121
function M.slurp_forwards(opts)

lua/nvim-paredit/defaults.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ M.default_keys = {
6161
M.defaults = {
6262
use_default_keys = true,
6363
cursor_behaviour = "auto", -- remain, follow, auto
64-
indent_behaviour = "native", -- native, lsp, none
64+
auto_indent = true,
6565
keys = {},
6666
}
6767

lua/nvim-paredit/indentation/init.lua

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
local native = require("nvim-paredit.indentation.native")
2-
local lsp = require("nvim-paredit.indentation.lsp")
2+
local config = require("nvim-paredit.config")
33

44
local M = {}
55

6-
function M.handle_indentation(operation)
7-
local behaviour = operation.indent_behaviour
8-
if not behaviour or behaviour == "none" then
6+
function M.handle_indentation(event, opts)
7+
local auto_indent = opts.auto_indent or config.config.auto_indent
8+
if not auto_indent then
99
return
1010
end
1111

12-
local indent_fn
13-
14-
if type(behaviour) == "function" then
15-
indent_fn = behaviour
16-
elseif behaviour == "lsp" then
17-
indent_fn = lsp.indent
18-
elseif behaviour == "native" then
19-
indent_fn = native.indent
20-
end
21-
12+
local indent_fn = opts.indent_fn or config.config.indent_fn or native.indent
2213
if not indent_fn then
2314
return
2415
end
@@ -27,11 +18,14 @@ function M.handle_indentation(operation)
2718

2819
tree:parse()
2920

30-
local parent = tree:named_node_for_range(operation.parent_range)
31-
indent_fn(vim.tbl_deep_extend("force", operation, {
32-
tree = tree,
33-
parent = parent,
34-
}))
21+
local parent = tree:named_node_for_range(event.parent_range)
22+
indent_fn(
23+
vim.tbl_deep_extend("force", event, {
24+
tree = tree,
25+
parent = parent,
26+
}),
27+
opts
28+
)
3529
end
3630

3731
return M

lua/nvim-paredit/indentation/lsp.lua

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)