Skip to content

Commit

Permalink
Handle slurp set
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 16, 2023
1 parent b798583 commit 0f87914
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# Form edit

Paredit in fennel
Paredit in Fennel for Clojure

## Getting started
## Features

- Form text objects
- Lists (s-exp, quoted list), vector, set are all under one text object
- so instead of `di(` `di[` `di{` just `dif` (or any other text object command)
- `f` for current form. `F` for root form
- Slurp
- Bring in element/form into your form
- Raise
- Remove parent form and replace with current form
- Wrap
- Add form around current form
- Insertion
- Move cursor to begining/end for form in insert mode

## Todo

- [ ] - Inner select
- [ ] - Barf

## Dev Getting started

```bash
./scripts/nfnl # To download nfnl
just test # Run tests
just watch {featuer} # Run watch tests for feature
```

[ ] - inner select - Get all named value children on form
[ ] - slurp/barf - ?

## Unlicensed

Find the full [Unlicense][unlicense] in the `UNLICENSE` file, but here's a
Expand Down
4 changes: 3 additions & 1 deletion fnl/formedit/slurp.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
(fn backward []
(let [form (find.form)
[row col] [(form:start)]
type (form:type)
offset (. find.insert-offset type)
col (+ col offset)
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)]]
Expand Down
14 changes: 12 additions & 2 deletions fnl/spec/slurp_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
(fn []
(h.setup {:content "((1) (+ 2 3))" :cursor [1 1]})
(h.feedkeys forward-keymap)
(h.expect {:content "((1 (+ 2 3)))" :cursor [1 1]})))))
(h.expect {:content "((1 (+ 2 3)))" :cursor [1 1]})))
(it :set
(fn []
(h.setup {:content "(#{1} 2)" :cursor [1 1]})
(h.feedkeys forward-keymap)
(h.expect {:content "(#{1 2})" :cursor [1 1]})))))


(describe "slurp backwards"
Expand All @@ -34,4 +39,9 @@
(fn []
(h.setup {:content "((1) (+ 2 3))" :cursor [1 5]})
(h.feedkeys backward-keymap)
(h.expect {:content "(((1) + 2 3))" :cursor [1 5]})))))
(h.expect {:content "(((1) + 2 3))" :cursor [1 5]})))
(it :set
(fn []
(h.setup {:content "(1 #{2})" :cursor [1 3]})
(h.feedkeys backward-keymap)
(h.expect {:content "(#{1 2})" :cursor [1 3]})))))
4 changes: 3 additions & 1 deletion lua/formedit/slurp.lua

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

30 changes: 21 additions & 9 deletions lua/spec/slurp_spec.lua

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

0 comments on commit 0f87914

Please sign in to comment.