Add configurable zettel root directory

Plugin will by default recursively look in this directory for any
zettel.
This commit is contained in:
Marty Oehme 2020-11-06 16:35:36 +01:00
parent 20a1eef2e4
commit 162057f149
Signed by: Marty
GPG key ID: B7538B8F50A1C800
5 changed files with 20 additions and 11 deletions

View file

@ -12,7 +12,7 @@ next up:
* [x] probably stop hardcoding anchor regex, make an option
* [ ] implement custom anchor creation function to go with custom regex
* [ ] opening zettel should use generated link table for full filename anchor search
* [ ] need a default zettel directory to look in
* [x] need a default zettel directory to look in
* [ ] implement fallback to filename
## TODO: needed functionality

View file

@ -36,10 +36,8 @@ end
-- Take a list of zettel as an optional variable, without which
-- it will use the (recursive) results of the zettel_root directory.
function ls.get_zettel(anchor, all)
-- TODO why is there 'somepath' here?
if not all then
all = ls.get_anchors_and_paths('/home/marty/documents/notes')
end
all = all or ls.get_anchors_and_paths(o.zettel().rootdir, true)
if not all then return end
return all[anchor]
end

View file

@ -150,12 +150,15 @@ describe("get_zettel", function()
assert.same("1910291645 myfile.md",
ls.get_zettel("1910291645", file_list))
end)
it("should return nil and not break on no all list passed in", function()
stub(ls, "get_anchors_and_paths")
assert.is_not_error(function() ls.get_zettel("myanchor") end)
end)
it("should default to the zettel root dir if no list passed in", function()
local file_list = {"1910291645 myfile.wiki", "2345678901 another.wiki"}
_G.vim = simple_api_mock(file_list)
local fc = stub(ls, "get_anchors_and_paths")
local expected = require'zettelkasten.options'.zettel().rootdir
pending("not implemented")
assert.same("1910291645 myfile.wiki", ls.get_zettel("1910291645"))
ls.get_zettel(expected)
assert.stub(fc).was_called_with(expected, true)
end)
end)

View file

@ -2,7 +2,8 @@ local Opt = {}
-- vim setting names and defaults
local zettel_defaults = {
extension = {vimname = "zettel_extension", default = ".md"}
extension = {vimname = "zettel_extension", default = ".md"},
rootdir = {vimname = "zettel_rootdir", default = "~/documents/notes"}
}
local link_defaults = {
style = {

View file

@ -15,6 +15,13 @@ describe("zettel options", function()
end)
it("should return the default zettel extension if not set in vim",
function() assert.same(".md", opt.zettel().extension) end)
it("should return the zettel root dir if set in vim", function()
_G.vim.g.zettel_rootdir = "~/my/own/dir"
assert.same("~/my/own/dir", opt.zettel().rootdir)
end)
it("should return the default root directory if not set in vim",
function() assert.same("~/documents/notes", opt.zettel().rootdir) end)
end)
describe("link options", function()