diff --git a/README.md b/README.md index 6ca4ddc..c24124b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi ## up next -* automatic switch between follow link / create link * text.lua testing * action.lua testing? @@ -22,10 +21,11 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi * [ ] list filenames * [x] link following (to existing anchor) * [x] fallback to filename if anchor invalid / not found - * [ ] maintain location list of previous jumps + * [x] maintain location list of previous jumps * [ ] link creation (to existing note) * [ ] list existing * [ ] create link (md / wiki) +* [x] allow same command for following/creating link depending on cursor over link or not * [ ] link switching (point to another existing note) * [ ] note search (title / full-text) * [x] jump to zettel (open existing anchor) @@ -80,6 +80,7 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi * [ ] support *both* md-style and wiki-style links at the same time * [ ] file/directory exception list for gathering files, which will be ignored * [ ] 'strict' mode *only* matching and following valid anchor links +* [ ] link creation - remove special marks, make customizable (e.g. i- will: help. -> i--will:-help..md [currently] -> i-will-help.md [possibly]) ## Options diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 069bbe4..28863e9 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -31,7 +31,10 @@ function A.open_selected(style) ln = t.get_link_under_cursor(links, curpos) end + if not ln then return false end + A.open(ln) + return true end -- Replaces the current text context with a link to a new zettel. @@ -39,7 +42,7 @@ end -- or the (big) word under the cursor if called from any other mode. function A.make_link(visual) local selection, start_col - if visual or vim.api.nvim_get_mode()['mode'] == "v" then + if visual then selection, start_col = t.get_current_selection() else selection, start_col = t.get_current_word() diff --git a/lua/zettelkasten/init.lua b/lua/zettelkasten/init.lua index 37df537..598b8da 100644 --- a/lua/zettelkasten/init.lua +++ b/lua/zettelkasten/init.lua @@ -22,9 +22,16 @@ function ZK.open_link() return action.open_selected() end -- Create a new link under cursor function ZK.make_link(visual) return action.make_link(visual) end +-- If invoked in reach of a valid link will try to follow said link. +-- Otherwise will take the current context and make a link out of it. +function ZK.open_or_make_link(visual) + if not ZK.open_link() then ZK.make_link(visual) end +end + return { get_zettel_list = ZK.get_zettel_list, get_anchor = ZK.get_anchor, open_link = ZK.open_link, - make_link = ZK.make_link + make_link = ZK.make_link, + open_or_make_link = ZK.open_or_make_link }