this repo has no description
1-- Fennel loader, default one do not work well with NeoVim so there is custom
2-- one
3_G.fennel = require('fennel')
4
5-- Load Fennel modules
6local function fennel_loader(name)
7 local basename = name:gsub('%.', '/')
8 local paths = {"fnl/"..basename..".fnl", "fnl/"..basename.."/init.fnl"}
9
10 for _, path in ipairs(paths) do
11 local found = vim.api.nvim_get_runtime_file(path, false)
12 if #found > 0 then
13 return function() return fennel.dofile(found[1], {compilerEnv = _G}) end, found[1]
14 end
15 end
16
17 return nil
18end
19table.insert(package.loaders, 1, fennel_loader)
20
21-- Load Fennel macros
22local function fennel_paths(suffixes)
23 local paths = ""
24 for _, dir in pairs(vim.api.nvim_get_runtime_file("fnl/", true)) do
25 for _, suffix in pairs(suffixes) do
26 paths = paths .. ";" .. dir .. "?" .. suffix .. ".fnl"
27 end
28 end
29
30 return paths
31end
32fennel["path"] = fennel["path"] .. fennel_paths({"", "/init"})
33fennel["macro-path"] = fennel["macro-path"] .. fennel_paths({"", "/macro-init", "/init"})
34
35debug.traceback = fennel.traceback
36
37-- Command-mode Fennel execution
38vim.api.nvim_create_user_command('Fnl', function(arg) fennel.eval(arg.args) end, {nargs = '*'})
39vim.api.nvim_create_user_command('FnlFile', function(arg) print(fennel.view(arg.args)) end, {nargs = 1})
40
41_G.reloadable = {}
42
43local function reload_init()
44 for _, name in pairs(_G.reloadable) do
45 package.loaded[name] = nil
46 end
47
48 for _, init in pairs(vim.api.nvim_get_runtime_file("init.fnl", false)) do
49 fennel.dofile(init, {compilerEnv = _G})
50 end
51end
52
53vim.api.nvim_create_user_command('ReloadInit', reload_init, {})
54
55reload_init()