diff --git a/fnl/formedit/selection.fnl b/fnl/formedit/selection.fnl index dd9fa27..d98002b 100644 --- a/fnl/formedit/selection.fnl +++ b/fnl/formedit/selection.fnl @@ -1,18 +1,23 @@ (local tree (require :formedit.tree)) -(fn delete-around-form [] +(fn get-around-form [] + (let [form (tree.get-current-form)] + [(form:range)])) + +(fn get-inner-form [] (let [form (tree.get-current-form) + offset (if (or (= :set_lit (form:type)) (= :anon_fn_lit (form:type))) + 2 + 1) [start-row start-col end-row end-col] [(form:range)]] + [start-row (+ start-col offset) end-row (- end-col 1)])) + +(fn delete-around-form [] + (let [[start-row start-col end-row end-col] (get-around-form)] (vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col {}))) (fn delete-inner-form [] - (let [form (tree.get-current-form) - [start-row start-col end-row end-col] [(form:range)] - buffer 0 - offset (if (or (= :set_lit (form:type)) (= :anon_fn_lit (form:type))) - 2 - 1)] - (vim.api.nvim_buf_set_text buffer start-row (+ start-col offset) end-row - (- end-col 1) {}))) + (let [[start-row start-col end-row end-col] (get-inner-form)] + (vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col {}))) -{: delete-around-form : delete-inner-form} +{: get-around-form : get-inner-form : delete-around-form : delete-inner-form} diff --git a/lua/formedit/selection.lua b/lua/formedit/selection.lua index f8c7cca..8b3dab9 100644 --- a/lua/formedit/selection.lua +++ b/lua/formedit/selection.lua @@ -1,28 +1,38 @@ -- [nfnl] Compiled from fnl/formedit/selection.fnl by https://github.com/Olical/nfnl, do not edit. local tree = require("formedit.tree") -local function delete_around_form() +local function get_around_form() local form = tree["get-current-form"]() - local _let_1_ = {form:range()} - local start_row = _let_1_[1] - local start_col = _let_1_[2] - local end_row = _let_1_[3] - local end_col = _let_1_[4] - return vim.api.nvim_buf_set_text(0, start_row, start_col, end_row, end_col, {}) + return {form:range()} end -local function delete_inner_form() +local function get_inner_form() local form = tree["get-current-form"]() - local _let_2_ = {form:range()} - local start_row = _let_2_[1] - local start_col = _let_2_[2] - local end_row = _let_2_[3] - local end_col = _let_2_[4] - local buffer = 0 local offset if (("set_lit" == form:type()) or ("anon_fn_lit" == form:type())) then offset = 2 else offset = 1 end - return vim.api.nvim_buf_set_text(buffer, start_row, (start_col + offset), end_row, (end_col - 1), {}) + local _let_2_ = {form:range()} + local start_row = _let_2_[1] + local start_col = _let_2_[2] + local end_row = _let_2_[3] + local end_col = _let_2_[4] + return {start_row, (start_col + offset), end_row, (end_col - 1)} +end +local function delete_around_form() + local _let_3_ = get_around_form() + local start_row = _let_3_[1] + local start_col = _let_3_[2] + local end_row = _let_3_[3] + local end_col = _let_3_[4] + return vim.api.nvim_buf_set_text(0, start_row, start_col, end_row, end_col, {}) +end +local function delete_inner_form() + local _let_4_ = get_inner_form() + local start_row = _let_4_[1] + local start_col = _let_4_[2] + local end_row = _let_4_[3] + local end_col = _let_4_[4] + return vim.api.nvim_buf_set_text(0, start_row, start_col, end_row, end_col, {}) end -return {["delete-around-form"] = delete_around_form, ["delete-inner-form"] = delete_inner_form} +return {["get-around-form"] = get_around_form, ["get-inner-form"] = get_inner_form, ["delete-around-form"] = delete_around_form, ["delete-inner-form"] = delete_inner_form}