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 * [x] probably stop hardcoding anchor regex, make an option
* [ ] implement custom anchor creation function to go with custom regex * [ ] implement custom anchor creation function to go with custom regex
* [ ] opening zettel should use generated link table for full filename anchor search * [ ] 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 * [ ] implement fallback to filename
## TODO: needed functionality ## TODO: needed functionality

View file

@ -36,10 +36,8 @@ end
-- Take a list of zettel as an optional variable, without which -- Take a list of zettel as an optional variable, without which
-- 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? all = all or ls.get_anchors_and_paths(o.zettel().rootdir, true)
if not all then if not all then return end
all = ls.get_anchors_and_paths('/home/marty/documents/notes')
end
return all[anchor] return all[anchor]
end end

View file

@ -150,12 +150,15 @@ describe("get_zettel", function()
assert.same("1910291645 myfile.md", assert.same("1910291645 myfile.md",
ls.get_zettel("1910291645", file_list)) ls.get_zettel("1910291645", file_list))
end) 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() it("should default to the zettel root dir if no list passed in", function()
local file_list = {"1910291645 myfile.wiki", "2345678901 another.wiki"} local fc = stub(ls, "get_anchors_and_paths")
_G.vim = simple_api_mock(file_list) local expected = require'zettelkasten.options'.zettel().rootdir
pending("not implemented") ls.get_zettel(expected)
assert.same("1910291645 myfile.wiki", ls.get_zettel("1910291645")) assert.stub(fc).was_called_with(expected, true)
end) end)
end) end)

View file

@ -2,7 +2,8 @@ local Opt = {}
-- vim setting names and defaults -- vim setting names and defaults
local zettel_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 = { local link_defaults = {
style = { style = {

View file

@ -15,6 +15,13 @@ 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)
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) end)
describe("link options", function() describe("link options", function()