From 2dfda749475821da3f2e0109e4a3e0c451510e2c Mon Sep 17 00:00:00 2001 From: Kyle Grierson Date: Thu, 17 Aug 2023 10:11:42 +0100 Subject: [PATCH] update readme --- docs/sample.clj | 77 ++++++++++++++++++++++++++++++++++--- fnl/formedit/insertion.fnl | 3 +- fnl/formedit/wrap.fnl | 2 +- fnl/spec/insertion_spec.fnl | 14 ++++--- fnl/spec/wrap_spec.fnl | 6 ++- lua/formedit/insertion.lua | 3 +- lua/formedit/wrap.lua | 2 +- lua/spec/insertion_spec.lua | 15 ++++---- lua/spec/wrap_spec.lua | 4 +- 9 files changed, 99 insertions(+), 27 deletions(-) diff --git a/docs/sample.clj b/docs/sample.clj index 2b06c2d..d48646f 100644 --- a/docs/sample.clj +++ b/docs/sample.clj @@ -1,8 +1,73 @@ -(+ 1 2 3) -[1 2 3] -#{1 2 3 (+ 2 (+ 1 2))} +; TODO: Broken +; barf forward +; cxt: cursor within 1st form +; key: <) +; expected: (+ 1 (+ 2) 3) +(+ 1 (+ 2 3)) -(+ 1 (+ 2 3 4)) +; TODO: Broken +; barf backwards +; cxt: cursor within 1st form +; key: >( +; expected: (+ 1 + (2 3)) +(+ 1 (+ 2 3)) -(defn foo [x] x) -(defn bar [x] x) +; Wrap form +; cxt: cursor within +; key: i +; expected: (| (+ 2 3)) *insert mode* +(+ 2 3) + +; slurp forward +; cxt: cursor within 1st form +; key: >) +; expected: ((+ 1 2 3)) +((+ 1 2) 3) + +; slurp backward +; cxt: cursor within 1st form +; key: <( +; expected: (+ (1 + 2 3)) +(+ 1 (+ 2 3)) + +; raise form +; cxt: cursor within 1st form +; key: o +; expected: (+ 2 3) +(+ 1 (+ 2 3)) + +; Text object inner +; cxt: cursor within form +; key: dif +; expected: () +(+ 2 3) + +; Text object root inner +; cxt: cursor within second form +; key: diF +; expected: () +(+ 2 (+ 3)) + +; Text object outer +; cxt: cursor within second form +; key: daf +; expected: (+ 2 ) +(+ 2 (+ 3 4)) + +; Text object root outer +; cxt: cursor within second form +; key: daF +; expected: _ +(+ 2 3) + +; Insert head +; cxt: cursor within +; key: h +; expected: (| + 2 3) *insert mode* +(+ 2 3) + +; Insert tail +; cxt: cursor within +; key: H +; expected: (+ 2 3 |) *insert mode* +(+ 2 3) diff --git a/fnl/formedit/insertion.fnl b/fnl/formedit/insertion.fnl index 7ba18c8..e56a94e 100644 --- a/fnl/formedit/insertion.fnl +++ b/fnl/formedit/insertion.fnl @@ -6,7 +6,7 @@ [start-row start-col] [(form:start)] start-col (+ start-col offset)] (vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col [" "]) - (vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col 1)]) + (vim.api.nvim_win_set_cursor 0 [(+ start-row 1) start-col]) (vim.api.nvim_feedkeys :i :n true))) (fn tail [] @@ -14,6 +14,7 @@ [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_win_set_cursor 0 [(+ end-row 1) end-row]) (vim.api.nvim_feedkeys :i :n true))) {: head : tail} diff --git a/fnl/formedit/wrap.fnl b/fnl/formedit/wrap.fnl index 4be38bf..f41bf04 100644 --- a/fnl/formedit/wrap.fnl +++ b/fnl/formedit/wrap.fnl @@ -6,7 +6,7 @@ [start-row start-col end-row end-col] [(form:range)]] (vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [")"]) (vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col ["( "]) - (vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col offset 1)]) + (vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col offset)]) (vim.api.nvim_feedkeys :i :n true))) {: head} diff --git a/fnl/spec/insertion_spec.fnl b/fnl/spec/insertion_spec.fnl index 2c600c5..add4dec 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 1]}))) (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 3]}))))) (describe "tail insertion" (fn [] @@ -35,9 +35,11 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 )" :cursor [1 0]}))) + (h.expect {:content "(1 )" :cursor [1 3]}))) (it :sub (fn [] - (h.setup {:content "(1 (2))" :cursor [1 4]}) + (h.setup {:content "(1 (2))" :cursor [1 3]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 (2 ))" :cursor [1 3]}))))) + (h.expect {:content "(1 (2 ))" :cursor [1 6]}))))) + +(print "foo") diff --git a/fnl/spec/wrap_spec.fnl b/fnl/spec/wrap_spec.fnl index c7e6518..9e27eb2 100644 --- a/fnl/spec/wrap_spec.fnl +++ b/fnl/spec/wrap_spec.fnl @@ -13,9 +13,11 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys keymap) - (h.expect {:content "( (1))" :cursor [1 1]}))) + (h.expect {:content "( (1))" :cursor [1 0]}))) (it "sub form" (fn [] (h.setup {:content "(1 (2))" :cursor [1 3]}) (h.feedkeys keymap) - (h.expect {:content "(1 ( (2)))" :cursor [1 4]}))))) + (h.expect {:content "(1 ( (2)))" :cursor [1 3]}))))) + + diff --git a/lua/formedit/insertion.lua b/lua/formedit/insertion.lua index ce9c4c0..f29529b 100644 --- a/lua/formedit/insertion.lua +++ b/lua/formedit/insertion.lua @@ -8,7 +8,7 @@ local function head() local start_col = _let_1_[2] local start_col0 = (start_col + offset) vim.api.nvim_buf_set_text(0, start_row, start_col0, start_row, start_col0, {" "}) - vim.api.nvim_win_set_cursor(0, {(start_row + 1), (start_col0 + 1)}) + vim.api.nvim_win_set_cursor(0, {(start_row + 1), start_col0}) return vim.api.nvim_feedkeys("i", "n", true) end local function tail() @@ -18,6 +18,7 @@ local function tail() 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, {" "}) + vim.api.nvim_win_set_cursor(0, {(end_row + 1), end_row}) return vim.api.nvim_feedkeys("i", "n", true) end return {head = head, tail = tail} diff --git a/lua/formedit/wrap.lua b/lua/formedit/wrap.lua index 4956c97..d084b2b 100644 --- a/lua/formedit/wrap.lua +++ b/lua/formedit/wrap.lua @@ -10,7 +10,7 @@ local function head() local end_col = _let_1_[4] vim.api.nvim_buf_set_text(0, end_row, end_col, end_row, end_col, {")"}) vim.api.nvim_buf_set_text(0, start_row, start_col, start_row, start_col, {"( "}) - vim.api.nvim_win_set_cursor(0, {(start_row + 1), (start_col + offset + 1)}) + vim.api.nvim_win_set_cursor(0, {(start_row + 1), (start_col + offset)}) return vim.api.nvim_feedkeys("i", "n", true) end return {head = head} diff --git a/lua/spec/insertion_spec.lua b/lua/spec/insertion_spec.lua index 41baf0d..b8e83e8 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, 1}}) 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, 3}}) end return it("sub form", _6_) end @@ -42,14 +42,15 @@ local function _7_() local function _9_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 )", cursor = {1, 0}}) + return h.expect({content = "(1 )", cursor = {1, 3}}) end it("form", _9_) local function _10_() - h.setup({content = "(1 (2))", cursor = {1, 4}}) + h.setup({content = "(1 (2))", cursor = {1, 3}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 (2 ))", cursor = {1, 3}}) + return h.expect({content = "(1 (2 ))", cursor = {1, 6}}) end return it("sub", _10_) end -return describe("tail insertion", _7_) +describe("tail insertion", _7_) +return print("foo") diff --git a/lua/spec/wrap_spec.lua b/lua/spec/wrap_spec.lua index b538ebd..a5c0956 100644 --- a/lua/spec/wrap_spec.lua +++ b/lua/spec/wrap_spec.lua @@ -15,13 +15,13 @@ local function _2_() local function _4_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(keymap) - return h.expect({content = "( (1))", cursor = {1, 1}}) + return h.expect({content = "( (1))", cursor = {1, 0}}) end it("form head", _4_) local function _5_() h.setup({content = "(1 (2))", cursor = {1, 3}}) h.feedkeys(keymap) - return h.expect({content = "(1 ( (2)))", cursor = {1, 4}}) + return h.expect({content = "(1 ( (2)))", cursor = {1, 3}}) end return it("sub form", _5_) end