Skip to content

Commit 6527d49

Browse files
committed
Merge branch 'conjure-eval-update'
2 parents dbdc4ad + ba5c6f4 commit 6527d49

24 files changed

+550
-431
lines changed

fnl/conjure/buffer.fnl

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
1-
(local {: autoload} (require :conjure.nfnl.module))
2-
(local nvim (autoload :conjure.aniseed.nvim))
1+
(local {: autoload : define} (require :conjure.nfnl.module))
32
(local core (autoload :conjure.nfnl.core))
43
(local text (autoload :conjure.text))
54

6-
(fn unlist [buf]
5+
(local M (define :conjure.buffer))
6+
7+
(fn M.unlist [buf]
78
"The buflisted attribute is reset when a new window is opened. Since the
89
buffer upsert is decoupled from the window we have to run this whenever we
910
split the buffer into some new window."
10-
(nvim.buf_set_option buf :buflisted false))
11+
(vim.api.nvim_buf_set_option buf :buflisted false))
1112

12-
(fn resolve [buf-name]
13-
(nvim.buf_get_name (nvim.fn.bufnr buf-name)))
13+
(fn M.resolve [buf-name]
14+
(vim.api.nvim_buf_get_name (vim.fn.bufnr buf-name)))
1415

15-
(fn upsert-hidden [buf-name new-buf-fn]
16-
(let [(ok? buf) (pcall nvim.fn.bufnr buf-name)
17-
loaded? (and ok? (nvim.buf_is_loaded buf))]
16+
(fn M.upsert-hidden [buf-name new-buf-fn]
17+
(let [(ok? buf) (pcall vim.fn.bufnr buf-name)
18+
loaded? (and ok? (vim.api.nvim_buf_is_loaded buf))]
1819

1920
;; This state happens when the user unloads the buffer somehow.
2021
;; It still exists but is in a bad state, we delete and start over.
2122
(when (and (not= -1 buf) (not loaded?))
22-
(nvim.buf_delete buf {}))
23+
(vim.api.nvim_buf_delete buf {}))
2324

2425
(if (or (= -1 buf) (not loaded?))
2526
(let [buf (if loaded?
2627
buf
27-
(let [buf (nvim.fn.bufadd buf-name)]
28-
(nvim.fn.bufload buf)
28+
(let [buf (vim.fn.bufadd buf-name)]
29+
(vim.fn.bufload buf)
2930
buf))]
30-
(nvim.buf_set_option buf :buftype :nofile)
31-
(nvim.buf_set_option buf :bufhidden :hide)
32-
(nvim.buf_set_option buf :swapfile false)
33-
(unlist buf)
31+
(vim.api.nvim_buf_set_option buf :buftype :nofile)
32+
(vim.api.nvim_buf_set_option buf :bufhidden :hide)
33+
(vim.api.nvim_buf_set_option buf :swapfile false)
34+
(M.unlist buf)
3435
(when new-buf-fn
3536
(new-buf-fn buf))
3637
buf)
3738
buf)))
3839

39-
(fn empty? [buf]
40-
(and (<= (nvim.buf_line_count buf) 1)
41-
(= 0 (core.count (core.first (nvim.buf_get_lines buf 0 -1 false))))))
40+
(fn M.empty? [buf]
41+
(and (<= (vim.api.nvim_buf_line_count buf) 1)
42+
(= 0 (core.count (core.first (vim.api.nvim_buf_get_lines buf 0 -1 false))))))
4243

43-
(fn replace-range [buf range s]
44+
(fn M.replace-range [buf range s]
4445
(let [start-line (core.dec (core.get-in range [:start 1]))
4546
end-line (core.get-in range [:end 1])
4647
start-char (core.get-in range [:start 2])
4748
end-char (core.get-in range [:end 2])
4849

4950
new-lines (text.split-lines s)
50-
old-lines (nvim.buf_get_lines buf start-line end-line false)
51+
old-lines (vim.api.nvim_buf_get_lines buf start-line end-line false)
5152

5253
head (string.sub (core.first old-lines) 1 start-char)
5354
tail (string.sub (core.last old-lines) (+ end-char 2))]
@@ -60,15 +61,15 @@
6061
new-lines (core.count new-lines)
6162
(fn [l] (.. l tail)))
6263

63-
(nvim.buf_set_lines buf start-line end-line false new-lines)))
64+
(vim.api.nvim_buf_set_lines buf start-line end-line false new-lines)))
6465

65-
(fn append-prefixed-line [buf [tl tc] prefix body]
66+
(fn M.append-prefixed-line [buf [tl tc] prefix body]
6667
"Appends a string to the end of the current line, or the one below this one
6768
if there's already the same suffix on the end. If there's already a matching
6869
suffix on the end of this line and the one below, it will insert another
6970
below that last one and so on."
7071
(let [tl (core.dec tl)
71-
[head-line & lines] (nvim.buf_get_lines buf tl -1 false)
72+
[head-line & lines] (vim.api.nvim_buf_get_lines buf tl -1 false)
7273
to-append (text.prefixed-lines body prefix {})]
7374
(if (head-line:find prefix tc)
7475
(let [[new-tl lines]
@@ -82,8 +83,8 @@
8283
(core.take-while core.identity)
8384
(core.last))
8485
[tl (core.concat [head-line] to-append)])]
85-
(nvim.buf_set_lines buf new-tl (core.inc new-tl) false lines))
86-
(nvim.buf_set_lines
86+
(vim.api.nvim_buf_set_lines buf new-tl (core.inc new-tl) false lines))
87+
(vim.api.nvim_buf_set_lines
8788
buf tl
8889
(core.inc tl)
8990
false
@@ -93,9 +94,4 @@
9394
[head-line]
9495
to-append))))))
9596

96-
{: unlist
97-
: resolve
98-
: upsert-hidden
99-
: empty?
100-
: replace-range
101-
: append-prefixed-line}
97+
M

fnl/conjure/dynamic.fnl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
(local {: autoload} (require :conjure.nfnl.module))
2-
(local a (autoload :conjure.aniseed.core))
1+
(local {: autoload : define} (require :conjure.nfnl.module))
2+
(local core (autoload :conjure.nfnl.core))
3+
4+
(local M (define :conjure.dynamic))
35

46
(local get-stack-key :conjure.dynamic/get-stack)
57

68
(fn assert-value-function! [value]
79
(when (not= :function (type value))
810
(error "conjure.dynamic values must always be wrapped in a function")))
911

10-
(fn new [base-value]
12+
(fn M.new [base-value]
1113
(assert-value-function! base-value)
12-
(var stack [base-value])
13-
(fn [x ...]
14-
(if (= get-stack-key x) stack
15-
((a.last stack) x ...))))
14+
(let [stack [base-value]]
15+
(fn [x ...]
16+
(if (= get-stack-key x)
17+
stack
18+
((core.last stack) x ...)))))
1619

1720
(fn run-binds! [f binds]
18-
(a.map-indexed
21+
(core.map-indexed
1922
(fn [[dyn new-value]]
2023
(assert-value-function! new-value)
2124
(f (dyn get-stack-key) new-value))
2225
binds))
2326

24-
(fn bind [binds f ...]
27+
(fn M.bind [binds f ...]
2528
(run-binds! table.insert binds)
2629
(let [(ok? result) (pcall f ...)]
2730
(run-binds! #(table.remove $1) binds)
2831
(if ok?
2932
result
3033
(error result))))
3134

32-
(fn set! [dyn new-value]
35+
(fn M.set! [dyn new-value]
3336
(assert-value-function! new-value)
3437
(let [stack (dyn get-stack-key)
35-
depth (a.count stack)]
36-
(a.assoc stack depth new-value))
38+
depth (core.count stack)]
39+
(core.assoc stack depth new-value))
3740
nil)
3841

39-
(fn set-root! [dyn new-value]
42+
(fn M.set-root! [dyn new-value]
4043
(assert-value-function! new-value)
41-
(a.assoc (dyn get-stack-key) 1 new-value)
44+
(core.assoc (dyn get-stack-key) 1 new-value)
4245
nil)
4346

44-
{: new
45-
: bind
46-
: set!
47-
: set-root!}
47+
M

0 commit comments

Comments
 (0)