-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Changes from all commits
2f32cd0
f468e45
3048f7f
f7b741c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
.. ")", | ||
.. "}" | ||
.. "[" | ||
.. 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, | ||
|
There was a problem hiding this comment.
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