[INIT]
This commit is contained in:
87
lua/repl_plugin/init.lua
Normal file
87
lua/repl_plugin/init.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
local git = require('repl_plugin.git')
|
||||
local runner = require('repl_plugin.runner')
|
||||
local sync = require('repl_plugin.sync')
|
||||
|
||||
local M = {}
|
||||
|
||||
local default_config = {
|
||||
main_repo_path = vim.fn.getcwd(),
|
||||
repl_repo_path = nil,
|
||||
repl_file = nil,
|
||||
poll_interval = 5000,
|
||||
auto_commit = true,
|
||||
output_target = 'buffer', -- buffer or file
|
||||
auto_start = false,
|
||||
log_file = nil,
|
||||
}
|
||||
|
||||
local config = {}
|
||||
|
||||
local function merge_opts(opts)
|
||||
opts = opts or {}
|
||||
for k, v in pairs(default_config) do
|
||||
if opts[k] == nil then opts[k] = v end
|
||||
end
|
||||
return opts
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
config = merge_opts(opts)
|
||||
if not config.repl_repo_path or config.repl_repo_path == '' then
|
||||
config.repl_repo_path = config.main_repo_path
|
||||
end
|
||||
if not config.repl_file or config.repl_file == '' then
|
||||
config.repl_file = config.repl_repo_path .. '/repl.pl'
|
||||
end
|
||||
|
||||
-- pass config to sync module
|
||||
sync.setup({
|
||||
main_repo_path = config.main_repo_path,
|
||||
repl_repo_path = config.repl_repo_path,
|
||||
auto_commit = config.auto_commit,
|
||||
poll_interval = config.poll_interval,
|
||||
})
|
||||
|
||||
-- register commands
|
||||
vim.api.nvim_create_user_command('REPL', function() M.open_repl_file() end, {})
|
||||
vim.api.nvim_create_user_command('RUN', function() M.run_repl() end, {})
|
||||
|
||||
if config.auto_start then M.start_auto_sync() end
|
||||
end
|
||||
|
||||
function M.open_repl_file()
|
||||
local file = config.repl_file
|
||||
if not file or file == '' then
|
||||
vim.notify('No repl_file configured', vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(file))
|
||||
end
|
||||
|
||||
function M.run_repl()
|
||||
local file = config.repl_file
|
||||
if not file or file == '' then
|
||||
vim.notify('No repl_file configured', vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
runner.run_perl(file, {
|
||||
repo_base = vim.fn.fnamemodify(config.repl_repo_path, ':t'),
|
||||
open_split = true,
|
||||
output_target = config.output_target,
|
||||
repl_repo_path = config.repl_repo_path,
|
||||
})
|
||||
end
|
||||
|
||||
function M.start_auto_sync()
|
||||
sync.start(config.poll_interval)
|
||||
end
|
||||
|
||||
function M.stop_auto_sync()
|
||||
sync.stop()
|
||||
end
|
||||
|
||||
function M.sync_once(cb)
|
||||
sync.sync_once(cb)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user