1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
--[[
Provides Lua handler that wraps invocation of an editor. Name of the wrapper
needs to be passed in as an argument.
Builtin wrappers:
* emacs
* gvim
* vim
* helix
* helix-tmux
Usage example:
set vicmd='#editor#run gvim'
--]]
-- TODO: consider loading implementations lazily, more than one is unlikely to
-- be used
local impls = {
emacs = vifm.plugin.require('emacs'),
gvim = vifm.plugin.require('gvim'),
vim = vifm.plugin.require('vim'),
helix = vifm.plugin.require('helix'),
['helix-tmux'] = vifm.plugin.require('helix-tmux'),
}
local function run(info)
local args = string.gmatch(info.command, "(%S+)")
local _ = args()
local editor = args()
if editor == nil then
vifm.errordialog(vifm.plugin.name, "Editor name is missing")
return { success = 1 }
end
local impl = impls[editor]
if impl == nil then
vifm.errordialog(vifm.plugin.name, "Editor name is wrong: " .. editor)
return { success = 1 }
end
local handler = impl.handlers[info.action]
if handler == nil then
vifm.errordialog(vifm.plugin.name, "Unexpected action: " .. info.action)
return { success = false }
end
return { success = handler(info) }
end
local added = vifm.addhandler {
name = "run",
handler = run,
}
if not added then
vifm.sb.error("Failed to register #run")
end
return { wrappers = impls }
|