Add opening zettel by reference if no anchor found
Opens zettel by linked value, most often a direct path link, but will also look through the root dir to find a(n exactly) matching basename to open. If nothing is found in the root dir will open a new file to write with the corresponding name. Careful, if the reference is a full path definition, and the file does not exist, it will still open the corresponding file at the correct location but when attempting to save will generally complain if parts of the path are missing. They have to be created manually or in some other place, this is outside the scope of this plugin.
This commit is contained in:
parent
43673aaf35
commit
fdcb0f2a93
4 changed files with 9 additions and 2 deletions
|
@ -81,6 +81,7 @@ next up:
|
||||||
* i.e. if 2030101200 exists move to 2030101159, 2030101158, ...
|
* i.e. if 2030101200 exists move to 2030101159, 2030101158, ...
|
||||||
* if moving backwards, we do not take away id space from *future* note creation
|
* if moving backwards, we do not take away id space from *future* note creation
|
||||||
* if moving forwards, every zettel created within a minute would delay next zettel creation *another* minute
|
* if moving forwards, every zettel created within a minute would delay next zettel creation *another* minute
|
||||||
|
* to decide: should zettel creation create a zettel in current working dir or at zettel root dir? or set by option?
|
||||||
|
|
||||||
* [ ] (CODE) switch -- comments to --- doc comments for function descriptions etc
|
* [ ] (CODE) switch -- comments to --- doc comments for function descriptions etc
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ local BIGNUMBER = 10000000
|
||||||
-- Requires a link object passed in.
|
-- Requires a link object passed in.
|
||||||
function A.open(zlink)
|
function A.open(zlink)
|
||||||
if not zlink or not zlink.ref then return end
|
if not zlink or not zlink.ref then return end
|
||||||
local fname = list.get_zettel_by_anchor(zlink.anchor) or zlink.ref
|
local fname = list.get_zettel_by_anchor(zlink.anchor) or
|
||||||
|
list.get_zettel_by_ref(zlink.ref) or zlink.ref
|
||||||
vim.api.nvim_command(string.format("edit %s", fname))
|
vim.api.nvim_command(string.format("edit %s", fname))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ describe("open", function()
|
||||||
vim.fn = {expand = function() end}
|
vim.fn = {expand = function() end}
|
||||||
assert.is_not_error(action.open)
|
assert.is_not_error(action.open)
|
||||||
end)
|
end)
|
||||||
it("should use the anchor to open the corresponding zettel", function()
|
it("should first use the anchor to open the corresponding zettel",
|
||||||
|
function()
|
||||||
vim.api = {nvim_command = mock(function() end)}
|
vim.api = {nvim_command = mock(function() end)}
|
||||||
local ls = stub(require 'zettelkasten.files', "get_zettel_by_anchor")
|
local ls = stub(require 'zettelkasten.files', "get_zettel_by_anchor")
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,10 @@ function ls.get_zettel_by_anchor(anchor, files)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns the path to the zettel defined by a reference link.
|
-- Returns the path to the zettel defined by a reference link.
|
||||||
|
-- Will prefer a fully matching path to only matching basename
|
||||||
|
-- of a file, but if only basename is found will return first
|
||||||
|
-- matching one.
|
||||||
|
--
|
||||||
-- Takes a set of files as optional variable in.
|
-- Takes a set of files as optional variable in.
|
||||||
-- If no set provided will use the (recursive) results
|
-- If no set provided will use the (recursive) results
|
||||||
-- of zettel_root directory.
|
-- of zettel_root directory.
|
||||||
|
|
Loading…
Reference in a new issue