From 1a58909e942a642fd8cb1f6248342cd6057f189d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 4 May 2021 09:46:18 +0200 Subject: [PATCH] Rename create_link to make_link Should prepare the differentiation between a 'new' link and linking an existing zetttel -- one is 'new_link' and one just 'makes_link' to something else. --- README.md | 6 ++++++ lua/zettelkasten/action.lua | 14 +++++++------- lua/zettelkasten/init.lua | 9 ++++----- plugin/zettelkasten.vim | 8 ++++---- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1487c5c..6ca4ddc 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ To develop / debug: start neovim with `nvim --cmd "set rtp+=$(pwd)" .` to automatically load the files in project dir as if they were on path +## up next + +* automatic switch between follow link / create link +* text.lua testing +* action.lua testing? + ## TODO: needed functionality * [ ] note creation (new anchor) diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 45226d5..069bbe4 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -1,8 +1,8 @@ local A = {} -local o = require 'zettelkasten.options' -local l = require 'zettelkasten.link' local f = require 'zettelkasten.files' +local l = require 'zettelkasten.link' +local o = require 'zettelkasten.options' local t = require 'zettelkasten.text' -- Opens the link passed in in the editor's current buffer. @@ -19,15 +19,15 @@ end -- Takes an optional style of link following to use, -- superseding the one set in options. function A.open_selected(style) - local st = style or o.link().following + style = style or o.link().following local curpos = vim.api.nvim_win_get_cursor(0)[2] local links = l.extract_all(vim.api.nvim_get_current_line()) local ln - if st == 'line' then + if style == 'line' then ln = t.get_next_link_on_line(links, curpos) - elseif st == 'cursor' then + elseif style == 'cursor' then ln = t.get_link_under_cursor(links, curpos) end @@ -37,7 +37,7 @@ end -- Replaces the current text context with a link to a new zettel. -- The current context is the visual selection (if called from visual mode) -- or the (big) word under the cursor if called from any other mode. -function A.link(visual) +function A.make_link(visual) local selection, start_col if visual or vim.api.nvim_get_mode()['mode'] == "v" then selection, start_col = t.get_current_selection() @@ -48,4 +48,4 @@ function A.link(visual) start_col)) end -return {open = A.open, open_selected = A.open_selected, link = A.link} +return {open = A.open, open_selected = A.open_selected, make_link = A.make_link} diff --git a/lua/zettelkasten/init.lua b/lua/zettelkasten/init.lua index 0993070..37df537 100644 --- a/lua/zettelkasten/init.lua +++ b/lua/zettelkasten/init.lua @@ -1,7 +1,6 @@ local ZK = {} -local ls = require 'zettelkasten.files' -local o = require 'zettelkasten.options' +local f = require 'zettelkasten.files' local anchor = require 'zettelkasten.anchor' local action = require 'zettelkasten.action' @@ -10,7 +9,7 @@ local action = require 'zettelkasten.action' -- table. -- Recurses into subdirectories if recursive argument is true. function ZK.get_zettel_list(path, recursive) - return ls.get_anchors_and_paths(ls.get_all_files(path, recursive or false)) + return f.get_anchors_and_paths(f.get_all_files(path, recursive or false)) end -- Return a valid zettelkasten anchor for the current time, @@ -21,11 +20,11 @@ function ZK.get_anchor() return anchor.create() end function ZK.open_link() return action.open_selected() end -- Create a new link under cursor -function ZK.create_link(visual) return action.link(visual) end +function ZK.make_link(visual) return action.make_link(visual) end return { get_zettel_list = ZK.get_zettel_list, get_anchor = ZK.get_anchor, open_link = ZK.open_link, - create_link = ZK.create_link + make_link = ZK.make_link } diff --git a/plugin/zettelkasten.vim b/plugin/zettelkasten.vim index 06a0003..d06f541 100644 --- a/plugin/zettelkasten.vim +++ b/plugin/zettelkasten.vim @@ -24,9 +24,9 @@ vnoremap zettel_link_open :lua require 'zettelkasten'.open_link() nmap i zettel_link_open vmap i zettel_link_open -nnoremap zettel_link_create :lua require 'zettelkasten'.create_link() -vnoremap zettel_link_create :lua require 'zettelkasten'.create_link(true) -nmap o zettel_link_create -vmap o zettel_link_create +nnoremap zettel_link_make :lua require 'zettelkasten'.make_link() +vnoremap zettel_link_make :lua require 'zettelkasten'.make_link(true) +nmap o zettel_link_make +vmap o zettel_link_make let g:loaded_zettelkasten = 1