diff --git a/README.md b/README.md index f5548f8..3fd88eb 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ Paredit in fennel ./scripts/nfnl # To download nfnl ``` -[ ] - inner select -[ ] - root select -[ ] - slurp/barf +[ ] - inner select - Get all named value children on form +[ ] - root select - Is form and on column 0 +[ ] - slurp/barf - ? ## Unlicensed diff --git a/docs/sample.clj b/docs/sample.clj index 5a1ef09..2b06c2d 100644 --- a/docs/sample.clj +++ b/docs/sample.clj @@ -2,5 +2,7 @@ [1 2 3] #{1 2 3 (+ 2 (+ 1 2))} +(+ 1 (+ 2 3 4)) + (defn foo [x] x) (defn bar [x] x) diff --git a/fnl/formedit/find.fnl b/fnl/formedit/find.fnl index c0fc29b..a279a87 100644 --- a/fnl/formedit/find.fnl +++ b/fnl/formedit/find.fnl @@ -26,9 +26,12 @@ (when parent (find-current-form parent))))) (fn find-root-form [node] - (if (node:parent) - (find-root-form (node:parent)) - node)) + (let [[_ col] [(node:start)] + type (node:type)] + (if (and (. forms type) (= col 0)) + node + (when (node:parent) + (find-root-form (node:parent)))))) ;; Find node (fn form [] diff --git a/fnl/spec/delete_around_spec.fnl b/fnl/spec/delete_around_spec.fnl index a1b05b3..21ee792 100644 --- a/fnl/spec/delete_around_spec.fnl +++ b/fnl/spec/delete_around_spec.fnl @@ -56,8 +56,13 @@ (h.setup {:content "(+ 1 (+ 2 3))" :cursor [1 7]}) (h.feedkeys :daF) (h.expect {:content "" :cursor [1 0]}))) - (it "cursor in sub form deletes root" + (it "only deletes root form that cursor is in" (fn [] - (h.setup {:content "(+ 1 (+ 2 3))" :cursor [1 7]}) + (h.setup {:content ["(+ 1 2)" "(+ 3 4)"] :cursor [1 0]}) + (h.feedkeys :daF) + (h.expect {:content ["" "(+ 3 4)"] :cursor [1 0]}))) + (it "only deletes root form that cursor is in second form" + (fn [] + (h.setup {:content ["(+ 1 2)" "(+ 3 4)"] :cursor [2 0]}) (h.feedkeys :daF) - (h.expect {:content "" :cursor [1 0]}))))) + (h.expect {:content ["(+ 1 2)" ""] :cursor [2 0]}))))) diff --git a/fnl/spec/helper.fnl b/fnl/spec/helper.fnl index 6422d52..55d5025 100644 --- a/fnl/spec/helper.fnl +++ b/fnl/spec/helper.fnl @@ -15,8 +15,11 @@ (fn expect [{: cursor : content}] (when content - (assert.are.same content - (core.first (vim.api.nvim_buf_get_lines 0 0 10 false)))) + (assert.are.same content (let [text (vim.api.nvim_buf_get_lines 0 0 10 + false)] + (if (= (core.count text) 1) + (core.first text) + text)))) (when cursor (assert.are.same cursor (vim.api.nvim_win_get_cursor 0)))) diff --git a/lua/formedit/find.lua b/lua/formedit/find.lua index 427460f..4b3abf9 100644 --- a/lua/formedit/find.lua +++ b/lua/formedit/find.lua @@ -16,10 +16,18 @@ local function find_current_form(node) end end local function find_root_form(node) - if node:parent() then - return find_root_form(node:parent()) - else + local _let_3_ = {node:start()} + local _ = _let_3_[1] + local col = _let_3_[2] + local type = node:type() + if (forms[type] and (col == 0)) then return node + else + if node:parent() then + return find_root_form(node:parent()) + else + return nil + end end end local function form() diff --git a/lua/spec/delete_around_spec.lua b/lua/spec/delete_around_spec.lua index 61c56fb..f6b8bb6 100644 --- a/lua/spec/delete_around_spec.lua +++ b/lua/spec/delete_around_spec.lua @@ -72,10 +72,16 @@ local function _11_() end it("cursor in sub form deletes root", _14_) local function _15_() - h.setup({content = "(+ 1 (+ 2 3))", cursor = {1, 7}}) + h.setup({content = {"(+ 1 2)", "(+ 3 4)"}, cursor = {1, 0}}) h.feedkeys("daF") - return h.expect({content = "", cursor = {1, 0}}) + return h.expect({content = {"", "(+ 3 4)"}, cursor = {1, 0}}) + end + it("only deletes root form that cursor is in", _15_) + local function _16_() + h.setup({content = {"(+ 1 2)", "(+ 3 4)"}, cursor = {2, 0}}) + h.feedkeys("daF") + return h.expect({content = {"(+ 1 2)", ""}, cursor = {2, 0}}) end - return it("cursor in sub form deletes root", _15_) + return it("only deletes root form that cursor is in second form", _16_) end return describe("delete around root", _11_) diff --git a/lua/spec/helper.lua b/lua/spec/helper.lua index f16600f..55d9a45 100644 --- a/lua/spec/helper.lua +++ b/lua/spec/helper.lua @@ -27,7 +27,15 @@ local function expect(_4_) local cursor = _arg_5_["cursor"] local content = _arg_5_["content"] if content then - assert.are.same(content, core.first(vim.api.nvim_buf_get_lines(0, 0, 10, false))) + local function _6_() + local text = vim.api.nvim_buf_get_lines(0, 0, 10, false) + if (core.count(text) == 1) then + return core.first(text) + else + return text + end + end + assert.are.same(content, _6_()) else end if cursor then