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: Opening hyperlinks externally #578

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ local DefaultConfig = {
deadline_reminder = true,
scheduled_reminder = true,
},
org_external_opener = 'xdg-open',
mappings = {
disable_all = false,
prefix = '<Leader>o',
Expand Down
11 changes: 11 additions & 0 deletions lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ function OrgMappings:open_at_point()
local parts = vim.split(link, '][', true)
local url = parts[1]
local link_ctx = { base = url, skip_add_prefix = true }

if url:find('^file:') then
if url:find(' +', 1, true) then
parts = vim.split(url, ' +', true)
Expand All @@ -766,6 +767,9 @@ function OrgMappings:open_at_point()

if url:find('^file:(.-)::') then
link_ctx.line = url
elseif vim.filetype.match({ filename = url }) == nil then
local filepath = Hyperlinks.get_file_real_path(url)
vim.fn.jobstart(config.org_external_opener .. ' ' .. vim.fn.shellescape(filepath), { detach = true })
else
vim.cmd(string.format('edit %s', Hyperlinks.get_file_real_path(url)))
vim.cmd([[normal! zv]])
Expand All @@ -783,6 +787,13 @@ function OrgMappings:open_at_point()
return vim.cmd(string.format('edit %s', url))
end

if url:find('^custom:') then
maidl0ver marked this conversation as resolved.
Show resolved Hide resolved
url = string.gsub(url, '^custom:', '')
local opener = string.gsub(url, '^(.-):.*', '%1')
local target = string.gsub(url, '^.-:', '')
vim.fn.jobstart(opener .. ' ' .. vim.fn.shellescape(target), { detach = true })
end

local headlines = Hyperlinks.find_matching_links(link_ctx)
local current_headline = Files.get_closest_headline()
if current_headline then
Expand Down