Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2eebc98

Browse files
feat(links): Open non-editable links with vim.ui.open
Links that are not editable in Neovim are now opened with `vim.ui.open`, like pdfs, images, or anything else that cannot be detected with `vim.filetype.match`. Closes #905
1 parent 1e627fc commit 2eebc98

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

lua/orgmode/org/links/types/http.lua

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@ function OrgLinkHttp:follow(link)
2626
return false
2727
end
2828

29-
if vim.ui['open'] then
30-
vim.ui.open(url)
31-
return true
32-
end
33-
34-
if not vim.g.loaded_netrwPlugin then
35-
utils.echo_warning('Netrw plugin must be loaded in order to open urls.')
36-
return false
37-
end
38-
39-
vim.fn['netrw#BrowseX'](url, vim.fn['netrw#CheckIfRemote']())
29+
vim.ui.open(url)
4030
return true
4131
end
4232

lua/orgmode/org/links/utils.lua

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
local utils = require('orgmode.utils')
22
local link_utils = {}
33

4+
local external_filetypes = {
5+
-- pdf is considered a valid filetype even though it cannot be correctly read
6+
'pdf',
7+
}
8+
9+
---@param filename string
10+
---@return boolean - if editable, returns true, otherwise false
11+
local function edit_file(filename)
12+
local filetype = vim.filetype.match({ filename = filename })
13+
if not filetype or vim.tbl_contains(external_filetypes, filetype) then
14+
vim.ui.open(filename)
15+
return false
16+
end
17+
vim.cmd(('edit %s'):format(filename))
18+
return true
19+
end
20+
421
---@param file OrgFile
522
---@return boolean
623
function link_utils.goto_file(file)
7-
vim.cmd(('edit %s'):format(file.filename))
24+
edit_file(file.filename)
825
return true
926
end
1027

@@ -54,7 +71,11 @@ function link_utils.open_file_and_search(file_path, search_text)
5471
return true
5572
end
5673
if file_path ~= utils.current_file_path() then
57-
vim.cmd(('edit %s'):format(file_path))
74+
local editable = edit_file(file_path)
75+
-- Return without attempt to find text. File is not editable.
76+
if not editable then
77+
return true
78+
end
5879
end
5980

6081
if not search_text or search_text == '' then

0 commit comments

Comments
 (0)