aboutsummaryrefslogtreecommitdiff
path: root/lua/vis.lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-22 18:33:57 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-22 18:59:05 +0100
commitb8b374702e7f24401baa883a969eb7f4165ac696 (patch)
tree8ddf5f3648ee708f4147b6a1e0dca594ec8a1ef6 /lua/vis.lua
parent335814c9caef5a25430e9493cbc7d4f806c1f715 (diff)
downloadvis-b8b374702e7f24401baa883a969eb7f4165ac696.tar.gz
vis-b8b374702e7f24401baa883a969eb7f4165ac696.tar.xz
lua: expose vis:module_exist method, load lexer and lpeg module during startup
Diffstat (limited to 'lua/vis.lua')
-rw-r--r--lua/vis.lua26
1 files changed, 24 insertions, 2 deletions
diff --git a/lua/vis.lua b/lua/vis.lua
index f1aff45..24d00bd 100644
--- a/lua/vis.lua
+++ b/lua/vis.lua
@@ -5,8 +5,6 @@
---
-- @type Vis
-vis.lexers = {}
-
--- Map a new motion.
--
-- Sets up a mapping in normal, visual and operator pending mode.
@@ -64,6 +62,30 @@ vis.textobject_new = function(vis, key, textobject, help)
return true
end
+--- Check whether a Lua module exists
+--
+-- Checks whether a subsequent @{require} call will succeed.
+-- @tparam string name the module name to check
+-- @treturn bool whether the module was found
+vis.module_exist = function(vis, 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 vis:module_exist('lpeg') then
+ vis:info('WARNING: could not find lpeg module')
+elseif not vis:module_exist('lexer') then
+ vis:info('WARNING: could not find lexer module')
+else
+ vis.lexers = require('lexer')
+ vis.lpeg = require('lpeg')
+end
+
--- Events.
--
-- User scripts can subscribe Lua functions to certain events. Multiple functions