diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-08 09:06:01 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-08 09:11:59 +0100 |
| commit | 6d1d45776b231304b0ff41b5e6098f07931ec44e (patch) | |
| tree | 2f7f41170491200d5da92bf4cd570a3e268fbed2 /lua/vis-std.lua | |
| parent | 065a804d282ac99dd93e9ebaf7bc986ccf53e75b (diff) | |
| download | vis-6d1d45776b231304b0ff41b5e6098f07931ec44e.tar.gz vis-6d1d45776b231304b0ff41b5e6098f07931ec44e.tar.xz | |
lua: add simple event multiplexing mechanism
The editor core calls into the functions registered in the `vis.events`
table which then multiplex the events to all registered event handlers.
The first handler which returns a non `nil` value terminates event
propagation.
Diffstat (limited to 'lua/vis-std.lua')
| -rw-r--r-- | lua/vis-std.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lua/vis-std.lua b/lua/vis-std.lua index d8a32ad..a46896a 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -1,6 +1,6 @@ -- standard vis event handlers -vis.events.theme_change = function(name) +vis.events.subscribe(vis.events.THEME_CHANGE, function(name) if name ~= nil then local theme = 'themes/'..name package.loaded[theme] = nil @@ -12,9 +12,9 @@ vis.events.theme_change = function(name) for win in vis:windows() do win.syntax = win.syntax; end -end +end) -vis.events.win_syntax = function(win, name) +vis.events.subscribe(vis.events.WIN_SYNTAX, function(win, name) local lexers = vis.lexers if not lexers.load then return false end @@ -37,9 +37,9 @@ vis.events.win_syntax = function(win, name) end return true -end +end) -vis.events.win_highlight = function(win, horizon_max) +vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win, horizon_max) if win.syntax == nil or vis.lexers == nil then return end local lexer = vis.lexers.load(win.syntax) if lexer == nil then return end @@ -67,7 +67,7 @@ vis.events.win_highlight = function(win, horizon_max) end token_start = token_end end -end +end) local modes = { [vis.MODE_NORMAL] = '', @@ -78,7 +78,7 @@ local modes = { [vis.MODE_REPLACE] = 'REPLACE', } -vis.events.win_status = function(win) +vis.events.subscribe(vis.events.WIN_STATUS, function(win) local left_parts = {} local right_parts = {} local file = win.file @@ -114,6 +114,6 @@ vis.events.win_status = function(win) local left = ' ' .. table.concat(left_parts, " » ") .. ' ' local right = ' ' .. table.concat(right_parts, " « ") .. ' ' win:status(left, right); -end +end) vis:command("set theme ".. (vis.ui.colors <= 16 and "default-16" or "default-256")) |
