From 7c6882ac16c9f41ea7f966cb81804f6de450f93d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 3 May 2021 17:29:42 +0200 Subject: [PATCH] Rename imports and local vars to unify more --- README.md | 1 + lua/zettelkasten/action.lua | 20 +++++++++++--------- lua/zettelkasten/link.lua | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d526200..1487c5c 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 0b81bd8..3e7a1ef 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -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 diff --git a/lua/zettelkasten/link.lua b/lua/zettelkasten/link.lua index 8eff6a7..0ef5d77 100644 --- a/lua/zettelkasten/link.lua +++ b/lua/zettelkasten/link.lua @@ -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