Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 17, 2023
1 parent 81400b1 commit 2dfda74
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 27 deletions.
77 changes: 71 additions & 6 deletions docs/sample.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,73 @@
(+ 1 2 3)
[1 2 3]
#{1 2 3 (+ 2 (+ 1 2))}
; TODO: Broken
; barf forward
; cxt: cursor within 1st form
; key: <)
; expected: (+ 1 (+ 2) 3)
(+ 1 (+ 2 3))

(+ 1 (+ 2 3 4))
; TODO: Broken
; barf backwards
; cxt: cursor within 1st form
; key: >(
; expected: (+ 1 + (2 3))
(+ 1 (+ 2 3))

(defn foo [x] x)
(defn bar [x] x)
; Wrap form
; cxt: cursor within
; key: <localleader>i
; expected: (| (+ 2 3)) *insert mode*
(+ 2 3)

; slurp forward
; cxt: cursor within 1st form
; key: >)
; expected: ((+ 1 2 3))
((+ 1 2) 3)

; slurp backward
; cxt: cursor within 1st form
; key: <(
; expected: (+ (1 + 2 3))
(+ 1 (+ 2 3))

; raise form
; cxt: cursor within 1st form
; key: <localleader>o
; expected: (+ 2 3)
(+ 1 (+ 2 3))

; Text object inner
; cxt: cursor within form
; key: dif
; expected: ()
(+ 2 3)

; Text object root inner
; cxt: cursor within second form
; key: diF
; expected: ()
(+ 2 (+ 3))

; Text object outer
; cxt: cursor within second form
; key: daf
; expected: (+ 2 )
(+ 2 (+ 3 4))

; Text object root outer
; cxt: cursor within second form
; key: daF
; expected: _
(+ 2 3)

; Insert head
; cxt: cursor within
; key: <localleader>h
; expected: (| + 2 3) *insert mode*
(+ 2 3)

; Insert tail
; cxt: cursor within
; key: <localleader>H
; expected: (+ 2 3 |) *insert mode*
(+ 2 3)
3 changes: 2 additions & 1 deletion fnl/formedit/insertion.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
[start-row start-col] [(form:start)]
start-col (+ start-col offset)]
(vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col [" "])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col 1)])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) start-col])
(vim.api.nvim_feedkeys :i :n true)))

(fn tail []
(let [form (find.form)
[end-row end-col] [(form:end_)]
end-col (- end-col 1)]
(vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [" "])
(vim.api.nvim_win_set_cursor 0 [(+ end-row 1) end-row])
(vim.api.nvim_feedkeys :i :n true)))

{: head : tail}
2 changes: 1 addition & 1 deletion fnl/formedit/wrap.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[start-row start-col end-row end-col] [(form:range)]]
(vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [")"])
(vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col ["( "])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col offset 1)])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) (+ start-col offset)])
(vim.api.nvim_feedkeys :i :n true)))

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

(describe "tail insertion"
(fn []
Expand All @@ -35,9 +35,11 @@
(fn []
(h.setup {:content "(1)" :cursor [1 0]})
(h.feedkeys tail-keymap)
(h.expect {:content "(1 )" :cursor [1 0]})))
(h.expect {:content "(1 )" :cursor [1 3]})))
(it :sub
(fn []
(h.setup {:content "(1 (2))" :cursor [1 4]})
(h.setup {:content "(1 (2))" :cursor [1 3]})
(h.feedkeys tail-keymap)
(h.expect {:content "(1 (2 ))" :cursor [1 3]})))))
(h.expect {:content "(1 (2 ))" :cursor [1 6]})))))

(print "foo")
6 changes: 4 additions & 2 deletions fnl/spec/wrap_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
(fn []
(h.setup {:content "(1)" :cursor [1 0]})
(h.feedkeys keymap)
(h.expect {:content "( (1))" :cursor [1 1]})))
(h.expect {:content "( (1))" :cursor [1 0]})))
(it "sub form"
(fn []
(h.setup {:content "(1 (2))" :cursor [1 3]})
(h.feedkeys keymap)
(h.expect {:content "(1 ( (2)))" :cursor [1 4]})))))
(h.expect {:content "(1 ( (2)))" :cursor [1 3]})))))


3 changes: 2 additions & 1 deletion 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/wrap.lua

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

15 changes: 8 additions & 7 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_spec.lua

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

0 comments on commit 2dfda74

Please sign in to comment.