Skip to content

Commit

Permalink
feat(core): enhance org-insert-link, add completion for prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
PannenetsF committed Jun 9, 2024
1 parent ac9a6e0 commit 69896b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lua/orgmode/org/hyperlinks/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ function Hyperlinks.find_by_filepath(url)
if not file_base then
return {}
end
local is_home_relative_path = file_base:match('^~/')
local process_file_to_home = function(home, file)
-- file and home is of absolute path
-- if there is a common prefix, replace it with ~
if file:sub(1, #home) == home then
return '~' .. file:sub(#home + 1)
end
end
if is_home_relative_path then
local home_abs = fs.get_home_dir()
filenames = vim.tbl_map(function(f)
return process_file_to_home(home_abs, f) or f
end, filenames)
end
--TODO integrate with orgmode.utils.fs or orgmode.objects.url
local file_base_no_start_path = vim.pesc(file_base:gsub('^%./', '') .. '')
local is_relative_path = file_base:match('^%./')
Expand Down
4 changes: 4 additions & 0 deletions lua/orgmode/utils/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ function M.get_current_file_dir()
return current_dir or ''
end

function M.get_home_dir()
return os.getenv('HOME') or ''
end

return M

0 comments on commit 69896b7

Please sign in to comment.