56 lines
1.2 KiB
Lua
56 lines
1.2 KiB
Lua
local M = {}
|
|
|
|
M.keys = {
|
|
[' p%d'] = '<vis-prompt-show>pin-files pin %d<Enter>',
|
|
[' %d'] = '<vis-prompt-show>pin-files e %d<Enter>',
|
|
}
|
|
|
|
M.files = {}
|
|
|
|
local function pin_file(num, file)
|
|
if file ~= nil then
|
|
M.files[num] = file
|
|
vis:info('[' .. num .. '] pin')
|
|
else
|
|
vis:info('Window has no file')
|
|
end
|
|
end
|
|
|
|
local function open_file(num, cmd)
|
|
local file = M.files[num]
|
|
if not file then
|
|
vis:info('[' .. num .. '] empty')
|
|
elseif file == vis.win.file.path and cmd == 'e' then
|
|
vis:info('[' .. num .. '] already opened')
|
|
else
|
|
vis:info('[' .. num .. '] ' .. cmd)
|
|
vis:command(string.format('%s %q', cmd or 'o', file))
|
|
end
|
|
end
|
|
|
|
vis:command_register('pin-files', function(argv, force, win, selection, range)
|
|
local cmd = argv[1] or 'o'
|
|
local num = tonumber(argv[2]) or argv[2] or vis.count
|
|
if not num then
|
|
vis:info('No file number given')
|
|
elseif cmd == 'pin' then
|
|
pin_file(num, win.file.path)
|
|
else
|
|
open_file(num, cmd)
|
|
end
|
|
end)
|
|
|
|
vis.events.subscribe(vis.events.INIT, function()
|
|
for key, cmd in pairs(M.keys or {}) do
|
|
if key:find('%%d') then
|
|
for num = 1, 9 do
|
|
vis:map(vis.modes.NORMAL, string.format(key, num), string.format(cmd, num))
|
|
end
|
|
else
|
|
vis:map(vis.modes.NORMAL, key, cmd)
|
|
end
|
|
end
|
|
end)
|
|
|
|
return M
|