Add Zettel ref getting defaulting to root dir

This commit is contained in:
Marty Oehme 2021-04-30 16:10:16 +02:00
parent e2a97570e0
commit 4aa9d98818
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 12 additions and 5 deletions

View file

@ -82,6 +82,8 @@ next up:
* 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
* [ ] (CODE) switch -- comments to --- doc comments for function descriptions etc
## Options
atm:

View file

@ -44,10 +44,10 @@ end
function A.get_next_link_on_line(links, curpos)
local nearestpos = BIGNUMBER
local nearestlink
for k, link in pairs(links) do
if link.endpos > curpos and link.endpos < nearestpos then
nearestpos = link.endpos
nearestlink = link
for _, ln in pairs(links) do
if ln.endpos > curpos and ln.endpos < nearestpos then
nearestpos = ln.endpos
nearestlink = ln
end
end
return nearestlink

View file

@ -75,7 +75,13 @@ function ls.get_zettel_by_anchor(anchor, all)
return all[anchor]
end
-- Returns the path to the zettel defined by a reference link.
-- Takes a set of files as optional variable in.
-- If no set provided will use the (recursive) results
-- of zettel_root directory.
function ls.get_zettel_by_ref(ref, files)
files = files or ls.get_all_files(o.zettel().rootdir, true)
local name_only_match
for full_path, bname in pairs(files) do
if full_path == ref then return full_path end
@ -84,5 +90,4 @@ function ls.get_zettel_by_ref(ref, files)
return name_only_match
end
return ls