Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ local DefaultConfig = {
deadline_reminder = true,
scheduled_reminder = true,
},
org_nontext_hyperlinks = false,
org_external_opener = 'xdg-open',
org_link_types = {
shell = {
handler = function(url)
url = string.gsub(url, '^shell:', '')
vim.fn.jobstart(url, { detach = true })
return
end,
},
},
mappings = {
disable_all = false,
prefix = '<Leader>o',
Expand Down
10 changes: 10 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 config.org_nontext_hyperlinks and 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,12 @@ function OrgMappings:open_at_point()
return vim.cmd(string.format('edit %s', url))
end

pref = string.gsub(url, '^(.-):.*', '%1')
if config.org_link_types[pref] ~= nil then
config.org_link_types[pref].handler(url)
return
end

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