Skip to content

Commit 69896b7

Browse files
committed
feat(core): enhance org-insert-link, add completion for prefix.
1 parent ac9a6e0 commit 69896b7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lua/orgmode/org/hyperlinks/init.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ function Hyperlinks.find_by_filepath(url)
2323
if not file_base then
2424
return {}
2525
end
26+
local is_home_relative_path = file_base:match('^~/')
27+
local process_file_to_home = function(home, file)
28+
-- file and home is of absolute path
29+
-- if there is a common prefix, replace it with ~
30+
if file:sub(1, #home) == home then
31+
return '~' .. file:sub(#home + 1)
32+
end
33+
end
34+
if is_home_relative_path then
35+
local home_abs = fs.get_home_dir()
36+
filenames = vim.tbl_map(function(f)
37+
return process_file_to_home(home_abs, f) or f
38+
end, filenames)
39+
end
2640
--TODO integrate with orgmode.utils.fs or orgmode.objects.url
2741
local file_base_no_start_path = vim.pesc(file_base:gsub('^%./', '') .. '')
2842
local is_relative_path = file_base:match('^%./')

lua/orgmode/utils/fs.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ function M.get_current_file_dir()
3939
return current_dir or ''
4040
end
4141

42+
function M.get_home_dir()
43+
return os.getenv('HOME') or ''
44+
end
45+
4246
return M

0 commit comments

Comments
 (0)