Skip to content

Commit

Permalink
Wrap and insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 15, 2023
1 parent bd1a28f commit 37e8e27
Show file tree
Hide file tree
Showing 21 changed files with 7,036 additions and 32 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Paredit in fennel
./scripts/nfnl # To download nfnl
```

## Todo

- [ ] Outer root deletes everything
- [ ] insert head cursor off by one to the left
- [ ] wrap cursor off by one to the left

## Unlicensed

Find the full [Unlicense][unlicense] in the `UNLICENSE` file, but here's a
Expand Down
7 changes: 7 additions & 0 deletions docs/sample.clj
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
(defn foo [x y]
(+ x y))

(defn bar [x y]
(+ x y))

(+ 1 2 3)
'(1 2 3)
[1 2 3]
#{1 2 3}
14 changes: 13 additions & 1 deletion fnl/formedit/find.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
:set_lit true
:anon_fn_lit true})

(local start-offset {:list_lit 0
:vec_lit 0
:map_lit 0
:set_lit 1
:anon_fn_lit 1})

(local insert-offset {:list_lit 1
:vec_lit 1
:map_lit 1
:set_lit 2
:anon_fn_lit 2})

;; Tree search
(fn find-current-form [node]
(if (. forms (node:type))
Expand Down Expand Up @@ -33,4 +45,4 @@
; [end-row end-col] [(: (. (form:field :close) 1) :start)]]
; [open-row open-col end-row end-col]))

{: form : root}
{: form : root : insert-offset : start-offset}
6 changes: 6 additions & 0 deletions fnl/formedit/init.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(local find (require :formedit.find))
(local insertion (require :formedit.insertion))
(local select (require :formedit.select))
(local wrap (require :formedit.wrap))

{: find : insertion : select : wrap}
6 changes: 4 additions & 2 deletions fnl/formedit/insertion.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

(fn head []
(let [form (find.form)
start-offset (. find.start-offset (form:type))
insert-offset (. find.start-offset (form:type))
[start-row start-col _ _] (range form)]
(vim.api.nvim_win_set_cursor 0 [start-row start-col])
(vim.api.nvim_win_set_cursor 0 [start-row (+ start-col start-offset)])
(vim.api.nvim_command "normal! a ")
(vim.api.nvim_win_set_cursor 0 [start-row start-col])
(vim.api.nvim_win_set_cursor 0 [start-row (+ start-col insert-offset)])
(vim.api.nvim_feedkeys :i :n true)))

(fn tail []
Expand Down
7 changes: 4 additions & 3 deletions fnl/formedit/wrap.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
(let [[start-row start-col end-row end-col] [(form:range)]]
[(+ start-row 1) start-col (+ end-row 1) end-col]))

(fn form-head []
(fn head []
(let [form (find.form)
insert-offset (. find.start-offset (form:type))
[start-row start-col end-row end-col] (range form)]
(vim.api.nvim_win_set_cursor 0 [end-row end-col])
(vim.api.nvim_command "normal! i)")
(vim.api.nvim_win_set_cursor 0 [start-row start-col])
(vim.api.nvim_command "normal! i( ")
(vim.api.nvim_win_set_cursor 0 [start-row start-col])
(vim.api.nvim_win_set_cursor 0 [start-row (+ start-col insert-offset)])
(vim.api.nvim_feedkeys :i :n true)))

{: form-head}
{: head}
9 changes: 7 additions & 2 deletions fnl/spec/insertion_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
(h.setup {:content "(1)" :cursor [1 0]})
(h.feedkeys head-keymap)
(h.expect {:content "( 1)" :cursor [1 0]})))
(it :sub
(it :set
(fn []
(h.setup {:content "(1 (2))" :cursor [1 4]})
(h.setup {:content "#{1}" :cursor [1 0]})
(h.feedkeys head-keymap)
(h.expect {:content "#{ 1}" :cursor [1 0]})))
(it "sub form"
(fn []
(h.setup {:content "(1 (2))" :cursor [1 3]})
(h.feedkeys head-keymap)
(h.expect {:content "(1 ( 2))" :cursor [1 2]})))))

Expand Down
2 changes: 1 addition & 1 deletion fnl/spec/wrap_form_spec.fnl → fnl/spec/wrap_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(fn []
(before_each (fn []
(set vim.g.maplocalleader keymap)
(vim.keymap.set :n keymap wrap.form-head)))
(vim.keymap.set :n keymap wrap.head)))
(it "form head"
(fn []
(h.setup {:content "(1)" :cursor [1 0]})
Expand Down
4 changes: 3 additions & 1 deletion lua/formedit/find.lua

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

6 changes: 6 additions & 0 deletions lua/formedit/init.lua

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

6 changes: 4 additions & 2 deletions lua/formedit/insertion.lua

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

2 changes: 1 addition & 1 deletion lua/formedit/nfnl/callback.lua

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

12 changes: 8 additions & 4 deletions lua/formedit/nfnl/init.lua

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

7 changes: 4 additions & 3 deletions lua/formedit/wrap.lua

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

26 changes: 16 additions & 10 deletions lua/spec/insertion_spec.lua

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

4 changes: 2 additions & 2 deletions lua/spec/wrap_form_spec.lua → lua/spec/wrap_spec.lua

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

3 changes: 3 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

script/fennel.bb --compile
3 changes: 3 additions & 0 deletions script/bootstrap-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

script/fennel.bb --files | entr script/fennel.bb --compile
Loading

0 comments on commit 37e8e27

Please sign in to comment.