commit
d6c182c2a1
4 changed files with 62 additions and 27 deletions
16
doc/cp.txt
16
doc/cp.txt
|
|
@ -84,6 +84,14 @@ example, with lazy.nvim (https://github.com/folke/lazy.nvim):
|
||||||
...
|
...
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
tile = function(source_buf, input_buf, output_buf)
|
||||||
|
vim.api.nvim_set_current_buf(source_buf)
|
||||||
|
vim.cmd.vsplit()
|
||||||
|
vim.api.nvim_set_current_buf(output_buf)
|
||||||
|
vim.cmd.vsplit()
|
||||||
|
vim.api.nvim_set_current_buf(input_buf)
|
||||||
|
vim.cmd('wincmd h | wincmd h')
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
@ -101,11 +109,19 @@ snippets LuaSnip snippets by contest type
|
||||||
|
|
||||||
hooks Functions called at specific events
|
hooks Functions called at specific events
|
||||||
before_run Called before :CP run
|
before_run Called before :CP run
|
||||||
|
function(problem_id)
|
||||||
|
(default: nil, do nothing)
|
||||||
before_debug Called before :CP debug
|
before_debug Called before :CP debug
|
||||||
|
function(problem_id)
|
||||||
|
(default: nil, do nothing)
|
||||||
|
|
||||||
debug Show info messages during operation
|
debug Show info messages during operation
|
||||||
(default: false, silent operation)
|
(default: false, silent operation)
|
||||||
|
|
||||||
|
tile Custom function to arrange windows
|
||||||
|
function(source_buf, input_buf, output_buf)
|
||||||
|
(default: nil, uses built-in layout)
|
||||||
|
|
||||||
WORKFLOW *cp-workflow*
|
WORKFLOW *cp-workflow*
|
||||||
|
|
||||||
1. Set up contest environment: >
|
1. Set up contest environment: >
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
---@field contests table
|
---@field contests table
|
||||||
---@field snippets table
|
---@field snippets table
|
||||||
---@field hooks table
|
---@field hooks table
|
||||||
|
---@field debug boolean
|
||||||
|
---@field tile? fun(source_buf: number, input_buf: number, output_buf: number)
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
@ -30,6 +32,7 @@ M.defaults = {
|
||||||
before_debug = nil,
|
before_debug = nil,
|
||||||
},
|
},
|
||||||
debug = false,
|
debug = false,
|
||||||
|
tile = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param base_config table
|
---@param base_config table
|
||||||
|
|
@ -58,6 +61,7 @@ function M.setup(user_config)
|
||||||
snippets = { user_config.snippets, { "table", "nil" }, true },
|
snippets = { user_config.snippets, { "table", "nil" }, true },
|
||||||
hooks = { user_config.hooks, { "table", "nil" }, true },
|
hooks = { user_config.hooks, { "table", "nil" }, true },
|
||||||
debug = { user_config.debug, { "boolean", "nil" }, true },
|
debug = { user_config.debug, { "boolean", "nil" }, true },
|
||||||
|
tile = { user_config.tile, { "function", "nil" }, true },
|
||||||
})
|
})
|
||||||
|
|
||||||
if user_config.hooks then
|
if user_config.hooks then
|
||||||
|
|
|
||||||
|
|
@ -98,19 +98,15 @@ local function setup_problem(problem_id, problem_letter)
|
||||||
vim.diagnostic.enable(false)
|
vim.diagnostic.enable(false)
|
||||||
|
|
||||||
local base_fp = vim.fn.fnamemodify(filename, ":p:h")
|
local base_fp = vim.fn.fnamemodify(filename, ":p:h")
|
||||||
local input = ("%s/io/%s.in"):format(base_fp, full_problem_id)
|
local input_file = ("%s/io/%s.in"):format(base_fp, full_problem_id)
|
||||||
local output = ("%s/io/%s.out"):format(base_fp, full_problem_id)
|
local output_file = ("%s/io/%s.out"):format(base_fp, full_problem_id)
|
||||||
|
|
||||||
vim.cmd.vsplit(output)
|
local source_buf = vim.api.nvim_get_current_buf()
|
||||||
vim.cmd.w()
|
local input_buf = vim.fn.bufnr(input_file, true)
|
||||||
vim.bo.filetype = "cp"
|
local output_buf = vim.fn.bufnr(output_file, true)
|
||||||
window.clearcol()
|
|
||||||
vim.cmd(("vertical resize %d"):format(math.floor(vim.o.columns * 0.3)))
|
local tile_fn = config.tile or window.default_tile
|
||||||
vim.cmd.split(input)
|
tile_fn(source_buf, input_buf, output_buf)
|
||||||
vim.cmd.w()
|
|
||||||
vim.bo.filetype = "cp"
|
|
||||||
window.clearcol()
|
|
||||||
vim.cmd.wincmd("h")
|
|
||||||
|
|
||||||
logger.log(("switched to problem %s"):format(full_problem_id))
|
logger.log(("switched to problem %s"):format(full_problem_id))
|
||||||
end
|
end
|
||||||
|
|
@ -172,7 +168,8 @@ end
|
||||||
|
|
||||||
local function diff_problem()
|
local function diff_problem()
|
||||||
if vim.g.cp_diff_mode then
|
if vim.g.cp_diff_mode then
|
||||||
window.restore_layout(vim.g.cp_saved_layout)
|
local tile_fn = config.tile or window.default_tile
|
||||||
|
window.restore_layout(vim.g.cp_saved_layout, tile_fn)
|
||||||
vim.g.cp_diff_mode = false
|
vim.g.cp_diff_mode = false
|
||||||
vim.g.cp_saved_layout = nil
|
vim.g.cp_saved_layout = nil
|
||||||
logger.log("exited diff mode")
|
logger.log("exited diff mode")
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ function M.clearcol()
|
||||||
vim.api.nvim_set_option_value("relativenumber", false, { scope = "local" })
|
vim.api.nvim_set_option_value("relativenumber", false, { scope = "local" })
|
||||||
vim.api.nvim_set_option_value("statuscolumn", "", { scope = "local" })
|
vim.api.nvim_set_option_value("statuscolumn", "", { scope = "local" })
|
||||||
vim.api.nvim_set_option_value("signcolumn", "no", { scope = "local" })
|
vim.api.nvim_set_option_value("signcolumn", "no", { scope = "local" })
|
||||||
vim.api.nvim_set_option_value("equalalways", false, { scope = "global" })
|
vim.api.nvim_set_option_value("foldcolumn", "0", { scope = "local" })
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.save_layout()
|
function M.save_layout()
|
||||||
|
|
@ -29,7 +29,7 @@ function M.save_layout()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.restore_layout(state)
|
function M.restore_layout(state, tile_fn)
|
||||||
if not state then
|
if not state then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -53,19 +53,20 @@ function M.restore_layout(state)
|
||||||
vim.cmd("silent only")
|
vim.cmd("silent only")
|
||||||
|
|
||||||
local base_fp = vim.fn.getcwd()
|
local base_fp = vim.fn.getcwd()
|
||||||
local input = ("%s/io/%s.in"):format(base_fp, problem_id)
|
local input_file = ("%s/io/%s.in"):format(base_fp, problem_id)
|
||||||
local output = ("%s/io/%s.out"):format(base_fp, problem_id)
|
local output_file = ("%s/io/%s.out"):format(base_fp, problem_id)
|
||||||
local source = problem_id .. ".cc"
|
local source_file = problem_id .. ".cc"
|
||||||
|
|
||||||
vim.cmd.edit(source)
|
vim.cmd.edit(source_file)
|
||||||
vim.cmd.vsplit(output)
|
local source_buf = vim.api.nvim_get_current_buf()
|
||||||
vim.bo.filetype = "cp"
|
local input_buf = vim.fn.bufnr(input_file, true)
|
||||||
M.clearcol()
|
local output_buf = vim.fn.bufnr(output_file, true)
|
||||||
vim.cmd(("vertical resize %d"):format(math.floor(vim.o.columns * 0.3)))
|
|
||||||
vim.cmd.split(input)
|
if tile_fn then
|
||||||
vim.bo.filetype = "cp"
|
tile_fn(source_buf, input_buf, output_buf)
|
||||||
M.clearcol()
|
else
|
||||||
vim.cmd.wincmd("h")
|
M.default_tile(source_buf, input_buf, output_buf)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
vim.cmd(state.layout)
|
vim.cmd(state.layout)
|
||||||
|
|
||||||
|
|
@ -107,7 +108,24 @@ function M.setup_diff_layout(actual_output, expected_output, input_file)
|
||||||
vim.cmd(("botright split %s"):format(input_file))
|
vim.cmd(("botright split %s"):format(input_file))
|
||||||
vim.bo.filetype = "cp"
|
vim.bo.filetype = "cp"
|
||||||
M.clearcol()
|
M.clearcol()
|
||||||
|
vim.cmd(("resize %d"):format(math.floor(vim.o.lines * 0.3)))
|
||||||
vim.cmd.wincmd("k")
|
vim.cmd.wincmd("k")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function default_tile(source_buf, input_buf, output_buf)
|
||||||
|
vim.api.nvim_set_current_buf(source_buf)
|
||||||
|
vim.cmd.vsplit()
|
||||||
|
vim.api.nvim_set_current_buf(output_buf)
|
||||||
|
vim.bo.filetype = "cp"
|
||||||
|
M.clearcol()
|
||||||
|
vim.cmd(("vertical resize %d"):format(math.floor(vim.o.columns * 0.3)))
|
||||||
|
vim.cmd.split()
|
||||||
|
vim.api.nvim_set_current_buf(input_buf)
|
||||||
|
vim.bo.filetype = "cp"
|
||||||
|
M.clearcol()
|
||||||
|
vim.cmd.wincmd("h")
|
||||||
|
end
|
||||||
|
|
||||||
|
M.default_tile = default_tile
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue