-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kbtz
committed
Aug 23, 2023
1 parent
393e8b2
commit 72ebe66
Showing
6 changed files
with
101 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
@ |