summaryrefslogtreecommitdiff
path: root/dot_config/nvim/lua
diff options
context:
space:
mode:
authorChloƩ Vulquin <code@toast.bunkerlabs.net>2024-08-07 21:51:15 +0200
committerChloƩ Vulquin <code@toast.bunkerlabs.net>2024-08-07 21:51:15 +0200
commit23d6644dbe76e22d8558657bfede7b5d471d6383 (patch)
tree6ef0b96be5a3e840548d125a208bca4d262d8827 /dot_config/nvim/lua
parentnvim: move mini plugin into a single file (diff)
nvim: rework mixed-table macro
I didn't like that you couldn't keep mixing and matching, so I made it so you can. In the process, I also implemented even?, odd?, filter, mapcat, flat, and concat. Some of them didn't end up needing to exist, and the entire :toast. namespace does need to be cleaned up. Then again, it's not like I'm selling this like an alternative stdlib. I should really try and port all of clojure.core though, it'd be funny.
Diffstat (limited to 'dot_config/nvim/lua')
-rw-r--r--dot_config/nvim/lua/plugins/flash.lua10
-rw-r--r--dot_config/nvim/lua/plugins/os/init.lua2
-rw-r--r--dot_config/nvim/lua/plugins/telescope.lua2
-rw-r--r--dot_config/nvim/lua/toast/core.lua42
-rw-r--r--dot_config/nvim/lua/toast/table.lua16
5 files changed, 58 insertions, 14 deletions
diff --git a/dot_config/nvim/lua/plugins/flash.lua b/dot_config/nvim/lua/plugins/flash.lua
index ad4203e..3a8feea 100644
--- a/dot_config/nvim/lua/plugins/flash.lua
+++ b/dot_config/nvim/lua/plugins/flash.lua
@@ -1,17 +1,17 @@
-- [nfnl] Compiled from fnl/plugins/flash.fnl by https://github.com/Olical/nfnl, do not edit.
local function _1_()
- return (require("flash")).jump()
+ return require("flash").jump()
end
local function _2_()
- return (require("flash")).treesitter()
+ return require("flash").treesitter()
end
local function _3_()
- return (require("flash")).remote()
+ return require("flash").remote()
end
local function _4_()
- return (require("flash")).treesitter_search()
+ return require("flash").treesitter_search()
end
local function _5_()
- return (require("flash")).toggle()
+ return require("flash").toggle()
end
return {{"folke/flash.nvim", event = "VeryLazy", keys = {{"s", _1_, desc = "Flash", mode = {"n", "x", "o"}}, {"S", _2_, desc = "Flash Treesitter", mode = {"n", "x", "o"}}, {"r", _3_, desc = "Remote Flash", mode = "o"}, {"R", _4_, desc = "Flash Treesitter Search", mode = {"o", "x"}}, {"<c-s>", _5_, desc = "Toggle Flash Search", mode = "c"}}, opts = {modes = {search = {enabled = false}}}}}
diff --git a/dot_config/nvim/lua/plugins/os/init.lua b/dot_config/nvim/lua/plugins/os/init.lua
index c9b9cab..3cb9f52 100644
--- a/dot_config/nvim/lua/plugins/os/init.lua
+++ b/dot_config/nvim/lua/plugins/os/init.lua
@@ -1,2 +1,2 @@
-- [nfnl] Compiled from fnl/plugins/os/init.fnl by https://github.com/Olical/nfnl, do not edit.
-return require(("plugins.os." .. (jit.os):lower()))
+return require(("plugins.os." .. jit.os:lower()))
diff --git a/dot_config/nvim/lua/plugins/telescope.lua b/dot_config/nvim/lua/plugins/telescope.lua
index 683bdd7..f406c03 100644
--- a/dot_config/nvim/lua/plugins/telescope.lua
+++ b/dot_config/nvim/lua/plugins/telescope.lua
@@ -1,7 +1,7 @@
-- [nfnl] Compiled from fnl/plugins/telescope.fnl by https://github.com/Olical/nfnl, do not edit.
local function gen(key, fun, desc)
local function _1_()
- return (require("telescope.builtin"))[fun]()
+ return require("telescope.builtin")[fun]()
end
return {("<leader>f" .. key), _1_, desc = desc}
end
diff --git a/dot_config/nvim/lua/toast/core.lua b/dot_config/nvim/lua/toast/core.lua
index 6daae14..2e5ba69 100644
--- a/dot_config/nvim/lua/toast/core.lua
+++ b/dot_config/nvim/lua/toast/core.lua
@@ -17,6 +17,12 @@ end
local function number_3f(n)
return ("number" == type(n))
end
+local function even_3f(n)
+ return (number_3f(n) and (0 == (n % 2)))
+end
+local function odd_3f(n)
+ return (number_3f(n) and (0 ~= (n % 2)))
+end
local function every_3f(pred, xs)
local pass = true
for _, x in ipairs(xs) do
@@ -108,19 +114,49 @@ local function assoc(_3ft, ...)
return assoc(t, unpack(xs))
end
end
+local function filter(f, xs)
+ local out = {}
+ for k, v in ipairs(xs) do
+ if f(k, v) then
+ out = insert(out, v)
+ else
+ out = out
+ end
+ end
+ return out
+end
local function map(f, xs)
local out = {}
for _, v in ipairs((xs or {})) do
local mapped = f(v)
- local function _15_()
+ local function _16_()
if (0 == select("#", mapped)) then
return nil
else
return mapped
end
end
- out = insert(out, _15_())
+ out = insert(out, _16_())
end
return out
end
-return {dec = dec, inc = inc, ["empty?"] = empty_3f, ["nil?"] = nil_3f, ["number?"] = number_3f, ["every?"] = every_3f, drop = drop, first = first, last = last, group = group, assoc = assoc, map = map}
+local function mapcat(f, xs)
+ local out = {}
+ for _, v in ipairs(xs) do
+ for _0, v0 in ipairs(f(v)) do
+ table.insert(out, v0)
+ end
+ out = out
+ end
+ return out
+end
+local function flat(xs)
+ local _17_ = type(xs)
+ if (_17_ == "table") then
+ return mapcat(flat, xs)
+ else
+ local _ = _17_
+ return {xs}
+ end
+end
+return {dec = dec, inc = inc, ["empty?"] = empty_3f, ["nil?"] = nil_3f, ["number?"] = number_3f, ["even?"] = even_3f, ["odd?"] = odd_3f, ["every?"] = every_3f, drop = drop, first = first, last = last, group = group, flat = flat, assoc = assoc, filter = filter, map = map, mapcat = mapcat}
diff --git a/dot_config/nvim/lua/toast/table.lua b/dot_config/nvim/lua/toast/table.lua
index a898a5e..e9c1baf 100644
--- a/dot_config/nvim/lua/toast/table.lua
+++ b/dot_config/nvim/lua/toast/table.lua
@@ -2,9 +2,8 @@
local function from_pairs(t, _3fmut)
local out = (_3fmut or {})
for _, _1_ in ipairs(t) do
- local _each_2_ = _1_
- local k = _each_2_[1]
- local v = _each_2_[2]
+ local k = _1_[1]
+ local v = _1_[2]
out[k] = v
end
return out
@@ -13,5 +12,14 @@ local function insert(t, ...)
table.insert(t, ...)
return t
end
+local function concat(...)
+ local out = {}
+ for _, xs in ipairs({...}) do
+ for _0, v in ipairs(xs) do
+ insert(out, v)
+ end
+ end
+ return out
+end
local unpack = (table.unpack or unpack)
-return {["from-pairs"] = from_pairs, insert = insert, unpack = unpack}
+return {["from-pairs"] = from_pairs, insert = insert, unpack = unpack, concat = concat}