vis-config
lua scripts to configure vis editor
git clone https://9o.is/git/vis-config.git
commit 8caa1ed0db9ca5cd5a19d43b6e0ec185d4a681a8 parent f63b540c3868f831a566adb8ae37aba4a28c94e1 Author: Jul <jul@9o.is> Date: Thu, 26 Feb 2026 10:00:45 +0800 move window-manager to lib/x11 Diffstat:
| M | lib/router.lua | | | 17 | ----------------- |
| M | lib/search.lua | | | 14 | ++++++++++++++ |
| M | lib/status.lua | | | 24 | ++++++------------------ |
| M | lib/tmux.lua | | | 8 | ++++---- |
| D | lib/window-manager/init.lua | | | 55 | ------------------------------------------------------- |
| D | lib/window-manager/x11.lua | | | 105 | ------------------------------------------------------------------------------- |
| A | lib/x11.lua | | | 120 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | visrc.lua | | | 5 | +---- |
8 files changed, 145 insertions(+), 203 deletions(-)
diff --git a/lib/router.lua b/lib/router.lua @@ -1,5 +1,3 @@ -local wm = require('lib/window-manager') - local stack = {} local index = 0 local allow = true @@ -59,22 +57,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) end end) -vis:command_register('tab', function(argv, _, win) - if not wm.enabled() then - vis:info('window manager missing') - return false - end - - win.navigate = wm.navigate - vis:command(table.concat(argv, ' ')) - win.navigate = M.navigate -end) - vis:action_register('vis-router-back', M.back, "Go back") vis:action_register('vis-router-forward', M.forward, "Go Forward") -vis.events.subscribe(vis.events.WIN_OPEN, function(win) - win.navigate = M.navigate -end) - return M diff --git a/lib/search.lua b/lib/search.lua @@ -1,4 +1,6 @@ local session = require('lib/session') +local router = require('lib/router') +local wm = require('lib/x11') local M = { find = 'ag -g . {path} | fzy', @@ -135,8 +137,20 @@ vis:command_register('scope', function(argv, _, win) vis.win.scope = '.' end) +vis:command_register('tab', function(argv, _, win) + if not wm.running() then + vis:info('tab: window manager missing') + return false + end + + win.navigate = wm.navigate + vis:command(table.concat(argv, ' ')) + win.navigate = router.navigate +end) + vis.events.subscribe(vis.events.WIN_OPEN, function(win) win.scope = '.' + win.navigate = router.navigate end) return M diff --git a/lib/status.lua b/lib/status.lua @@ -1,4 +1,4 @@ -local wm = require('lib/window-manager') +local wm = require('lib/x11') local mode_names = { [vis.modes.NORMAL] = '[NORMAL]', @@ -9,11 +9,8 @@ local mode_names = { [vis.modes.VISUAL_LINE] = '[VISUAL LINE]', } -local lastl = '' -local lastr = '' - vis.events.subscribe(vis.events.WIN_OPEN, function(win) - if wm.enabled() then + if wm.running() then vis:command('set statusbar off') end end) @@ -21,9 +18,8 @@ end) vis.events.subscribe(vis.events.WIN_CLOSE, function(win) local wc = 0 for _ in vis:windows() do wc = wc + 1 end - if wm.enabled() and wc == 1 then - wm.set_title('') - wm.set_status('') + if wm.running() and wc == 1 then + wm.set_status('', '') end end) @@ -56,16 +52,8 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win) scroll_percent ) - if wm.enabled() and wm.hasstatus() then - if left ~= lastl then - wm.set_title(left) - lastl = left - end - - if right ~= lastr then - wm.set_status(right) - lastr = right - end + if wm.running() then + wm.set_status(left, right) else win:status(left, right) end diff --git a/lib/tmux.lua b/lib/tmux.lua @@ -7,7 +7,7 @@ local M = { } local function write(cmd) - if M.running() then + if not M.running() then vis:info('tmux client is not running') return false end @@ -40,7 +40,7 @@ M.init = function() end M.running = function() - return io.type(M.fd) ~= 'file' + return io.type(M.fd) == 'file' end M.navigate = function(path, cmd) @@ -65,12 +65,12 @@ end M.set_status = function(left, right) if left and left ~= M.status.left then M.status.left = left - return write(string.format("set -pt %s @pane_left_status '%s'", M.id, right)) + write(string.format("set -pt %s @pane_left_status '%s'", M.id, right)) end if right and right ~= M.status.right then M.status.right = right - return write(string.format("set -pt %s @pane_right_status '%s'", M.id, right)) + write(string.format("set -pt %s @pane_right_status '%s'", M.id, right)) end end diff --git a/lib/window-manager/init.lua b/lib/window-manager/init.lua @@ -1,55 +0,0 @@ -local x11 = require('lib/window-manager/x11') - -local wm = 'none' - -local function nullfunc() - vis:info('window manager missing') - return false -end - -local nullstrategy = { - enabled = function() return false end, - hasstatus = function() return false end, - init = nullfunc, - tabnew = nullfunc, - terminal = nullfunc, - navigate = nullfunc, - set_title = nullfunc, - set_status = nullfunc, -} - -local M = { - strategy = nullstrategy, -} - -M.init = function() - if wm == 'x11' and os.getenv('WINDOWID') then - M.strategy = x11 - M.strategy.init() - end -end - -M.enabled = function(...) return M.strategy.enabled(...) end -M.hasstatus = function(...) return M.strategy.hasstatus(...) end -M.tabnew = function(...) return M.strategy.tabnew(...) end -M.terminal = function(...) return M.strategy.terminal(...) end -M.navigate = function(...) return M.strategy.navigate(...) end -M.set_title = function(...) return M.strategy.set_title(...) end -M.set_status = function(...) return M.strategy.set_status(...) end - -vis.events.subscribe(vis.events.INIT, function() - M.init() -end) - -vis:command_register('tabnew', M.tabnew, 'Run vis command in a new tab page') -vis:command_register('terminal', M.terminal, 'Run shell command in a new tab page') - -vis:option_register('wm', 'string', function(value) - if value == 'none' or value == 'tmux' or value == 'x11' then - wm = value - return - end - vis:message('invalid window manager: ' .. value) -end, 'Set window manager') - -return M diff --git a/lib/window-manager/x11.lua b/lib/window-manager/x11.lua @@ -1,105 +0,0 @@ -local fd_qrexec -local fd_xev -local winid -local xembed -local laststatus - -local function write(cmd) - if io.type(fd_qrexec) ~= 'file' then - vis:info('qrexec-winstatus client is not running') - return false - end - fd_qrexec:write(cmd .. '\n') - fd_qrexec:flush() - return true -end - -local function open_status() - local cmd - if os.execute('qubesdb-read-bool /qubes-service/guivm') then - cmd = 'exec xprop-sink 0x%x _MY_WIN_STATUS' - else - cmd = 'exec qrexec-client-vm @default user.WindowStatus+%d' - end - return vis:communicate('qrexec-winstatus', string.format(cmd, xembed or winid)) -end - -local function listenfocus() - local cmd = 'exec xev -id %d -event focus' - return vis:communicate('xev-winstatus', string.format(cmd, winid)) -end - -local x11 = {} - -x11.init = function() - xembed = os.getenv('XEMBED') - winid = os.getenv('WINDOWID') - - if not winid then - return - end - - fd_qrexec = open_status() - fd_xev = listenfocus() - - vis.events.subscribe(vis.events.PROCESS_RESPONSE, function(name, event, code, msg) - if name ~= 'qrexec-winstatus' and name ~= 'xev-winstatus' then - return - end - - if name == 'xev-winstatus' and event == 'STDOUT' then - if msg:match('FocusIn') then - write(laststatus) - end - end - - if event == 'EXIT' then - vis:info(string.format('%s client exited: %s', name, code)) - elseif event == 'SIGNAL' then - vis:info(string.format('%s client exited: %s', name, code)) - end - end) - -end - -x11.enabled = function() - return io.type(fd_qrexec) == 'file' -end - -x11.hasstatus = function() - return true -end - -local function spawn_terminal(cmd) - return os.execute(string.format('terminal %s >/dev/null 2>&1 &', cmd)) -end - -x11.navigate = function(path, cmd) - cmd = cmd and "+'"..cmd.."'" or '' - return spawn_terminal(string.format('vis %s %s', cmd, path)) -end - -x11.tabnew = function(argv) - return spawn_terminal(string.format('vis %s', table.concat(argv, ' '))) -end - -x11.terminal = function(argv) - local cmd = os.getenv('SHELL') or 'sh' - if #argv ~= 0 then cmd = table.concat(argv, ' '):gsub('"', '\\"') end - return spawn_terminal(cmd) -end - -x11.set_title = function(title) - local f = io.open("/dev/tty", "w") - if f then - f:write("\27]2;" .. title .. "\7") - f:close() - end -end - -x11.set_status = function(status) - laststatus = status; - return write(status) -end - -return x11 diff --git a/lib/x11.lua b/lib/x11.lua @@ -0,0 +1,120 @@ +local M = { + enabled = true, + fd = {}, + status = { + left = '', + right = '', + }, +} + +local function write(cmd) + if not M.running() then + vis:info('x11 client is not running') + return false + end + M.fd.status:write(cmd .. '\n') + M.fd.status:flush() + return true +end + +local function open_status() + local cmd = os.execute('qubesdb-read-bool /qubes-service/guivm') and + 'exec xprop-sink 0x%x _MY_WIN_STATUS' or + 'exec qrexec-client-vm @default user.WindowStatus+%d' + return vis:communicate('x11-status', string.format(cmd, M.id_xembed or M.id)) +end + +local function open_events() + local cmd = 'exec xev -id %d -event focus' + return vis:communicate('x11-events', string.format(cmd, M.id)) +end + +M.running = function() + return io.type(M.fd.status) == 'file' +end + +M.init = function() + M.id_xembed = os.getenv('XEMBED') + M.id = os.getenv('WINDOWID') + + if not M.id then + return + end + + M.fd.status = open_status() + M.fd.events = open_events() + + vis.events.subscribe(vis.events.PROCESS_RESPONSE, function(name, event, code, msg) + if name ~= 'x11-status' and name ~= 'x11-events' then + return + end + + if name == 'x11-events' and event == 'STDOUT' then + if msg:match('FocusIn') then + M.set_title(M.status.left) + write(M.status.right) + end + end + + if event == 'EXIT' then + vis:info(string.format('%s client exited: %s', name, code)) + elseif event == 'SIGNAL' then + vis:info(string.format('%s client exited: %s', name, code)) + end + end) + +end + +local function spawn_terminal(cmd) + return os.execute(string.format('terminal %s >/dev/null 2>&1 &', cmd)) +end + +M.navigate = function(path, cmd) + cmd = cmd and "+'"..cmd.."'" or '' + return spawn_terminal(string.format('vis %s %s', cmd, path)) +end + +M.tabnew = function(argv) + return spawn_terminal(string.format('vis %s', table.concat(argv, ' '))) +end + +M.terminal = function(argv) + local cmd = os.getenv('SHELL') or 'sh' + if #argv ~= 0 then cmd = table.concat(argv, ' '):gsub('"', '\\"') end + return spawn_terminal(cmd) +end + +M.set_title = function(title) + local f = io.open("/dev/tty", "w") + if f then + f:write("\27]2;" .. title .. "\7") + f:close() + end +end + +M.set_status = function(left, right) + if left and left ~= M.status.left then + M.status.left = left + M.set_title(left) + end + + if right and right ~= M.status.right then + M.status.right = right + write(right) + end +end + +vis.events.subscribe(vis.events.INIT, function() + if M.enabled then + M.init() + end +end) + +vis.events.subscribe(vis.events.WIN_OPEN, function() + if M.running() then + vis:command_register('tabnew', M.tabnew, 'Run vis command in a new tab page') + vis:command_register('terminal', M.terminal, 'Run shell command in a new tab page') + end +end) + +return M diff --git a/visrc.lua b/visrc.lua @@ -2,7 +2,7 @@ require('vis') require('plugins/commentary') require('plugins/surround') require('plugins/modelines') -require('lib/window-manager') +require('lib/x11') require('lib/status') require('lib/session') require('lib/router') @@ -10,7 +10,6 @@ require('lib/search') require('lib/utils') local ctags = require('lib/ctags') - local lspc = require('plugins/vis-lspc') lspc.enabled = true lspc.autostart = false @@ -22,8 +21,6 @@ local m = vis.modes local ll = ' ' -- left leader local lr = '<Backspace>' -- right leader -vis:command('set wm x11') - vis.events.subscribe(vis.events.INIT, function() vis:command('set autoindent on') vis:command('set ignorecase on')