Rename imports and local vars to unify more
This commit is contained in:
parent
3f3e5ec7c2
commit
7c6882ac16
3 changed files with 16 additions and 13 deletions
|
@ -16,6 +16,7 @@ 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
|
||||
* [ ] link creation (to existing note)
|
||||
* [ ] list existing
|
||||
* [ ] create link (md / wiki)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
local A = {}
|
||||
|
||||
local o = require 'zettelkasten.options'
|
||||
local link = require 'zettelkasten.link'
|
||||
local files = require 'zettelkasten.files'
|
||||
local l = require 'zettelkasten.link'
|
||||
local f = 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 = files.get_zettel_by_anchor(zlink.anchor) or
|
||||
files.get_zettel_by_ref(zlink.ref) or zlink.ref
|
||||
function A.open(link)
|
||||
if not link or not link.ref then return end
|
||||
local fname = f.get_zettel_by_anchor(link.anchor) or
|
||||
f.get_zettel_by_ref(link.ref) or link.ref
|
||||
vim.api.nvim_command(string.format("edit %s", fname))
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ function A.open_selected(style)
|
|||
local st = style or o.link().following
|
||||
|
||||
local curpos = vim.api.nvim_win_get_cursor(0)[2]
|
||||
local links = link.extract_all(vim.api.nvim_get_current_line())
|
||||
local links = l.extract_all(vim.api.nvim_get_current_line())
|
||||
|
||||
local ln
|
||||
if st == 'line' then
|
||||
|
@ -38,8 +38,10 @@ 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)
|
||||
for _, l in pairs(links) do
|
||||
if l.startpos <= curpos + 1 and l.endpos > curpos then return l end
|
||||
for _, link in pairs(links) do
|
||||
if link.startpos <= curpos + 1 and link.endpos > curpos then
|
||||
return link
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ local parsers = {
|
|||
ref = "%[.-%]%((.-)%)",
|
||||
text = "%[(.-)%]%(.-%)",
|
||||
style_func = function(anchor, text, extension)
|
||||
local link = (a.prepend(anchor, L.urlify(L.trimmed(text))))
|
||||
return "[" .. L.trimmed(text) .. "](" .. link .. extension .. ")"
|
||||
local link = (a.prepend(anchor, L.urlify(L.trim(text))))
|
||||
return "[" .. L.trim(text) .. "](" .. link .. extension .. ")"
|
||||
end
|
||||
},
|
||||
wiki = {
|
||||
|
@ -17,7 +17,7 @@ local parsers = {
|
|||
text = "%[%[.-|?(.-)%]%]",
|
||||
style_func = function(anchor, text)
|
||||
local pipetxt = ""
|
||||
text = L.trimmed(text)
|
||||
text = L.trim(text)
|
||||
|
||||
if text and text ~= "" then pipetxt = "|" .. text end
|
||||
return "[[" .. anchor .. pipetxt .. "]]"
|
||||
|
@ -38,7 +38,7 @@ function L.append_extension(text) return text .. o.zettel().extension end
|
|||
|
||||
-- Returns text with surrounding whitespace trimmed. Returns empty string
|
||||
-- if only whitespace.
|
||||
function L.trimmed(text)
|
||||
function L.trim(text)
|
||||
if not text then return end
|
||||
return text:match '^()%s*$' and '' or text:match '^%s*(.*%S)'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue