Skip to content

Commit

Permalink
nvim: wip lua to yue
Browse files Browse the repository at this point in the history
  • Loading branch information
kbtz committed Aug 23, 2023
1 parent 393e8b2 commit 72ebe66
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 82 deletions.
89 changes: 43 additions & 46 deletions cfg/nvim/base
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
global kind, word, spairs, is
global *

-- error handling
local clean = true
err = (msg, lvl = 2) ->
if clean
error msg, lvl
clean = false

-- index symbols
kind = {}
kind = {'kind'}

-- error handling
err = (msg, lvl = 2) -> error msg, lvl
-- type guard helpers
local primitive =
num: 'number', bol: 'boolean', str: 'string',
fun: 'function', tbl: 'table', udt: 'userdata'

-- word containers
word =
<call>: (name) =>
err "Word recursion #{@name} -> #{name}" if is.wrd @
err 'Non string word name' unless is.str name
<>: word.<>, [kind]: 'wrd', :name, value: true
<unm>: =>
@value = false
@
<add>: (value) =>
err 'Can only add words' unless is.wrd value
@value = { @name } if not is.tbl @value
@value[] = value.name
@
<div>: (value) =>
value = value.name if is.wrd value
@value = value
@
<tostring>: => switch type(@value)
when 'boolean', 'table' then @name
else tostring(@value)
--[[ toggle
call next
cycle default v f
store cycle indexes
restore save
]]
-- bare strings as words
_G.<index> = (name) => if bare then word name


kpair = (kt) -> (t, k) ->
is =
<call>: (q, x, t = type(x), p = primitive[q]) =>
t == p or (t == 'table' and q == x[kind])
<index>: (q, s = @) => {
<call>: (x) => s q, x
<index>: (r) => (x, y) -> s(q, x) and s(r, y)
}

-- iterators for specific key types
kpair = (tg) -> (t, k) ->
k, v = next(t, k)
k, v = next(t, k) while v? and not kt k
k, v = next(t, k) while v? and not tg k
k, v

-- iterators for specific key types
spairs = (t) -> kpair(is.str), t
wpairs = (t) -> kpair(is.wrd), t

-- type guard helpers
primitive =
num: 'number', bol: 'boolean', str: 'string',
fun: 'function', tbl: 'table', udt: 'userdata'
is =
<call>: (x, q, t = type(x), p = primitive[q]) =>
t == p or (t == 'table' and q == x[kind])
<index>: (q) => (x) -> @ x, q
-- string iterators
local str = ''.<index>
str.words = => @\gmatch('%S+')

-- augmented bare words
local word
_G.<index> = (n) => word.create n

word =
create: (n, k = 'wrd') ->
<>: word.<>, [kind]: k, :n, v: true
<tostring>: => tostring(@n)
<call>: (w) => @n .. ' ' .. (w.n or w)
<unm>: =>
@v = false
@

-- branded words
brand = (b) -> <index>: (n) => word.create n, b.n or b
34 changes: 15 additions & 19 deletions cfg/nvim/conf
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
opt {
hlsearch
-compatible
-wrap
with brand var
opt {
hlsearch
-compatible
-wrap

[number + rnu]: linenumbers

softtabstop: 0
[tabstop + shiftwidth]: tabsize,
[expandtab]: -spaces,
[number rnu]: .linenumbers
softtabstop: 0
expandtab: false --.spaces
[tabstop sw]: .tabsize

clipboard/unnamedplus
belloff/spell
clipboard: unnamedplus
belloff: spell

[list]: -seechars
[listchars]: chars
}, {
tabsize: { 2, 4 }
chars:
* lead: '', tab: '├─', eol: ''
* lead: '', tab: '├─', eol: ''
}
list: .seechars
listchars: .chars
}
4 changes: 3 additions & 1 deletion cfg/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'meta'
require 'moon'

use { base, nvim, conf }

vim.keymap.set('n', 'mm', ':set ft=lua<CR>|:set ts=4<CR>|:set sw=4<CR>')
3 changes: 1 addition & 2 deletions cfg/nvim/meta.lua → cfg/nvim/moon.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- include extensionless config files
package.path = vim.fn.stdpath'config' .. '/?;' .. package.path

-- allow bare strings
bare = true
-- basic bare words
setmetatable(_G, { __index = function(_, key) return key end })

function use(files)
Expand Down
41 changes: 27 additions & 14 deletions cfg/nvim/nvim
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
-- neovim api aliases and helpers
global opt, tgl
global opt

toggle = (k, v) ->
k = is.tbl(k.value) and k.value or k.name
v = tgl[v.name]?[1] or v.value
k, v
var =
cur: {}
set: (o, v) =>
@cur[v.n] ??= :o, i: 1
v.v = @get v.n
print resolved, v.n, to, v.v
v.v
get: (n) =>
d = @def[n] or @def.flag
d[@cur[n].i]
def:
flag: { true, false }
tabsize: { 2, 4 }
chars:
* lead: '', tab: '├─', eol: nil
* lead: '', tab: '├─', eol: ''

opt = (input, toggles) ->
tgl = toggles -- TODO
for k, v in next, input
k, v = toggle k, v if is.wrd k
{ name: k, value: v } = v if is.num(k) and is.wrd(v)
if is.str k then vim.opt[k] = v
else vim.opt[kk] = v for kk in *k

tgl = {}
opt = (t) ->
for k, v in next, t
{ n: k, :v } = v if is.num.wrd k, v
v = v.n if is.wrd v
v = var\set k, v if is.var v
vim.opt[o] = v for o in k\words!

print Finished conf
for n, t in next, var.cur
print n, t.i, t.o
12 changes: 12 additions & 0 deletions cfg/nvim/word
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- augmented bare words
local word
_G.<index> = (n) =>
<>: word.<>, [kind]: 'wrd', :n, v: true

word =
<tostring>: => tostring(@n)
<index>: (k) => @n, @v if k == 'nv'
<call>: (w) => @n .. ' ' .. (w.n or w)
<unm>: =>
@v = false
@

0 comments on commit 72ebe66

Please sign in to comment.