From 2ee2c928e2e8cb9eef00acc3ec8c0926d81067ee Mon Sep 17 00:00:00 2001 From: max397574 <81827001+max397574@users.noreply.github.com> Date: Mon, 27 Dec 2021 18:49:34 +0100 Subject: [PATCH] feat: updated to current link format (#6) --- .../_extensions/neorg/insert_link.lua | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lua/telescope/_extensions/neorg/insert_link.lua b/lua/telescope/_extensions/neorg/insert_link.lua index 265ebcb..06a4dbd 100644 --- a/lua/telescope/_extensions/neorg/insert_link.lua +++ b/lua/telescope/_extensions/neorg/insert_link.lua @@ -32,11 +32,14 @@ end local function get_linkables(bufnr, file) local ret = {} + local lines if file then + lines = vim.fn.readfile(file) file = file:gsub(".norg", "") + else + lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) end - local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) for i, line in ipairs(lines) do local heading = { line:match("^%s*(%*+%s+(.+))$") } @@ -76,8 +79,6 @@ local function generate_links() return end - vim.fn.bufload(full_path_file) - -- Because we do not want file name to appear in a link to the same file local file_inserted = (function () if vim.api.nvim_get_current_buf() == bufnr then @@ -89,10 +90,6 @@ local function generate_links() local links = get_linkables(bufnr, file_inserted) - if vim.api.nvim_get_current_buf() ~= bufnr then - vim.cmd('bunload! ' .. bufnr) - end - vim.list_extend(res, links) end @@ -135,20 +132,20 @@ return function(opts) vim.api.nvim_put( { - "[" - .. entry.ordinal:gsub(":$", "") - .. "]" - .. "(" + "{" .. inserted_file - .. entry.display:gsub("^(%W+)%s+.+", "%1") + .. entry.display:gsub("^(%W+)%s+.+", "%1 ") .. entry.ordinal:gsub("[%*#%|_]", "\\%1") - .. ")", + .. "}" + .. "[" + .. entry.ordinal:gsub(":$", "") + .. "]", }, "c", false, true ) - vim.api.nvim_feedkeys("f)a", "t", false) + vim.api.nvim_feedkeys("hf]a", "t", false) end) return true end,