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*
|
||||
|
||||
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
|
||||
example, with lazy.nvim (https://github.com/folke/lazy.nvim):
|
||||
|
||||
{
|
||||
'barrett-ruth/cp.nvim',
|
||||
config = function()
|
||||
local ls = require('luasnip')
|
||||
local s = ls.snippet
|
||||
|
||||
require('cp').setup({
|
||||
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,
|
||||
},
|
||||
Optional: >
|
||||
vim.g.cp = {
|
||||
config = {
|
||||
debug = false,
|
||||
contests = {
|
||||
default = {
|
||||
cpp_version = 20,
|
||||
compile_flags = { "-O2", "-DLOCAL", "-Wall", "-Wextra" },
|
||||
debug_flags = { "-g3", "-fsanitize=address,undefined", "-DLOCAL" },
|
||||
timeout_ms = 2000,
|
||||
},
|
||||
snippets = {
|
||||
cses = {
|
||||
s("cses", "#include <iostream>\nusing namespace std;\n\nint main() {\n\t$0\n}")
|
||||
},
|
||||
},
|
||||
hooks = {
|
||||
before_run = function(problem_id)
|
||||
vim.cmd.w()
|
||||
vim.lsp.buf.format()
|
||||
end,
|
||||
before_debug = function(problem_id)
|
||||
...
|
||||
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
|
||||
atcoder = { cpp_version = 23 },
|
||||
},
|
||||
hooks = {
|
||||
before_run = function(problem_id) vim.cmd.w() end,
|
||||
},
|
||||
tile = function(source_buf, input_buf, output_buf)
|
||||
-- custom window layout
|
||||
end,
|
||||
filename = function(contest, problem_id, problem_letter)
|
||||
-- custom filename generation
|
||||
end,
|
||||
}
|
||||
}
|
||||
<
|
||||
|
||||
Configuration options:
|
||||
|
||||
|
|
|
|||
|
|
@ -263,21 +263,15 @@ local function navigate_problem(delta)
|
|||
end
|
||||
end
|
||||
|
||||
local initialized = false
|
||||
|
||||
function M.is_initialized()
|
||||
return initialized
|
||||
end
|
||||
|
||||
function M.setup(user_config)
|
||||
if initialized and not user_config then
|
||||
local function ensure_initialized()
|
||||
if config then
|
||||
return
|
||||
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)
|
||||
snippets.setup(config)
|
||||
initialized = true
|
||||
end
|
||||
|
||||
local function parse_command(args)
|
||||
|
|
@ -311,6 +305,7 @@ local function parse_command(args)
|
|||
end
|
||||
|
||||
function M.handle_command(opts)
|
||||
ensure_initialized()
|
||||
local cmd = parse_command(opts.fargs)
|
||||
|
||||
if cmd.type == "error" then
|
||||
|
|
@ -374,4 +369,8 @@ function M.handle_command(opts)
|
|||
end
|
||||
end
|
||||
|
||||
function M.is_initialized()
|
||||
return config ~= nil
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ local actions = { "run", "debug", "diff", "next", "prev" }
|
|||
|
||||
vim.api.nvim_create_user_command("CP", function(opts)
|
||||
local cp = require("cp")
|
||||
if not cp.is_initialized() then
|
||||
cp.setup()
|
||||
end
|
||||
cp.handle_command(opts)
|
||||
end, {
|
||||
nargs = "*",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue