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:
parent
1a58909e94
commit
477ec45d22
3 changed files with 15 additions and 4 deletions
|
@ -6,7 +6,6 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi
|
||||||
|
|
||||||
## up next
|
## up next
|
||||||
|
|
||||||
* automatic switch between follow link / create link
|
|
||||||
* text.lua testing
|
* text.lua testing
|
||||||
* action.lua testing?
|
* action.lua testing?
|
||||||
|
|
||||||
|
@ -22,10 +21,11 @@ start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the fi
|
||||||
* [ ] list filenames
|
* [ ] list filenames
|
||||||
* [x] link following (to existing anchor)
|
* [x] link following (to existing anchor)
|
||||||
* [x] fallback to filename if anchor invalid / not found
|
* [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)
|
* [ ] link creation (to existing note)
|
||||||
* [ ] list existing
|
* [ ] list existing
|
||||||
* [ ] create link (md / wiki)
|
* [ ] 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)
|
* [ ] link switching (point to another existing note)
|
||||||
* [ ] note search (title / full-text)
|
* [ ] note search (title / full-text)
|
||||||
* [x] jump to zettel (open existing anchor)
|
* [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
|
* [ ] support *both* md-style and wiki-style links at the same time
|
||||||
* [ ] file/directory exception list for gathering files, which will be ignored
|
* [ ] file/directory exception list for gathering files, which will be ignored
|
||||||
* [ ] 'strict' mode *only* matching and following valid anchor links
|
* [ ] '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
|
## Options
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,10 @@ function A.open_selected(style)
|
||||||
ln = t.get_link_under_cursor(links, curpos)
|
ln = t.get_link_under_cursor(links, curpos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not ln then return false end
|
||||||
|
|
||||||
A.open(ln)
|
A.open(ln)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Replaces the current text context with a link to a new zettel.
|
-- 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.
|
-- or the (big) word under the cursor if called from any other mode.
|
||||||
function A.make_link(visual)
|
function A.make_link(visual)
|
||||||
local selection, start_col
|
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()
|
selection, start_col = t.get_current_selection()
|
||||||
else
|
else
|
||||||
selection, start_col = t.get_current_word()
|
selection, start_col = t.get_current_word()
|
||||||
|
|
|
@ -22,9 +22,16 @@ function ZK.open_link() return action.open_selected() end
|
||||||
-- Create a new link under cursor
|
-- Create a new link under cursor
|
||||||
function ZK.make_link(visual) return action.make_link(visual) end
|
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 {
|
return {
|
||||||
get_zettel_list = ZK.get_zettel_list,
|
get_zettel_list = ZK.get_zettel_list,
|
||||||
get_anchor = ZK.get_anchor,
|
get_anchor = ZK.get_anchor,
|
||||||
open_link = ZK.open_link,
|
open_link = ZK.open_link,
|
||||||
make_link = ZK.make_link
|
make_link = ZK.make_link,
|
||||||
|
open_or_make_link = ZK.open_or_make_link
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue