vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit ba2b2db3912845e5d0867ab5aaa18d1bf6d299f3 parent 600df36713b74fe7c38da8e9d474f19874476681 Author: alex <alex@cloudware.io> Date: Fri, 21 Feb 2020 18:40:07 +0100 vis: allow tests to have an optional lua script The script named after <test-name>.lua, if exists, is run just before loading and executing <test-name>.keys. This allows tests to inject Lua code in the running vis instance to help augment the test environment. For instance, a test could listen to vis.events.FILE_SAVE_PRE events and mutate file text. Diffstat:
| M | vis/visrc.lua | | | 9 | +++++++++ |
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/vis/visrc.lua b/vis/visrc.lua @@ -1,12 +1,21 @@ package.path = '../../lua/?.lua;'..package.path dofile("../../lua/vis.lua") +local function run_if_exists(luafile) + local f = io.open(luafile, "r") + if f ~= nil then + f:close() + dofile(luafile) + end +end + vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- test.in file passed to vis local name = win.file.name if name then -- use the corresponding test.lua file name = string.gsub(name, '%.in$', '') + run_if_exists(string.format("%s.lua", name)) local file = io.open(string.format("%s.keys", name)) local keys = file:read('*all') keys = string.gsub(keys, '%s*\n', '')