Skip to content

Commit

Permalink
feat: updated to current link format (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 authored Dec 27, 2021
1 parent d6089ba commit 2ee2c92
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lua/telescope/_extensions/neorg/insert_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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+(.+))$") }
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2ee2c92

Please sign in to comment.