diff --git a/README.md b/README.md index b63ca69..a20efc5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/zettelkasten/list.lua b/lua/zettelkasten/list.lua index c71db73..6525498 100644 --- a/lua/zettelkasten/list.lua +++ b/lua/zettelkasten/list.lua @@ -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 diff --git a/lua/zettelkasten/list_spec.lua b/lua/zettelkasten/list_spec.lua index 8ad56da..e97c42d 100644 --- a/lua/zettelkasten/list_spec.lua +++ b/lua/zettelkasten/list_spec.lua @@ -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) diff --git a/lua/zettelkasten/options.lua b/lua/zettelkasten/options.lua index 09542af..799cfa5 100644 --- a/lua/zettelkasten/options.lua +++ b/lua/zettelkasten/options.lua @@ -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 = { diff --git a/lua/zettelkasten/options_spec.lua b/lua/zettelkasten/options_spec.lua index c0c4e30..741ac8f 100644 --- a/lua/zettelkasten/options_spec.lua +++ b/lua/zettelkasten/options_spec.lua @@ -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()