feat: nest all config in vim.g
This commit is contained in:
parent
b5b55afece
commit
2214c510a6
3 changed files with 33 additions and 66 deletions
77
doc/cp.txt
77
doc/cp.txt
|
|
@ -64,62 +64,33 @@ Navigation Commands ~
|
||||||
|
|
||||||
CONFIGURATION *cp-config*
|
CONFIGURATION *cp-config*
|
||||||
|
|
||||||
cp.nvim is automatically lazy-loaded - no config/setup is required.
|
cp.nvim works out of the box. No setup required.
|
||||||
|
|
||||||
Provide extra options via a setup() function with your package manager. For
|
Optional: >
|
||||||
example, with lazy.nvim (https://github.com/folke/lazy.nvim):
|
vim.g.cp = {
|
||||||
|
config = {
|
||||||
{
|
debug = false,
|
||||||
'barrett-ruth/cp.nvim',
|
contests = {
|
||||||
config = function()
|
default = {
|
||||||
local ls = require('luasnip')
|
cpp_version = 20,
|
||||||
local s = ls.snippet
|
compile_flags = { "-O2", "-DLOCAL", "-Wall", "-Wextra" },
|
||||||
|
debug_flags = { "-g3", "-fsanitize=address,undefined", "-DLOCAL" },
|
||||||
require('cp').setup({
|
timeout_ms = 2000,
|
||||||
debug = false,
|
|
||||||
contests = {
|
|
||||||
default = {
|
|
||||||
cpp_version = 20,
|
|
||||||
compile_flags = { "-O2", "-DLOCAL", "-Wall", "-Wextra" },
|
|
||||||
debug_flags = { "-g3", "-fsanitize=address,undefined", "-DLOCAL" },
|
|
||||||
timeout_ms = 2000,
|
|
||||||
},
|
|
||||||
atcoder = {
|
|
||||||
cpp_version = 23,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
snippets = {
|
atcoder = { cpp_version = 23 },
|
||||||
cses = {
|
},
|
||||||
s("cses", "#include <iostream>\nusing namespace std;\n\nint main() {\n\t$0\n}")
|
hooks = {
|
||||||
},
|
before_run = function(problem_id) vim.cmd.w() end,
|
||||||
},
|
},
|
||||||
hooks = {
|
tile = function(source_buf, input_buf, output_buf)
|
||||||
before_run = function(problem_id)
|
-- custom window layout
|
||||||
vim.cmd.w()
|
end,
|
||||||
vim.lsp.buf.format()
|
filename = function(contest, problem_id, problem_letter)
|
||||||
end,
|
-- custom filename generation
|
||||||
before_debug = function(problem_id)
|
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,
|
|
||||||
filename = function(contest, problem_id, problem_letter)
|
|
||||||
if contest == "atcoder" then
|
|
||||||
return problem_id:lower() .. (problem_letter or "") .. ".cpp"
|
|
||||||
else
|
|
||||||
return problem_id:lower() .. (problem_letter or "") .. ".cc"
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
<
|
||||||
|
|
||||||
Configuration options:
|
Configuration options:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -263,21 +263,15 @@ local function navigate_problem(delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local initialized = false
|
local function ensure_initialized()
|
||||||
|
if config then
|
||||||
function M.is_initialized()
|
|
||||||
return initialized
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.setup(user_config)
|
|
||||||
if initialized and not user_config then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
config = config_module.setup(user_config)
|
vim.g.cp = vim.g.cp or {}
|
||||||
|
config = config_module.setup(vim.g.cp.config)
|
||||||
logger.set_config(config)
|
logger.set_config(config)
|
||||||
snippets.setup(config)
|
snippets.setup(config)
|
||||||
initialized = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parse_command(args)
|
local function parse_command(args)
|
||||||
|
|
@ -311,6 +305,7 @@ local function parse_command(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.handle_command(opts)
|
function M.handle_command(opts)
|
||||||
|
ensure_initialized()
|
||||||
local cmd = parse_command(opts.fargs)
|
local cmd = parse_command(opts.fargs)
|
||||||
|
|
||||||
if cmd.type == "error" then
|
if cmd.type == "error" then
|
||||||
|
|
@ -374,4 +369,8 @@ function M.handle_command(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.is_initialized()
|
||||||
|
return config ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@ local actions = { "run", "debug", "diff", "next", "prev" }
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("CP", function(opts)
|
vim.api.nvim_create_user_command("CP", function(opts)
|
||||||
local cp = require("cp")
|
local cp = require("cp")
|
||||||
if not cp.is_initialized() then
|
|
||||||
cp.setup()
|
|
||||||
end
|
|
||||||
cp.handle_command(opts)
|
cp.handle_command(opts)
|
||||||
end, {
|
end, {
|
||||||
nargs = "*",
|
nargs = "*",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue