diff --git a/fnl/formedit/insertion.fnl b/fnl/formedit/insertion.fnl index 9ffd2ce..e6f25ef 100644 --- a/fnl/formedit/insertion.fnl +++ b/fnl/formedit/insertion.fnl @@ -1,25 +1,18 @@ (local find (require :formedit.find)) -(fn range [form] - (let [[start-row start-col end-row end-col] [(form:range)]] - [(+ start-row 1) start-col (+ end-row 1) end-col])) - (fn head [] (let [form (find.form) - start-offset (. find.start-offset (form:type)) insert-offset (. find.insert-offset (form:type)) - [start-row start-col _ _] (range form)] - (vim.api.nvim_win_set_cursor 0 [start-row (+ start-col start-offset)]) - (vim.api.nvim_command "normal! a ") - (vim.api.nvim_win_set_cursor 0 [start-row (+ start-col insert-offset)]) + [start-row start-col] [(form:start)] + start-col (+ start-col insert-offset)] + (vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col [" "]) (vim.api.nvim_feedkeys :i :n true))) (fn tail [] (let [form (find.form) - [_ _ end-row end-col] (range form)] - (vim.api.nvim_win_set_cursor 0 [end-row (- end-col 1)]) - (vim.api.nvim_command "normal! i ") - (vim.api.nvim_win_set_cursor 0 [end-row end-col]) + [end-row end-col] [(form:end_)] + end-col (- end-col 1)] + (vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [" "]) (vim.api.nvim_feedkeys :i :n true))) {: head : tail} diff --git a/fnl/spec/insertion_spec.fnl b/fnl/spec/insertion_spec.fnl index dadaeea..caf8890 100644 --- a/fnl/spec/insertion_spec.fnl +++ b/fnl/spec/insertion_spec.fnl @@ -14,17 +14,17 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys head-keymap) - (h.expect {:content "( 1)" :cursor [1 1]}))) + (h.expect {:content "( 1)" :cursor [1 0]}))) (it :set (fn [] (h.setup {:content "#{1}" :cursor [1 0]}) (h.feedkeys head-keymap) - (h.expect {:content "#{ 1}" :cursor [1 2]}))) + (h.expect {:content "#{ 1}" :cursor [1 0]}))) (it "sub form" (fn [] (h.setup {:content "(1 (2))" :cursor [1 3]}) (h.feedkeys head-keymap) - (h.expect {:content "(1 ( 2))" :cursor [1 4]}))))) + (h.expect {:content "(1 ( 2))" :cursor [1 2]}))))) (describe "tail insertion" (fn [] @@ -35,9 +35,9 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 )" :cursor [1 2]}))) + (h.expect {:content "(1 )" :cursor [1 0]}))) (it :sub (fn [] (h.setup {:content "(1 (2))" :cursor [1 4]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 (2 ))" :cursor [1 5]}))))) + (h.expect {:content "(1 (2 ))" :cursor [1 3]}))))) diff --git a/lua/formedit/insertion.lua b/lua/formedit/insertion.lua index 6c71648..a70b0f3 100644 --- a/lua/formedit/insertion.lua +++ b/lua/formedit/insertion.lua @@ -1,37 +1,22 @@ -- [nfnl] Compiled from fnl/formedit/insertion.fnl by https://github.com/Olical/nfnl, do not edit. local find = require("formedit.find") -local function range(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 {(start_row + 1), start_col, (end_row + 1), end_col} -end local function head() local form = find.form() - local start_offset = (find["start-offset"])[form:type()] local insert_offset = (find["insert-offset"])[form:type()] - local _let_2_ = range(form) - local start_row = _let_2_[1] - local start_col = _let_2_[2] - local _ = _let_2_[3] - local _0 = _let_2_[4] - vim.api.nvim_win_set_cursor(0, {start_row, (start_col + start_offset)}) - vim.api.nvim_command("normal! a ") - vim.api.nvim_win_set_cursor(0, {start_row, (start_col + insert_offset)}) + local _let_1_ = {form:start()} + local start_row = _let_1_[1] + local start_col = _let_1_[2] + local start_col0 = (start_col + insert_offset) + vim.api.nvim_buf_set_text(0, start_row, start_col0, start_row, start_col0, {" "}) return vim.api.nvim_feedkeys("i", "n", true) end local function tail() local form = find.form() - local _let_3_ = range(form) - local _ = _let_3_[1] - local _0 = _let_3_[2] - local end_row = _let_3_[3] - local end_col = _let_3_[4] - vim.api.nvim_win_set_cursor(0, {end_row, (end_col - 1)}) - vim.api.nvim_command("normal! i ") - vim.api.nvim_win_set_cursor(0, {end_row, end_col}) + local _let_2_ = {form:end_()} + local end_row = _let_2_[1] + local end_col = _let_2_[2] + local end_col0 = (end_col - 1) + vim.api.nvim_buf_set_text(0, end_row, end_col0, end_row, end_col0, {" "}) return vim.api.nvim_feedkeys("i", "n", true) end return {head = head, tail = tail} diff --git a/lua/spec/insertion_spec.lua b/lua/spec/insertion_spec.lua index d914da1..f2f5902 100644 --- a/lua/spec/insertion_spec.lua +++ b/lua/spec/insertion_spec.lua @@ -16,19 +16,19 @@ local function _2_() local function _4_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(head_keymap) - return h.expect({content = "( 1)", cursor = {1, 1}}) + return h.expect({content = "( 1)", cursor = {1, 0}}) end it("form", _4_) local function _5_() h.setup({content = "#{1}", cursor = {1, 0}}) h.feedkeys(head_keymap) - return h.expect({content = "#{ 1}", cursor = {1, 2}}) + return h.expect({content = "#{ 1}", cursor = {1, 0}}) end it("set", _5_) local function _6_() h.setup({content = "(1 (2))", cursor = {1, 3}}) h.feedkeys(head_keymap) - return h.expect({content = "(1 ( 2))", cursor = {1, 4}}) + return h.expect({content = "(1 ( 2))", cursor = {1, 2}}) end return it("sub form", _6_) end @@ -42,13 +42,13 @@ local function _7_() local function _9_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 )", cursor = {1, 2}}) + return h.expect({content = "(1 )", cursor = {1, 0}}) end it("form", _9_) local function _10_() h.setup({content = "(1 (2))", cursor = {1, 4}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 (2 ))", cursor = {1, 5}}) + return h.expect({content = "(1 (2 ))", cursor = {1, 3}}) end return it("sub", _10_) end