2020-10-30 15:04:23 +00:00
|
|
|
local Opt = {}
|
|
|
|
|
2020-11-04 14:14:36 +00:00
|
|
|
-- vim setting names and defaults
|
|
|
|
local zettel_defaults = {
|
|
|
|
extension = {vimname = "zettel_extension", default = ".md"},
|
|
|
|
link_style = {
|
|
|
|
vimname = "zettel_link_style",
|
|
|
|
default = "markdown",
|
|
|
|
valid = {markdown = true, wiki = true}
|
|
|
|
},
|
|
|
|
link_following = {
|
|
|
|
vimname = "zettel_link_following",
|
|
|
|
default = "cursor",
|
|
|
|
valid = {cursor = true, line = true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local anchor_defaults = {
|
|
|
|
separator = {vimname = "zettel_anchor_separator", default = "_"}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- remaining options
|
2020-10-30 15:04:23 +00:00
|
|
|
-- TODO zettel_root = vim.g["zettel_root"] or vim.b["zettel_root"] or "~/documents/notes",
|
|
|
|
-- TODO zettel_anchor_pattern = regex? -> needs custom creation function in `create_anchor`
|
|
|
|
|
2020-10-30 18:08:52 +00:00
|
|
|
local function must_contain(set, value, name)
|
|
|
|
if type(set) ~= "table" then return false end
|
|
|
|
if not set[value] then
|
|
|
|
local allvalues = ""
|
|
|
|
for n, _ in pairs(set) do allvalues = n .. ", " .. allvalues end
|
|
|
|
error((name or "value") .. " " .. value .. " must be one of " ..
|
|
|
|
allvalues:sub(1, -3))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-04 14:14:36 +00:00
|
|
|
local function get_options(defaults)
|
2020-10-30 15:04:23 +00:00
|
|
|
local options = {}
|
2020-11-04 14:14:36 +00:00
|
|
|
local def = defaults
|
|
|
|
for opt, v in pairs(def) do
|
2020-10-30 17:44:50 +00:00
|
|
|
|
2020-11-04 14:14:36 +00:00
|
|
|
-- check for vim options set (globally or buffer), otherwise use default value
|
|
|
|
options[opt] = vim.g[def[opt].vimname] or vim.b[def[opt].vimname] or
|
|
|
|
def[opt].default
|
2020-11-01 21:18:40 +00:00
|
|
|
|
2020-11-04 14:14:36 +00:00
|
|
|
-- check correct option set for constrained value sets
|
|
|
|
if def[opt].valid then
|
|
|
|
must_contain(def[opt].valid, options[opt], def[opt].name)
|
|
|
|
end
|
|
|
|
end
|
2020-10-30 15:04:23 +00:00
|
|
|
return options
|
|
|
|
end
|
|
|
|
|
2020-11-04 14:14:36 +00:00
|
|
|
function Opt.zettel() return get_options(zettel_defaults) end
|
|
|
|
|
|
|
|
function Opt.anchor() return get_options(anchor_defaults) end
|
2020-10-30 15:04:23 +00:00
|
|
|
|
|
|
|
return Opt
|