1
0
Fork 0

.config/vis: update config, theme, use local vis-std.lua

main
urosm 2024-08-26 17:03:12 +02:00
parent 7aa7dd1750
commit 4bfd6003aa
3 changed files with 59 additions and 33 deletions

View File

@ -109,8 +109,10 @@ lex:embed(html, html_start_rule, html_end_rule)
-- Embedded YAML. -- Embedded YAML.
local yaml = lexer.load('yaml') local yaml = lexer.load('yaml')
local yaml_start_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl local doc_bounds_rule = yaml:get_rule('doc_bounds')
local yaml_end_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl local hr_rule = lex:get_rule('hr')
local yaml_start_rule = doc_bounds_rule - hr_rule
local yaml_end_rule = doc_bounds_rule - hr_rule
lex:embed(yaml, yaml_start_rule, yaml_end_rule) lex:embed(yaml, yaml_start_rule, yaml_end_rule)
return lex return lex

View File

@ -25,6 +25,7 @@ end)
-- apply additional cursor styles on WIN_STATUS -- apply additional cursor styles on WIN_STATUS
vis.events.subscribe(vis.events.WIN_STATUS, function(win) vis.events.subscribe(vis.events.WIN_STATUS, function(win)
local pos = win.selection.pos local pos = win.selection.pos
if not pos then return end
local style_id = win ~= vis.win and local style_id = win ~= vis.win and
win['STYLE_CURSOR'] or win['STYLE_CURSOR'] or
win['STYLE_CURSOR_'..vis.mode] or win['STYLE_CURSOR_'..vis.mode] or

View File

@ -12,10 +12,15 @@ local mode_strings = {
local e = vis.events local e = vis.events
-- editor options -- init
e.subscribe(e.INIT, function() e.subscribe(e.INIT, function()
require("themes.basic") -- load theme
require("themes/basic")
local lexers = vis.lexers
lexers.lexers = {}
if lexers.load and not lexers.property then lexers.load("text") end
-- mappings
vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>') vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
vis:map(m.VISUAL, 'y', '<vis-register>+<vis-operator-yank>') vis:map(m.VISUAL, 'y', '<vis-register>+<vis-operator-yank>')
vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>') vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
@ -29,6 +34,11 @@ e.subscribe(e.INIT, function()
vis:map(m.VISUAL, 'P', '<vis-register>+<vis-put-before>') vis:map(m.VISUAL, 'P', '<vis-register>+<vis-put-before>')
vis:map(m.VISUAL_LINE, 'P', '<vis-register>+<vis-put-before>') vis:map(m.VISUAL_LINE, 'P', '<vis-register>+<vis-put-before>')
vis:map(m.NORMAL, 'gA', '<vis-motion-screenline-end><vis-motion-char-prev><vis-append-char-next>')
vis:map(m.NORMAL, '<C-h>', '<vis-jumplist-prev>');
vis:map(m.NORMAL, '<C-l>', '<vis-jumplist-next>');
vis:map(m.NORMAL, '<C-w>o', function() vis:map(m.NORMAL, '<C-w>o', function()
local unclosed local unclosed
for win in vis:windows() do for win in vis:windows() do
@ -41,46 +51,65 @@ e.subscribe(e.INIT, function()
vis.win = unclosed vis.win = unclosed
vis:info('No write since last change') vis:info('No write since last change')
end end
end) end, 'Close all unfocused windows')
vis:map(m.NORMAL, ' e', function() vis:map(m.NORMAL, ' e', function()
local _, f = vis:pipe('find -type f | vis-menu -l 5 -p ":e"') local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
if f == nil then return end if s ~= 0 or not f then return end
cmd = ('e "%s"'):format(f:sub(1, -2)) cmd = ('e "%s"'):format(f:sub(1, -2))
vis:info(cmd) vis:info(cmd)
vis:command(cmd) vis:command(cmd)
end) end, 'pick file to :e')
vis:map(m.NORMAL, ' o', function() vis:map(m.NORMAL, ' o', function()
local _, f = vis:pipe('find -type f | vis-menu -l 5 -p ":o"') local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
if file == nil then return end if s ~= 0 or not f then return end
cmd = ('vsplit "%s"'):format(f:sub(1, -2)) cmd = ('o "%s"'):format(f:sub(1, -2))
vis:info(cmd) vis:info(cmd)
vis:command(cmd) vis:command(cmd)
end) end, 'pick file to :o')
vis:map(m.NORMAL, ' b', function()
local wins = {}
local i, wi = 0, 0
for win in vis:windows() do
table.insert(wins, ('%q:%q'):format(i,win.file.name or '[No_Name]'))
if win == vis.win then wi = i end
i = i + 1
end
wins = table.concat(wins, '\n')
local s, w = vis:pipe(('printf "%s" | vis-menu -l 5 -p "pick window"'):format(wins))
if s ~= 0 or not w then return end
local si = tonumber(w:match('^(%d+):.*$') or wi)
if si == wi then return end
local action = si > wi and '<vis-window-next>' or '<vis-window-prev>'
for i=1,math.abs(si-wi) do
vis:feedkeys(action)
end
end, 'pick window to move to')
vis:map(m.NORMAL, ' g', function() vis:map(m.NORMAL, ' g', function()
local _, w = vis:pipe( local s, word = vis:pipe(
vis.win.file or nil, vis.win.file or nil,
vis.win.viewport.bytes, vis.win.viewport.bytes,
'grep -Eo "\\w\\w\\w+" | sort | uniq | vis-menu -l 5 -p "grep"') 'grep -Eo "\\w\\w\\w+" | sort -u | vis-menu -l 5 -p "grep"')
if w == nil then return end if s ~= 0 or not word then return end
w = w:sub(1, -2) word = word:sub(1, -2)
local _, f = vis:pipe(('grep -n "%s" ** | tr "\\t" " " | vis-menu -l 5 -p ":o"'):format(w)) local s, f = vis:pipe(('grep -n "%s" ** | tr "\\t" " " | vis-menu -l 5 -p ":o"'):format(word))
if f == nil then return end if s ~= 0 or not f then return end
local file, lineno, line = f:match("^(.+):(%d+):(.*)$") local file, lineno, line = f:match("^(.+):(%d+):(.*)$")
if file == nil then return end -- TODO report error if file == nil then return end -- TODO report error
cmd = ('vsplit "%s"'):format(file) cmd = ('o "%s"'):format(file)
vis:info(cmd) vis:info(cmd)
vis:command(cmd) vis:command(cmd)
vis.win.selection:to(tonumber(lineno), line:find(w)) vis.win.selection:to(tonumber(lineno), line:find(word))
end) end, 'grep and pick file to :o')
-- editor options
vis.options.autoindent = true vis.options.autoindent = true
end) end)
-- window options -- window open
e.subscribe(e.WIN_OPEN, function(win) e.subscribe(e.WIN_OPEN, function(win)
win.options.colorcolumn = 81 win.options.colorcolumn = 81
win.options.relativenumbers = true win.options.relativenumbers = true
@ -99,8 +128,7 @@ e.subscribe(e.WIN_OPEN, function(win)
end) end)
-- statusline -- statusline
e.subscribe(e.WIN_STATUS, function(win)
function set_statusline(win, mode_string)
local left_parts = {} local left_parts = {}
local right_parts = {} local right_parts = {}
local file = win.file local file = win.file
@ -110,7 +138,7 @@ function set_statusline(win, mode_string)
if vis.win == win then if vis.win == win then
-- mode -- mode
table.insert(left_parts, mode_string) table.insert(left_parts, mode_strings[vis.mode])
-- selection -- selection
table.insert(left_parts, selection.number..'/'..#win.selections) table.insert(left_parts, selection.number..'/'..#win.selections)
@ -137,18 +165,13 @@ function set_statusline(win, mode_string)
table.insert(right_parts, selection.col) table.insert(right_parts, selection.col)
-- fillchars -- fillchars
local left = table.concat(left_parts, " ") local left = table.concat(left_parts, ' ')
local right = table.concat(right_parts, " ") local right = table.concat(right_parts, ' ')
win:status(table.concat({ left, ('^'):rep(win.width - #left - #right - 2)}, ' '), right) win:status(table.concat({ left, ('^'):rep(win.width - #left - #right - 2)}, ' '), right)
end
e.subscribe(e.WIN_STATUS, function(win)
set_statusline(win, mode_strings[vis.mode])
end) end)
-- title -- title
local modified = false local modified = false
local function set_title(title) local function set_title(title)
os.execute('printf "\\e];vis: '..title..(modified and '[+]' or '')..'\\e"') os.execute('printf "\\e];vis: '..title..(modified and '[+]' or '')..'\\e"')