Add follow link command to go to or create link

Automatically chooses whether to create a new link or go to an existing
file, depending on the existence of a link in the current context (i.e.
under the cursor or in selection).
This commit is contained in:
Marty Oehme 2021-05-04 14:06:59 +02:00
parent 1a58909e94
commit 477ec45d22
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
3 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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()

View File

@ -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
}