summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-12-23 23:00:42 +0600
committerunwox <me@unwox.com>2024-12-23 23:00:42 +0600
commitc2bf2853b4319acb2a5e6b90e71014552bc67aec (patch)
treee9e42775f94f0c7c6845cefb1eff15e5553fb7ce
parentaa9460bb7132571e66171884b6d1f4625399fb6d (diff)
implement module reloading
-rw-r--r--.nvim.lua14
-rw-r--r--bin/serve.fnl21
2 files changed, 29 insertions, 6 deletions
diff --git a/.nvim.lua b/.nvim.lua
index 50bdee2..a0e5777 100644
--- a/.nvim.lua
+++ b/.nvim.lua
@@ -1,14 +1,16 @@
-
vim.keymap.set("n", ",tf", ":!./run.sh fetch<cr>")
vim.keymap.set("n", ",tt", ":!./run.sh serve<cr>")
+vim.keymap.set("n", ",rr", function ()
+ local module = vim.fn.expand("%"):gsub("/", "."):gsub(".fnl$", "")
+ vim.repl.send({args = "(reload :" .. module .. ")"})
+ vim.fn.system("qutebrowser :reload")
+end)
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.fnl"},
callback = function()
- vim.repl.configs.fennel.cmd = {"fennel"}
- vim.opt.lispwords:append("local")
- vim.opt.lispwords:append("fn")
- vim.opt.lispwords:append("set")
- vim.opt.lispwords:append("if")
+ vim.repl.fennel.cmd = {"go", "run", "-tags=fts5,jit", "../.",
+ "-n", "1", "-D", "main.lua", "bin/serve.fnl"}
+ vim.repl.fennel.filters = {}
end,
})
diff --git a/bin/serve.fnl b/bin/serve.fnl
index b18d842..de5b4b3 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -3,6 +3,24 @@
(when _G.unpack
(tset table :unpack _G.unpack))
+(set _G.reload
+ (fn [module]
+ (local old (require module))
+ (tset package :loaded module nil)
+ (local (ok? new) (pcall require module))
+ (if (not ok?)
+ (do
+ (tset package :loaded module old)
+ (error new))
+ (when (= (type new) :table)
+ (do
+ (each [k v (pairs new)]
+ (tset old k v))
+ (each [k (pairs old)]
+ (when (not (. new k))
+ (tset old k nil)))
+ (tset package :loaded module old))))))
+
(fn ends-with [str end]
(= (string.sub str (- (# end))) end))
@@ -32,3 +50,6 @@
(luna.router.route "GET /" router)
(luna.router.static "GET /static/" "static/")
+
+(when luna.debug
+ (luna.evalfn (fn [code] (fennel.eval code {:env _G}))))