Skip to content

Commit

Permalink
lua: move digraph handling to separate 'plugin'
Browse files Browse the repository at this point in the history
Load a standard plugins directly from vis-std.lua.
  • Loading branch information
martanne committed Feb 28, 2017
1 parent b759216 commit 28fae46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
23 changes: 23 additions & 0 deletions lua/plugins/digraph.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- insert digraphs using vis-digraph(1)

vis:map(vis.modes.INSERT, "<C-k>", function(keys)
if #keys < 2 then
return -1 -- need more input
end
local file = io.popen(string.format("vis-digraph '%s' 2>&1", keys:gsub("'", "'\\''")))
local output = file:read('*all')
local success, msg, status = file:close()
if success then
if vis.mode == vis.modes.INSERT then
vis:insert(output)
elseif vis.mode == vis.modes.REPLACE then
vis:replace(output)
end
elseif msg == 'exit' then
if status == 2 then
return -1 -- prefix need more input
end
vis:info(output)
end
return #keys
end, "Insert digraph")
26 changes: 4 additions & 22 deletions lua/vis-std.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,8 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
win:status(left, right);
end)

-- additional default keybindings
-- default plugins

vis:map(vis.modes.INSERT, "<C-k>", function(keys)
if #keys < 2 then
return -1 -- need more input
end
local file = io.popen(string.format("vis-digraph '%s' 2>&1", keys:gsub("'", "'\\''")))
local output = file:read('*all')
local success, msg, status = file:close()
if success then
if vis.mode == vis.modes.INSERT then
vis:insert(output)
elseif vis.mode == vis.modes.REPLACE then
vis:replace(output)
end
elseif msg == 'exit' then
if status == 2 then
return -1 -- prefix need more input
end
vis:info(output)
end
return #keys
end, "Insert digraph")
require('plugins/filetype')
require('plugins/textobject-lexer')
require('plugins/digraph')
2 changes: 0 additions & 2 deletions lua/visrc.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-- load standard vis module, providing parts of the Lua API
require('vis')
require('plugins/filetype')
require('plugins/textobject-lexer')

vis.events.subscribe(vis.events.INIT, function()
-- Your global configuration options
Expand Down

0 comments on commit 28fae46

Please sign in to comment.