Skip to content

Commit

Permalink
Deduplicate deletions code, combine functions into shared, configurab…
Browse files Browse the repository at this point in the history
…le local functions
  • Loading branch information
Olical committed Sep 23, 2023
1 parent e94263e commit e757bf6
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions lua/nvim-paredit/api/deletions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ local selections = require("nvim-paredit.api.selections")

local M = {}

function M.delete_form()
local range = selections.get_range_around_form()
local function delete_form_impl(range)
if not range then
return
end
Expand All @@ -18,24 +17,15 @@ function M.delete_form()
)
end

function M.delete_top_level_form()
local range = selections.get_range_around_top_level_form()
if not range then
return
end
function M.delete_form()
delete_form_impl(selections.get_range_around_form())
end

local buf = vim.api.nvim_get_current_buf()
-- stylua: ignore
vim.api.nvim_buf_set_text(
buf,
range[1], range[2],
range[3], range[4],
{}
)
function M.delete_top_level_form()
delete_form_impl(selections.get_range_around_top_level_form())
end

function M.delete_in_form()
local range = selections.get_range_in_form()
local function delete_in_form_impl(range)
if not range then
return
end
Expand All @@ -52,22 +42,12 @@ function M.delete_in_form()
vim.api.nvim_win_set_cursor(0, { range[1] + 1, range[2] })
end

function M.delete_in_top_level_form()
local range = selections.get_range_in_top_level_form()
if not range then
return
end

local buf = vim.api.nvim_get_current_buf()
-- stylua: ignore
vim.api.nvim_buf_set_text(
buf,
range[1], range[2],
range[3], range[4],
{}
)
function M.delete_in_form()
delete_in_form_impl(selections.get_range_in_form())
end

vim.api.nvim_win_set_cursor(0, { range[1] + 1, range[2] })
function M.delete_in_top_level_form()
delete_in_form_impl(selections.get_range_in_top_level_form())
end

function M.delete_element()
Expand Down

0 comments on commit e757bf6

Please sign in to comment.