Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated to current link format #6

Merged
merged 4 commits into from
Dec 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use readfile instead of buf_get_lines

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with readfile because it's much faster


-- 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed because of the readfile

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding this regex correctly this is checking for the various symbols that need escaping. If that is true, then we need to add all detached modifiers which can be linked against, right @vhyrro?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I don't think we need to escape custom symbols anymore, only } symbols in the case of {this} and ] symbols in the case of [this].

.. ")",
.. "}"
.. "["
.. 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