Add anchor regex ceontent as changeable option
This commit is contained in:
parent
d29d92cc0a
commit
65e3b0bc1c
3 changed files with 35 additions and 16 deletions
|
@ -15,7 +15,7 @@ function ls.get_anchors_and_paths(path, recursive, options)
|
||||||
-- TODO check for duplicates and warn user
|
-- TODO check for duplicates and warn user
|
||||||
local zettel = {}
|
local zettel = {}
|
||||||
-- TODO let user set as option, at least remove magic var
|
-- TODO let user set as option, at least remove magic var
|
||||||
local anchorreg = '^.*/?([%d][%d][%d][%d][%d][%d][%d][%d][%d][%d])[^/]*%' ..
|
local anchorreg = '^.*/?(' .. o.anchor().regex .. ')[^/]*%' ..
|
||||||
o.zettel().extension .. '$'
|
o.zettel().extension .. '$'
|
||||||
|
|
||||||
local handle = vim.loop.fs_scandir(path)
|
local handle = vim.loop.fs_scandir(path)
|
||||||
|
@ -39,7 +39,9 @@ end
|
||||||
-- it will use the (recursive) results of the zettel_root directory.
|
-- it will use the (recursive) results of the zettel_root directory.
|
||||||
function ls.get_zettel(anchor, all)
|
function ls.get_zettel(anchor, all)
|
||||||
-- TODO why is there 'somepath' here?
|
-- TODO why is there 'somepath' here?
|
||||||
if not all then all = ls.get_anchors_and_paths('/home/marty/documents/notes') end
|
if not all then
|
||||||
|
all = ls.get_anchors_and_paths('/home/marty/documents/notes')
|
||||||
|
end
|
||||||
|
|
||||||
return all[anchor]
|
return all[anchor]
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,11 @@ local zettel_defaults = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local anchor_defaults = {
|
local anchor_defaults = {
|
||||||
separator = {vimname = "zettel_anchor_separator", default = "_"}
|
separator = {vimname = "zettel_anchor_separator", default = "_"},
|
||||||
|
regex = {
|
||||||
|
vimname = "zettel_anchor_regex",
|
||||||
|
default = '[%d][%d][%d][%d][%d][%d][%d][%d][%d][%d]'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- remaining options
|
-- remaining options
|
||||||
|
|
|
@ -15,19 +15,6 @@ describe("zettel options", function()
|
||||||
end)
|
end)
|
||||||
it("should return the default zettel extension if not set in vim",
|
it("should return the default zettel extension if not set in vim",
|
||||||
function() assert.same(".md", opt.zettel().extension) end)
|
function() assert.same(".md", opt.zettel().extension) end)
|
||||||
end)
|
|
||||||
|
|
||||||
describe("zettel options", function()
|
|
||||||
it("should return the global anchor separator if set in vim", function()
|
|
||||||
_G.vim.g.zettel_anchor_separator = "SEPARATE"
|
|
||||||
assert.same("SEPARATE", opt.anchor().separator)
|
|
||||||
end)
|
|
||||||
it("should return the buffer anchor separator if set in vim", function()
|
|
||||||
_G.vim.b.zettel_anchor_separator = "--"
|
|
||||||
assert.same("--", opt.anchor().separator)
|
|
||||||
end)
|
|
||||||
it("should return the default anchor separator if not set in vim",
|
|
||||||
function() assert.same("_", opt.anchor().separator) end)
|
|
||||||
|
|
||||||
it("should return the global link style if set in vim", function()
|
it("should return the global link style if set in vim", function()
|
||||||
_G.vim.g.zettel_link_style = "wiki"
|
_G.vim.g.zettel_link_style = "wiki"
|
||||||
|
@ -59,3 +46,29 @@ describe("zettel options", function()
|
||||||
assert.is_error(function() opt.zettel() end)
|
assert.is_error(function() opt.zettel() end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("anchor options", function()
|
||||||
|
it("should return the global anchor separator if set in vim", function()
|
||||||
|
_G.vim.g.zettel_anchor_separator = "SEPARATE"
|
||||||
|
assert.same("SEPARATE", opt.anchor().separator)
|
||||||
|
end)
|
||||||
|
it("should return the buffer anchor separator if set in vim", function()
|
||||||
|
_G.vim.b.zettel_anchor_separator = "--"
|
||||||
|
assert.same("--", opt.anchor().separator)
|
||||||
|
end)
|
||||||
|
it("should return the default anchor separator if not set in vim",
|
||||||
|
function() assert.same("_", opt.anchor().separator) end)
|
||||||
|
|
||||||
|
it("should return the anchor regex if set in vim", function()
|
||||||
|
vim.g.zettel_anchor_regex =
|
||||||
|
"[%d][%d][%d][%d][%d][%d][%d][%d][%d][%d][%d]?[%d]?"
|
||||||
|
-- allowing both 10- and 12-digit time-based zettel ids
|
||||||
|
assert.same('[%d][%d][%d][%d][%d][%d][%d][%d][%d][%d][%d]?[%d]?',
|
||||||
|
opt.anchor().regex)
|
||||||
|
end)
|
||||||
|
it("should return the default anchor regex if not set in vim", function()
|
||||||
|
assert.same('[%d][%d][%d][%d][%d][%d][%d][%d][%d][%d]',
|
||||||
|
opt.anchor().regex)
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
Loading…
Reference in a new issue