diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-14 21:39:30 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-14 21:39:30 +0100 |
| commit | 822b2c913c7d6690221eabf9b252850fb7c32513 (patch) | |
| tree | d1c60192f8b8369aa9cbe5f16d1cb2934ba66729 | |
| parent | c7a56e3a3257af927695f564a8773bea31b93adf (diff) | |
| download | vis-822b2c913c7d6690221eabf9b252850fb7c32513.tar.gz vis-822b2c913c7d6690221eabf9b252850fb7c32513.tar.xz | |
lua: improve error message when failing to load lpeg/lexer module
Differentiate between the case where the module is not found and
the case where an error occured while loading it.
This should make it easier to debug cases in which there is a
Lua version mismatch between vis and lpeg.
| -rw-r--r-- | lua/vis-std.lua | 22 | ||||
| -rw-r--r-- | lua/vis.lua | 9 |
2 files changed, 22 insertions, 9 deletions
diff --git a/lua/vis-std.lua b/lua/vis-std.lua index 85defad..9ed0317 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -1,5 +1,25 @@ -- standard vis event handlers +vis.events.subscribe(vis.events.INIT, function() + local package_exist = function(name) + for _, searcher in ipairs(package.searchers or package.loaders) do + local loader = searcher(name) + if type(loader) == 'function' then + return true + end + end + return false + end + + if not package_exist('lpeg') then + vis:info('WARNING: could not find lpeg module') + elseif not package_exist('lexer') then + vis:info('WARNING: could not find lexer module') + else + vis.lexers = require('lexer') + end +end) + vis.events.subscribe(vis.events.THEME_CHANGE, function(name) if name ~= nil then local theme = 'themes/'..name @@ -7,7 +27,7 @@ vis.events.subscribe(vis.events.THEME_CHANGE, function(name) require(theme) end - if vis.lexers ~= nil then vis.lexers.lexers = {} end + if vis.lexers then vis.lexers.lexers = {} end for win in vis:windows() do win.syntax = win.syntax; diff --git a/lua/vis.lua b/lua/vis.lua index 97350a7..f1aff45 100644 --- a/lua/vis.lua +++ b/lua/vis.lua @@ -5,14 +5,7 @@ --- -- @type Vis -local ok, msg = pcall(function() - vis.lexers = {} - vis.lexers = require('lexer') -end) - -if not ok then - vis:info('WARNING: could not load lexer module, is lpeg installed?') -end +vis.lexers = {} --- Map a new motion. -- |
