@@ -2,7 +2,7 @@ local Calendar = require('orgmode.objects.calendar')
2
2
local Date = require (' orgmode.objects.date' )
3
3
local EditSpecial = require (' orgmode.objects.edit_special' )
4
4
local Help = require (' orgmode.objects.help' )
5
- local Hyperlinks = require (' orgmode.org.hyperlinks ' )
5
+ local OrgHyperlink = require (' orgmode.org.links.hyperlink ' )
6
6
local PriorityState = require (' orgmode.objects.priority_state' )
7
7
local TodoState = require (' orgmode.objects.todo_state' )
8
8
local config = require (' orgmode.config' )
@@ -785,18 +785,20 @@ end
785
785
-- Inserts a new link after the cursor position or modifies the link the cursor is
786
786
-- currently on
787
787
function OrgMappings :insert_link ()
788
- local link_location = vim .fn .OrgmodeInput (' Links: ' , ' ' , Hyperlinks .autocomplete_links )
788
+ local link_location = vim .fn .OrgmodeInput (' Links: ' , ' ' , function (arg_lead )
789
+ return self .links :autocomplete (arg_lead )
790
+ end )
789
791
if vim .trim (link_location ) == ' ' then
790
792
utils .echo_warning (' No Link selected' )
791
793
return
792
794
end
793
795
794
- Hyperlinks . insert_link (link_location )
796
+ self . links : insert_link (link_location )
795
797
end
796
798
797
799
function OrgMappings :store_link ()
798
800
local headline = self .files :get_closest_headline ()
799
- Hyperlinks . store_link_to_headline (headline )
801
+ self . links : store_link_to_headline (headline )
800
802
return utils .echo_info (' Stored: ' .. headline :get_title ())
801
803
end
802
804
@@ -861,7 +863,7 @@ function OrgMappings:add_note()
861
863
end
862
864
863
865
function OrgMappings :open_at_point ()
864
- local link = Hyperlinks . get_link_under_cursor ()
866
+ local link = OrgHyperlink . at_cursor ()
865
867
if not link then
866
868
local date = self :_get_date_under_cursor ()
867
869
if date then
@@ -870,91 +872,7 @@ function OrgMappings:open_at_point()
870
872
return
871
873
end
872
874
873
- -- handle external links (non-org or without org-specific line target)
874
-
875
- if link .url :is_id () then
876
- local id = link .url :get_id () or ' '
877
- local files = self .files :find_files_with_property (' id' , id )
878
- if # files > 0 then
879
- if # files > 1 then
880
- utils .echo_warning (string.format (' Multiple files found with id: %s, jumping to first one found' , id ))
881
- end
882
- vim .cmd ((' edit %s' ):format (files [1 ].filename ))
883
- return
884
- end
885
-
886
- local headlines = self .files :find_headlines_with_property (' id' , id )
887
- if # headlines == 0 then
888
- return utils .echo_warning (string.format (' No headline found with id: %s' , id ))
889
- end
890
- if # headlines > 1 then
891
- return utils .echo_warning (string.format (' Multiple headlines found with id: %s' , id ))
892
- end
893
- local headline = headlines [1 ]
894
- return self :_goto_headline (headline )
895
- end
896
-
897
- if link .url :is_file_line_number () then
898
- local line_number = link .url :get_line_number () or 0
899
- local file_path = link .url :get_file () or utils .current_file_path ()
900
- local cmd = string.format (' edit +%s %s' , line_number , fs .get_real_path (file_path ))
901
- vim .cmd (cmd )
902
- return vim .cmd ([[ normal! zv]] )
903
- end
904
-
905
- if link .url :is_external_url () then
906
- if vim .ui [' open' ] then
907
- return vim .ui .open (link .url :to_string ())
908
- end
909
- if not vim .g .loaded_netrwPlugin then
910
- return utils .echo_warning (' Netrw plugin must be loaded in order to open urls.' )
911
- end
912
- return vim .fn [' netrw#BrowseX' ](link .url :to_string (), vim .fn [' netrw#CheckIfRemote' ]())
913
- end
914
-
915
- if link .url :is_file_only () then
916
- local file_path = link .url :get_file ()
917
- local cmd = file_path and string.format (' edit %s' , fs .get_real_path (file_path )) or ' '
918
- vim .cmd (cmd )
919
- vim .cmd ([[ normal! zv]] )
920
- end
921
-
922
- if link .url .protocol and not link .url :is_supported_protocol () then
923
- utils .echo_warning (string.format (' Unsupported link protocol: %q' , link .url .protocol ))
924
- return
925
- end
926
-
927
- local headlines = Hyperlinks .find_matching_links (link .url )
928
- local current_headline = self .files :get_closest_headline_or_nil ()
929
- if current_headline then
930
- headlines = vim .tbl_filter (function (headline )
931
- return not current_headline :is_same (headline )
932
- end , headlines )
933
- end
934
- if # headlines == 0 then
935
- return
936
- end
937
- local headline = headlines [1 ]
938
- if # headlines > 1 then
939
- local longest_headline = utils .reduce (headlines , function (acc , h )
940
- return math.max (acc , h :get_headline_line_content ():len ())
941
- end , 0 )
942
- local options = {}
943
- for i , h in ipairs (headlines ) do
944
- table.insert (
945
- options ,
946
- string.format (' %d) %-' .. longest_headline .. ' s (%s)' , i , h :get_headline_line_content (), h .file .filename )
947
- )
948
- end
949
- vim .cmd ([[ echo "Multiple targets found. Select target:"]] )
950
- local choice = vim .fn .inputlist (options )
951
- if choice < 1 or choice > # headlines then
952
- return
953
- end
954
- headline = headlines [choice ]
955
- end
956
-
957
- return self :_goto_headline (headline )
875
+ return self .links :follow (link .url :to_string ())
958
876
end
959
877
960
878
function OrgMappings :export ()
0 commit comments