forked from zhisme/copy_with_context.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.lua
More file actions
53 lines (46 loc) · 1.64 KB
/
config.lua
File metadata and controls
53 lines (46 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local user_config_validation = require("copy_with_context.user_config_validation")
local M = {}
-- Default configuration
M.options = {
mappings = {
relative = "<leader>cy",
absolute = "<leader>cY",
},
-- Formats: copied_text is automatically prepended with a newline
formats = {
default = "# {filepath}:{line}",
},
-- Full output formats: use {copied_text} token for complete control over output
-- Example: output_formats = { default = "{copied_text}\n\n# {filepath}:{line}" }
output_formats = {},
trim_lines = false,
}
-- Setup function to merge user config with defaults
function M.setup(opts)
if opts then
M.options = vim.tbl_deep_extend("force", M.options, opts)
end
-- Validate configuration
local valid, err = user_config_validation.validate(M.options)
if not valid then
error(string.format("Invalid configuration: %s", err))
end
-- Validate each format string (is_output_format = false)
for format_name, format_string in pairs(M.options.formats or {}) do
local format_valid, format_err =
user_config_validation.validate_format_string(format_string, false)
if not format_valid then
error(string.format("Invalid format '%s': %s", format_name, format_err))
end
end
-- Validate each output_format string (is_output_format = true, requires
-- {copied_text})
for format_name, format_string in pairs(M.options.output_formats or {}) do
local format_valid, format_err =
user_config_validation.validate_format_string(format_string, true)
if not format_valid then
error(string.format("Invalid output_format '%s': %s", format_name, format_err))
end
end
end
return M