summaryrefslogtreecommitdiff
path: root/.config/vis
diff options
context:
space:
mode:
Diffstat (limited to '.config/vis')
-rw-r--r--.config/vis/lexers/execline.lua64
-rw-r--r--.config/vis/lexers/hare.lua82
-rw-r--r--.config/vis/lexers/roff.lua32
-rw-r--r--.config/vis/themes/flexoki.lua125
-rw-r--r--.config/vis/visrc.lua61
5 files changed, 364 insertions, 0 deletions
diff --git a/.config/vis/lexers/execline.lua b/.config/vis/lexers/execline.lua
new file mode 100644
index 0000000..cb79c8d
--- /dev/null
+++ b/.config/vis/lexers/execline.lua
@@ -0,0 +1,64 @@
+-- Copyright 2023 Sam Nystrom <sam@samnystrom.dev>
+-- Execline LPeg lexer.
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'execline'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local comment = token(l.COMMENT, l.starts_line(S('#')) * l.nonnewline^0)
+
+-- Strings.
+local sq_str = l.range("'")
+local dq_str = l.range('"')
+local string = token(l.STRING, sq_str + dq_str)
+
+-- Numbers.
+local dec = l.digit^1 * ('_' * l.digit^1)^0
+local oct_num = '0' * S('01234567_')^1
+local integer = S('+-')^-1 * (l.hex_num + oct_num + dec)
+local number = token(l.NUMBER, (l.float + integer))
+
+-- Keywords.
+local keyword = token(l.KEYWORD, word_match{
+ 'execlineb', 'execline-cd', 'posix-cd', 'execline-umask', 'posix-umask',
+ 'emptyenv', 'envfile', 'export', 'unexport', 'fdclose', 'fdblock', 'fdmove',
+ 'fdswap', 'fdreserve', 'redirfd', 'piperw', 'heredoc', 'wait', 'getcwd',
+ 'getpid', 'exec', 'tryexec', 'exit', 'trap', 'withstdinas',
+ 'foreground', 'background', 'case', 'if', 'ifelse', 'ifte', 'ifthenelse',
+ 'backtick', 'pipeline', 'runblock',
+ 'define', 'importas', 'elglob', 'elgetpositionals', 'multidefine',
+ 'multisubstitute',
+ 'forx', 'forstdin', 'forbacktickx', 'loopwhilex',
+ 'elgetopt', 'shift', 'dollarat',
+ 'eltest', 'homeof',
+ 'execline'
+})
+
+-- Identifiers.
+local identifier = token(l.IDENTIFIER, l.word)
+
+local variable = token(l.VARIABLE, '$' * (l.word + l.range('{}', true, true, true)))
+
+-- Operators.
+local operator = token(l.OPERATOR, S('{}'))
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'identifier', identifier},
+ {'string', string},
+ {'comment', comment},
+ {'number', number},
+ {'variable', variable},
+ {'operator', operator},
+}
+
+M._LEXBYLINE = true
+
+return M
diff --git a/.config/vis/lexers/hare.lua b/.config/vis/lexers/hare.lua
new file mode 100644
index 0000000..0aacad3
--- /dev/null
+++ b/.config/vis/lexers/hare.lua
@@ -0,0 +1,82 @@
+-- Copyright 2023 Sam Nystrom <sam@samnystrom.dev>
+-- Hare LPeg lexer
+
+local l = require('lexer')
+local C, Cmt, P, R, S = lpeg.C, lpeg.Cmt, lpeg.P, lpeg.R, lpeg.S
+
+local lex = l.new('hare')
+
+-- Whitespace
+lex:add_rule('whitespace', l.token(l.WHITESPACE, l.space^1))
+
+-- Comments
+lex:add_rule('comment', l.token(l.COMMENT, l.to_eol('//', true)))
+
+-- Keywords
+lex:add_rule('keyword', l.token(l.KEYWORD, l.word_match{
+ 'as', 'is',
+ 'if', 'else', 'match', 'switch',
+ 'break', 'continue', 'defer', 'return', 'yield',
+ 'const', 'def', 'let',
+ 'fn',
+ 'case',
+ 'for',
+ 'export', 'static',
+ 'enum', 'struct', 'union',
+ 'type',
+}))
+
+-- Builtins
+lex:add_rule('function', l.token(l.FUNCTION, l.word_match{
+ 'abort', 'assert',
+ 'align', 'len', 'offset',
+ 'alloc', 'free',
+ 'append', 'insert', 'delete',
+ -- C ABI
+ 'vastart', 'vaarg', 'vaend',
+}))
+
+-- Types
+lex:add_rule('type', l.token(l.TYPE, l.word_match{
+ 'bool',
+ 'f32', 'f64',
+ 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64',
+ 'size', 'int', 'uint', 'uintptr',
+ 'never',
+ 'nullable',
+ 'opaque',
+ 'rune', 'str',
+ 'void',
+ -- C ABI
+ 'valist',
+}))
+
+-- Constants
+lex:add_rule('constant', l.token(l.CONSTANT, l.word_match{'true', 'false', 'null'}))
+
+-- Numbers
+--[[local identifier = P('r#')^-1 * l.word
+local function opt_cap(patt) return C(patt^-1) end
+local float = l.digit *
+ (Cmt(opt_cap('.' * l.digit) * opt_cap(S('eE') * S('+-')^-1 * l.digit) *
+ opt_cap(P('f32') + 'f64'), function(input, index, decimals, exponent, type)
+ return decimals ~= "" or exponent ~= "" or type ~= ""
+ end) + '.' * -(S('._') + identifier))
+local bin = P('0b') * S('01')
+local oct = P('0o') * lpeg.R('07')
+local hex = P('0x') * l.xdigit
+local integer = (bin + oct + hex + decimal_literal) *
+ (S('iu') * (P('8') + '16' + '32' + '64' + '128' + 'size'))^-1
+--]]
+lex:add_rule('number', l.token(l.NUMBER, l.float + l.integer))
+
+-- Strings
+lex:add_rule('string', l.token(l.STRING, l.range('"') + l.range('\'')))
+
+-- Operators
+lex:add_rule('operator', l.token(l.OPERATOR, S('+-/*<>!=@~&|^?:;,.()[]{}')))
+
+lex:add_fold_point(l.OPERATOR, '{', '}')
+lex:add_fold_point(l.COMMENT, l.fold_consecutive_lines('//'))
+
+return lex
diff --git a/.config/vis/lexers/roff.lua b/.config/vis/lexers/roff.lua
new file mode 100644
index 0000000..59657a7
--- /dev/null
+++ b/.config/vis/lexers/roff.lua
@@ -0,0 +1,32 @@
+-- Copyright 2023 Sam Nystrom <sam@samnystrom.dev>
+-- Roff LPeg lexer.
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'roff'}
+
+-- Whitespace
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments
+local comment = token(l.COMMENT, '\\"' * l.nonnewline^0)
+
+-- Strings
+local string = token(l.STRING, l.delimited_range('"'))
+
+-- Keywords
+local word = (l.alpha + '_') * (l.alnum + S('_.'))^0
+local keyword = token(l.KEYWORD, l.starts_line('.') * l.word)
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'string', string},
+ {'comment', comment},
+}
+
+M._LEXBYLINE = true
+
+return M
diff --git a/.config/vis/themes/flexoki.lua b/.config/vis/themes/flexoki.lua
new file mode 100644
index 0000000..e540a00
--- /dev/null
+++ b/.config/vis/themes/flexoki.lua
@@ -0,0 +1,125 @@
+local mode = 'dark' -- one of 'dark' or 'light'
+
+local colors = {
+ black = '#100f0f',
+ base950 = '#1c1b1a',
+ base900 = '#282726',
+ base850 = '#343331',
+ base800 = '#403e3c',
+ base700 = '#575653',
+ base600 = '#6f6e69',
+ base500 = '#878580',
+ base300 = '#b7b5ac',
+ base200 = '#cecdc3',
+ base150 = '#dad8ce',
+ base100 = '#e6e4d9',
+ base50 = '#f2f0e5',
+ paper = '#fffcf0',
+ red600 = '#af3029',
+ orange600 = '#bc5215',
+ yellow600 = '#ad8301',
+ green600 = '#66800b',
+ cyan600 = '#24837b',
+ blue600 = '#205ea6',
+ purple600 = '#5e409d',
+ magenta600 = '#a02f6f',
+ red400 = '#d14d41',
+ orange400 = '#da702c',
+ yellow400 = '#d0a215',
+ green400 = '#879a39',
+ cyan400 = '#3aa99f',
+ blue400 = '#4385be',
+ purple400 = '#8b7ec8',
+ magenta400 = '#ce5d97',
+}
+
+if mode == 'light' then
+ colors.bg = colors.paper
+ colors.bg2 = colors.base50
+ colors.ui = colors.base100
+ colors.ui2 = colors.base150
+ colors.ui3 = colors.base200
+ colors.tx3 = colors.base300
+ colors.tx2 = colors.base600
+ colors.tx = colors.black
+
+ colors.re = colors.red600
+ colors.ng = colors.orange600
+ colors.ye = colors.yellow600
+ colors.gr = colors.green600
+ colors.cy = colors.cyan600
+ colors.bl = colors.blue600
+ colors.pu = colors.purple600
+ colors.ma = colors.magenta600
+
+ colors.re2 = colors.red400
+ colors.ng2 = colors.orange400
+ colors.ye2 = colors.yellow400
+ colors.gr2 = colors.green400
+ colors.cy2 = colors.cyan400
+ colors.bl2 = colors.blue400
+ colors.pu2 = colors.purple400
+ colors.ma2 = colors.magenta400
+else
+ colors.bg = colors.black
+ colors.bg2 = colors.base950
+ colors.ui = colors.base900
+ colors.ui2 = colors.base850
+ colors.ui3 = colors.base800
+ colors.tx3 = colors.base700
+ colors.tx2 = colors.base500
+ colors.tx = colors.base200
+
+ colors.re = colors.red400
+ colors.ng = colors.orange400
+ colors.ye = colors.yellow400
+ colors.gr = colors.green400
+ colors.cy = colors.cyan400
+ colors.bl = colors.blue400
+ colors.pu = colors.purple400
+ colors.ma = colors.magenta400
+
+ colors.re2 = colors.red600
+ colors.ng2 = colors.orange600
+ colors.ye2 = colors.yellow600
+ colors.gr2 = colors.green600
+ colors.cy2 = colors.cyan600
+ colors.bl2 = colors.blue600
+ colors.pu2 = colors.purple600
+ colors.ma2 = colors.magenta600
+end
+
+vis.lexers.STYLE_DEFAULT = 'fore:'..colors.tx..',back:'..colors.bg
+vis.lexers.STYLE_NOTHING = ''
+vis.lexers.STYLE_CLASS = 'fore:'..colors.ng
+vis.lexers.STYLE_COMMENT = 'fore:'..colors.tx3
+vis.lexers.STYLE_CONSTANT = 'fore:'..colors.ye
+vis.lexers.STYLE_DEFINITION = 'fore:'..colors.ng
+vis.lexers.STYLE_ERROR = 'fore:'..colors.re2..',bold'
+vis.lexers.STYLE_FUNCTION = 'fore:'..colors.ng
+vis.lexers.STYLE_KEYWORD = 'fore:'..colors.gr
+vis.lexers.STYLE_LABEL = 'fore:'..colors.gr
+vis.lexers.STYLE_NUMBER = 'fore:'..colors.pu
+vis.lexers.STYLE_OPERATOR = 'fore:'..colors.tx2
+vis.lexers.STYLE_REGEX = 'fore:'..colors.cy
+vis.lexers.STYLE_STRING = 'fore:'..colors.cy
+vis.lexers.STYLE_PREPROCESSOR = 'fore:'..colors.ma
+vis.lexers.STYLE_TAG = 'fore:'..colors.cy
+vis.lexers.STYLE_TYPE = 'fore:'..colors.gr
+vis.lexers.STYLE_VARIABLE = 'fore:'..colors.re..',bold'
+vis.lexers.STYLE_WHITESPACE = 'fore:'..colors.tx3
+vis.lexers.STYLE_EMBEDDED = 'fore:'..colors.re..',bold'
+vis.lexers.STYLE_IDENTIFIER = 'fore:'..colors.bl
+
+vis.lexers.STYLE_LINENUMBER = 'fore:'..colors.tx3
+vis.lexers.STYLE_LINENUMBER_CURSOR = 'fore:'..colors.tx
+vis.lexers.STYLE_CURSOR = 'fore:'..colors.bg..',back:'..colors.tx
+vis.lexers.STYLE_CURSOR_PRIMARY = 'fore:'..colors.bg..',back:'..colors.tx
+vis.lexers.STYLE_CURSOR_LINE = 'back:'..colors.bg2
+vis.lexers.STYLE_COLOR_COLUMN = 'back:'..colors.ui
+vis.lexers.STYLE_SELECTION = 'back:'..colors.ui
+vis.lexers.STYLE_STATUS = 'fore:'..colors.tx2..',back:'..colors.ui
+vis.lexers.STYLE_STATUS_FOCUSED = 'fore:'..colors.tx..',back:'..colors.ui2
+vis.lexers.STYLE_SEPARATOR = 'fore:'..colors.ui3
+vis.lexers.STYLE_INFO = 'fore:'..colors.ye..',bold'
+vis.lexers.STYLE_EOF = 'fore:'..colors.tx3 \ No newline at end of file
diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua
new file mode 100644
index 0000000..9641dd6
--- /dev/null
+++ b/.config/vis/visrc.lua
@@ -0,0 +1,61 @@
+require('vis')
+
+require('plugins/vis-backspace')
+require('plugins/vis-ctags')
+require('plugins/vis-cursors')
+require('plugins/vis-editorconfig')
+require('plugins/vis-quickfix')
+
+for _, ext in ipairs({ "%.jsx$", "%.ts", "%.tsx$" }) do
+ table.insert(vis.ftdetect.filetypes.javascript.ext, ext)
+end
+
+vis.ftdetect.filetypes.hare = {
+ ext = { "%.ha$" },
+}
+
+shebangs = {
+ awk = { "awk" },
+ bash = { "bash", "sh" },
+ execline = { "execlineb" },
+ perl = { "perl" },
+ python = { "python", "python3" },
+}
+
+vis.events.subscribe(vis.events.WIN_OPEN, function(win)
+ local shebang = vis.win.file.lines[1]
+ local cmd = shebang:match("^#!%g*/([^/%s]+)")
+ if cmd == "env" then
+ cmd = shebang:match("^#!%g*/env (%g+)")
+ end
+ for syntax, cmds in pairs(shebangs) do
+ for _, c in ipairs(cmds) do
+ if c == cmd then
+ vis:command("set syntax " .. syntax)
+ return
+ end
+ end
+ end
+end)
+
+vis.events.subscribe(vis.events.INIT, function()
+ vis:command('set escdelay 25')
+ vis:command('set autoindent')
+ vis:command('set theme flexoki')
+end)
+
+vis.events.subscribe(vis.events.WIN_OPEN, function(win)
+ vis:command('set relativenumbers')
+end)
+
+function automake_handler()
+ vis:command('make')
+end
+
+vis:option_register('automake', 'bool', function(value, toggle)
+ if toggle then
+ vis.events.subscribe(vis.events.FILE_SAVE_POST, automake_handler)
+ else
+ vis.events.unsubscribe(vis.events.FILE_SAVE_POST, automake_handler)
+ end
+end, 'Run :make automatically after saving')