diff --git a/README.md b/README.md index 7f18b41..d526200 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi * [ ] add missing anchors * [ ] 'rename' anchor (goes against stability?) * [ ] recognize duplicate anchors (in directory, when listing, etc) + * [ ] potentially warn user * [ ] provide option to rename and automatically change backlinks * [ ] zettel 'lens' (preview first headline + content of linked zettel through floating window etc, on keypress) * [ ] support *both* md-style and wiki-style links at the same time diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 0319193..0b81bd8 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -2,16 +2,14 @@ local A = {} local o = require 'zettelkasten.options' local link = require 'zettelkasten.link' -local list = require 'zettelkasten.files' - -local BIGNUMBER = 10000000 +local files = require 'zettelkasten.files' -- Opens the link passed in in the editor's current buffer. -- Requires a link object passed in. function A.open(zlink) if not zlink or not zlink.ref then return end - local fname = list.get_zettel_by_anchor(zlink.anchor) or - list.get_zettel_by_ref(zlink.ref) or zlink.ref + local fname = files.get_zettel_by_anchor(zlink.anchor) or + files.get_zettel_by_ref(zlink.ref) or zlink.ref vim.api.nvim_command(string.format("edit %s", fname)) end @@ -25,13 +23,18 @@ function A.open_selected(style) local curpos = vim.api.nvim_win_get_cursor(0)[2] local links = link.extract_all(vim.api.nvim_get_current_line()) + local ln if st == 'line' then - A.open(A.get_next_link_on_line(links, curpos)) + ln = A.get_next_link_on_line(links, curpos) elseif st == 'cursor' then - A.open(A.get_link_under_cursor(links, curpos)) + ln = A.get_link_under_cursor(links, curpos) end + + A.open(ln) end +function A.create_link() return end + -- Returns the link currently under cursor, roughly the vim equivalent of yiW. -- Works for links containing spaces in their text or reference link. function A.get_link_under_cursor(links, curpos) @@ -43,7 +46,7 @@ end -- Returns the next link of the current line from the cursor onwards. function A.get_next_link_on_line(links, curpos) - local nearestpos = BIGNUMBER + local nearestpos = math.huge local nearestlink for _, ln in pairs(links) do if ln.endpos > curpos and ln.endpos < nearestpos then diff --git a/lua/zettelkasten/init.lua b/lua/zettelkasten/init.lua index 0824ef7..c12a727 100644 --- a/lua/zettelkasten/init.lua +++ b/lua/zettelkasten/init.lua @@ -10,7 +10,7 @@ local action = require 'zettelkasten.action' -- table. -- Recurses into subdirectories if recursive argument is true. function ZK.get_zettel_list(path, recursive) - return ls.get_anchors_and_paths(path, recursive or false) + return ls.get_anchors_and_paths(ls.get_all_files(path, recursive or false)) end -- Return a valid zettelkasten anchor for the current time,