From a6f0420f09205a6e59292e0a38cca392976e6c52 Mon Sep 17 00:00:00 2001 From: drearondov <63360808+drearondov@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:24:14 -0500 Subject: [PATCH 1/2] Added icons and preview to `insert_file_link` and `insert_link` functions --- .../_extensions/neorg/insert_file_link.lua | 10 +++++--- .../_extensions/neorg/insert_link.lua | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lua/telescope/_extensions/neorg/insert_file_link.lua b/lua/telescope/_extensions/neorg/insert_file_link.lua index 4d3774b..6f390b9 100644 --- a/lua/telescope/_extensions/neorg/insert_file_link.lua +++ b/lua/telescope/_extensions/neorg/insert_file_link.lua @@ -74,15 +74,18 @@ local function generate_links(preview) if preview then title = get_file_title(file) if title then - title_display = " [" .. title .. "]" + title_display = "| " .. title end end file = Path(file) local relative = file:relative_to(Path(files[1])) + local relative_string = relative:remove_suffix(".norg"):tostring() + + local padding = 100 - #relative_string local links = { file = file, - display = "$/" .. relative .. title_display, + display = "󰈙 " .. relative_string .. string.rep(" ", padding) .. title_display, relative = relative:remove_suffix(".norg"), title = title, } @@ -106,6 +109,7 @@ return function(opts) entry_maker = function(entry) return { value = entry, + path = entry.file:tostring(), display = entry.display, ordinal = entry.display, relative = entry.relative, @@ -115,7 +119,7 @@ return function(opts) end, }), -- I couldn't get syntax highlight to work with this :( - previewer = nil, + previewer = conf.file_previewer(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) actions_set.select:replace(function() diff --git a/lua/telescope/_extensions/neorg/insert_link.lua b/lua/telescope/_extensions/neorg/insert_link.lua index 3381f4a..0ae16e4 100644 --- a/lua/telescope/_extensions/neorg/insert_link.lua +++ b/lua/telescope/_extensions/neorg/insert_link.lua @@ -34,11 +34,12 @@ end local function get_linkables(bufnr, file, workspace) local ret = {} + local path local lines if file then lines = vim.fn.readfile(file:tostring("/")) - file = file:remove_suffix(".norg") - file = "$/" .. file:relative_to(workspace) + path = file + file = " " .. file:relative_to(workspace):remove_suffix(".norg") else lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) end @@ -46,12 +47,15 @@ local function get_linkables(bufnr, file, workspace) for i, line in ipairs(lines) do local heading = { line:match("^%s*(%*+%s+(.+))$") } if not vim.tbl_isempty(heading) then - table.insert(ret, { line = i, linkable = heading[2], display = heading[1], file = file }) + table.insert(ret, { line = i, linkable = heading[2], display = heading[1], file = file, path = path }) end local marker_or_drawer = { line:match("^%s*(%|%|?%s+(.+))$") } if not vim.tbl_isempty(marker_or_drawer) then - table.insert(ret, { line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file }) + table.insert( + ret, + { line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file, path = path } + ) end end @@ -111,16 +115,16 @@ return function(opts) results = links, entry_maker = function(entry) local displayer = entry_display.create({ - separator = ": ", + separator = " | ", items = { - { width = 30 }, + { width = 100 }, { remaining = true }, }, }) local function make_display(ent) if entry.file then return displayer({ - { ent.file:sub(-30, -1), "NeorgLinkFile" }, + { ent.file, "NeorgLinkFile" }, { ent.ordinal, "NeorgLinkText" }, }) else @@ -129,6 +133,7 @@ return function(opts) }) end end + -- if not entry.file then -- entry.file = vim.fn.expand("%:r") -- end @@ -139,11 +144,12 @@ return function(opts) lnum = entry.line, file = entry.file and tostring(entry.file) or nil, linkable = entry.linkable, + path = entry.path:tostring(), } end, }), -- I couldn't get syntax highlight to work with this :( - previewer = nil, + previewer = conf.file_previewer(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) actions_set.select:replace(function() @@ -153,7 +159,7 @@ return function(opts) local inserted_file = (function() if entry.file then -- entry.display = string.gsub(entry.display, entry.file..": ", "") - return ":" .. entry.file .. ":" + return ":" .. string.gsub(entry.file, " ", "$/") .. ":" else return "" end From 1a0492d5c6ddb5dbef6ae90f25c966f76d69b5b2 Mon Sep 17 00:00:00 2001 From: drearondov <63360808+drearondov@users.noreply.github.com> Date: Tue, 23 Jul 2024 07:57:02 -0500 Subject: [PATCH 2/2] Added preview to `insert_file_link` and `insert_link` --- lua/telescope/_extensions/neorg/insert_file_link.lua | 11 ++++------- lua/telescope/_extensions/neorg/insert_link.lua | 11 +++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lua/telescope/_extensions/neorg/insert_file_link.lua b/lua/telescope/_extensions/neorg/insert_file_link.lua index 6f390b9..fb3b723 100644 --- a/lua/telescope/_extensions/neorg/insert_file_link.lua +++ b/lua/telescope/_extensions/neorg/insert_file_link.lua @@ -74,19 +74,17 @@ local function generate_links(preview) if preview then title = get_file_title(file) if title then - title_display = "| " .. title + title_display = " [" .. title .. "]" end end file = Path(file) - local relative = file:relative_to(Path(files[1])) - local relative_string = relative:remove_suffix(".norg"):tostring() + local relative = file:relative_to(Path(files[1])):tostring() - local padding = 100 - #relative_string local links = { file = file, - display = "󰈙 " .. relative_string .. string.rep(" ", padding) .. title_display, - relative = relative:remove_suffix(".norg"), + display = "$/" .. relative .. title_display, + relative = relative, title = title, } table.insert(res, links) @@ -118,7 +116,6 @@ return function(opts) } end, }), - -- I couldn't get syntax highlight to work with this :( previewer = conf.file_previewer(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) diff --git a/lua/telescope/_extensions/neorg/insert_link.lua b/lua/telescope/_extensions/neorg/insert_link.lua index 0ae16e4..16898e5 100644 --- a/lua/telescope/_extensions/neorg/insert_link.lua +++ b/lua/telescope/_extensions/neorg/insert_link.lua @@ -39,7 +39,7 @@ local function get_linkables(bufnr, file, workspace) if file then lines = vim.fn.readfile(file:tostring("/")) path = file - file = " " .. file:relative_to(workspace):remove_suffix(".norg") + file = "$/" .. file:relative_to(workspace):remove_suffix(".norg") else lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) end @@ -115,16 +115,16 @@ return function(opts) results = links, entry_maker = function(entry) local displayer = entry_display.create({ - separator = " | ", + separator = "", items = { - { width = 100 }, + { width = 55 }, { remaining = true }, }, }) local function make_display(ent) if entry.file then return displayer({ - { ent.file, "NeorgLinkFile" }, + { ent.file, "NeorgLinkFile" }, { ent.ordinal, "NeorgLinkText" }, }) else @@ -148,7 +148,6 @@ return function(opts) } end, }), - -- I couldn't get syntax highlight to work with this :( previewer = conf.file_previewer(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) @@ -159,7 +158,7 @@ return function(opts) local inserted_file = (function() if entry.file then -- entry.display = string.gsub(entry.display, entry.file..": ", "") - return ":" .. string.gsub(entry.file, " ", "$/") .. ":" + return ":" .. entry.file .. ":" else return "" end