Skip to content

Commit

Permalink
Delete around form
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 12, 2023
1 parent 6519633 commit 93b0880
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
10 changes: 10 additions & 0 deletions fnl/formedit/selection.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(local tree (require :formedit.tree))
(local ts (require :nvim-treesitter.ts_utils))

(fn delete-form []
(let [node (ts.get_node_at_cursor)
form (tree.get-form node)
[start-row start-col end-row end-col] [(form:range)]]
(vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col {})))

{: delete-form}
38 changes: 38 additions & 0 deletions fnl/spec/selection_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(local {: describe : it} (require :plenary.busted))
(local h (require :spec.helper))
(local tree (require :formedit.tree))
(local assert (require :luassert.assert))
(local selection (require :formedit.selection))
(local ts (require :nvim-treesitter.ts_utils))

(describe :selection
(fn []
(it :list
(fn []
(h.setup {:content "(a)" :cursor [1 1]})
(let [node (ts.get_node_at_cursor)
form (tree.get-form node)]
(assert.are.same [0 0 0 3] [(form:range)]))))))

(describe "delete around"
(fn []
(it :list
(fn []
(h.setup {:content "(1)" :cursor [1 1]})
(selection.delete-form)
(h.expect {:content "" :cursor [1 0]})))
(it :vector
(fn []
(h.setup {:content "[1]" :cursor [1 1]})
(selection.delete-form)
(h.expect {:content "" :cursor [1 0]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 1]})
(selection.delete-form)
(h.expect {:content "" :cursor [1 0]})))
(it "anonymous function"
(fn []
(h.setup {:content "#(fn [x] x)" :cursor [1 1]})
(selection.delete-form)
(h.expect {:content "" :cursor [1 0]})))))
2 changes: 0 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ test: prepare
-u lua/spec/init.lua \
-c "PlenaryBustedDirectory lua/spec { minimal_init='lua/spec/init.lua', sequential=true }"


file feature: prepare
./.build/nvim/bin/nvim --version
./.build/nvim/bin/nvim \
Expand All @@ -52,4 +51,3 @@ focus feature: prepare

watch feature:
fswatch -o lua/formedit/{{feature}}.lua lua/spec/{{feature}}_spec.lua | xargs -n1 -I{} just file {{feature}}

14 changes: 14 additions & 0 deletions lua/formedit/selection.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions lua/spec/selection_spec.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93b0880

Please sign in to comment.