-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(local find (require :formedit.find)) | ||
(local ts (require :vim.treesitter)) | ||
|
||
(fn forward [] | ||
(let [form (find.form) | ||
[row col] [(form:end_)] | ||
col (- col 1) | ||
sibling (form:next_sibling) | ||
sibling-text (ts.get_node_text sibling 0) | ||
sibling-text (.. " " sibling-text) | ||
[sibling-row-start sibling-col-start sibling-row-end sibling-col-end] [(sibling:range)]] | ||
(vim.api.nvim_buf_set_text 0 sibling-row-start (- sibling-col-start 1) | ||
sibling-row-end sibling-col-end [""]) | ||
(vim.api.nvim_buf_set_text 0 row col row col [sibling-text]))) | ||
|
||
(fn backward [] | ||
(let [form (find.form) | ||
[row col] [(form:start)] | ||
sibling (form:prev_sibling) | ||
col (+ col 1) | ||
sibling-text (ts.get_node_text sibling 0) | ||
sibling-text (.. sibling-text " ") | ||
[sibling-row-start sibling-col-start sibling-row-end sibling-col-end] [(sibling:range)]] | ||
(vim.api.nvim_buf_set_text 0 row col row col [sibling-text]) | ||
(vim.api.nvim_buf_set_text 0 sibling-row-start sibling-col-start | ||
sibling-row-end (+ sibling-col-end 1) [""]))) | ||
|
||
{: forward : backward} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(local {: describe : it : before_each} (require :plenary.busted)) | ||
(local h (require :spec.helper)) | ||
(local slurp (require :formedit.slurp)) | ||
|
||
(local forward-keymap ">)") | ||
(local backward-keymap "<(") | ||
|
||
(describe "slurp forward" | ||
(fn [] | ||
(before_each (fn [] | ||
(vim.keymap.set :n forward-keymap slurp.forward))) | ||
(it :element | ||
(fn [] | ||
(h.setup {:content "((1) 2)" :cursor [1 1]}) | ||
(h.feedkeys forward-keymap) | ||
(h.expect {:content "((1 2))" :cursor [1 1]}))) | ||
(it :form | ||
(fn [] | ||
(h.setup {:content "((1) (+ 2 3))" :cursor [1 1]}) | ||
(h.feedkeys forward-keymap) | ||
(h.expect {:content "((1 (+ 2 3)))" :cursor [1 1]}))))) | ||
|
||
|
||
(describe "slurp backwards" | ||
(fn [] | ||
(before_each (fn [] | ||
(vim.keymap.set :n backward-keymap slurp.backward))) | ||
(it :element | ||
(fn [] | ||
(h.setup {:content "(1 (2))" :cursor [1 3]}) | ||
(h.feedkeys backward-keymap) | ||
(h.expect {:content "((1 2))" :cursor [1 3]}))) | ||
(it :form | ||
(fn [] | ||
(h.setup {:content "((1) (+ 2 3))" :cursor [1 5]}) | ||
(h.feedkeys backward-keymap) | ||
(h.expect {:content "(((1) + 2 3))" :cursor [1 5]}))))) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.