vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit d947dbcfdc1b2499365882dbdea7b43f04364aea parent 171929d32001fa80a9afea04ec464490aa8d210b Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 8 Dec 2016 09:21:15 +0100 vis-lua: expose init event and use it to set default theme The init event is emitted immediately after `visrc.lua` has been sourced, but before any other events have occured, in particular the command line arguments have not yet been processed. Close #422 Diffstat:
| M | lua/vis-std.lua | | | 2 | -- |
| M | lua/vis.lua | | | 2 | ++ |
| M | lua/visrc.lua | | | 6 | +++--- |
| M | vis-lua.c | | | 11 | ++++++++++- |
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/lua/vis-std.lua b/lua/vis-std.lua @@ -115,5 +115,3 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win) local right = ' ' .. table.concat(right_parts, " « ") .. ' ' win:status(left, right); end) - -vis:command("set theme ".. (vis.ui.colors <= 16 and "default-16" or "default-256")) diff --git a/lua/vis.lua b/lua/vis.lua @@ -88,6 +88,7 @@ local events = { FILE_OPEN = "Event::FILE_OPEN", -- see @{file_open} FILE_SAVE_POST = "Event::FILE_SAVE_POST", -- see @{file_save_post} FILE_SAVE_PRE = "Event::FILE_SAVE_PRE", -- see @{file_save_pre} + INIT = "Event::INIT", -- see @{init} QUIT = "Event::QUIT", -- see @{quit} START = "Event::START", -- see @{start} THEME_CHANGE = "Event::THEME_CHANGE", -- see @{theme_change} @@ -102,6 +103,7 @@ events.file_close = function(...) events.emit(events.FILE_CLOSE, ...) end events.file_open = function(...) events.emit(events.FILE_OPEN, ...) end events.file_save_post = function(...) events.emit(events.FILE_SAVE_POST, ...) end events.file_save_pre = function(...) return events.emit(events.FILE_SAVE_PRE, ...) end +events.init = function(...) events.emit(events.INIT, ...) end events.quit = function(...) events.emit(events.QUIT, ...) end events.start = function(...) events.emit(events.START, ...) end events.theme_change = function(...) events.emit(events.THEME_CHANGE, ...) end diff --git a/lua/visrc.lua b/lua/visrc.lua @@ -3,9 +3,9 @@ require('vis') require('plugins/filetype') require('plugins/textobject-lexer') -vis.events.subscribe(vis.events.START, function() - -- Your global configuration options e.g. - -- vis:command('map! normal j gj') +vis.events.subscribe(vis.events.INIT, function() + -- Your global configuration options + vis:command("set theme ".. (vis.ui.colors <= 16 and "default-16" or "default-256")) end) vis.events.subscribe(vis.events.WIN_OPEN, function(win) diff --git a/vis-lua.c b/vis-lua.c @@ -1846,6 +1846,15 @@ static bool package_exist(Vis *vis, lua_State *L, const char *name) { return ret; } +/*** + * Editor initialization completed. + * This event is emitted immediately after `visrc.lua` has been sourced, but + * before any other events have occured, in particular the command line arguments + * have not yet been processed. + * + * Can be used to set *global* configuration options. + * @function init + */ void vis_lua_init(Vis *vis) { lua_State *L = luaL_newstate(); if (!L) @@ -1979,6 +1988,7 @@ void vis_lua_init(Vis *vis) { lua_getglobal(L, "require"); lua_pushstring(L, "visrc"); pcall(vis, L, 1, 0); + vis_lua_event_call(vis, "init"); } } @@ -1987,7 +1997,6 @@ void vis_lua_init(Vis *vis) { * This event is emitted immediately before the main loop starts. * At this point all files are loaded and corresponding windows are created. * We are about to process interactive keyboard input. - * Can be used to set *global* configuration options. * @function start */ void vis_lua_start(Vis *vis) {