@@ -6,6 +6,7 @@ local defaults = require('orgmode.config.defaults')
6
6
local mappings = require (' orgmode.config.mappings' )
7
7
local TodoKeywords = require (' orgmode.objects.todo_keywords' )
8
8
local PriorityState = require (' orgmode.objects.priority_state' )
9
+ local Alias = require (' orgmode.org.hyperlinks.builtin.alias' )
9
10
10
11
--- @class OrgConfig : OrgDefaultConfig
11
12
--- @field opts table
@@ -53,13 +54,85 @@ function Config:extend(opts)
53
54
opts .org_priority_lowest = self .opts .org_priority_lowest
54
55
opts .org_priority_default = self .opts .org_priority_default
55
56
end
57
+ opts .hyperlinks = self :_process_links (opts .hyperlinks )
56
58
self .opts = vim .tbl_deep_extend (' force' , self .opts , opts )
57
59
if self .org_startup_indented then
58
60
self .org_adapt_indentation = not self .org_indent_mode_turns_off_org_adapt_indentation
59
61
end
60
62
return self
61
63
end
62
64
65
+ function Config :_process_links (links )
66
+ if not (links or type (links ) == table ) then
67
+ return nil
68
+ end
69
+
70
+ local processed = {}
71
+
72
+ for protocol , hyperlink in pairs (links ) do
73
+ if type (hyperlink ) == ' string' then
74
+ if not protocol then
75
+ utils .echo_warning ((' A link alias must have a protocol key. Skipped %s' ):format (hyperlink ))
76
+ else
77
+ hyperlink = self :_process_link_alias (protocol , hyperlink )
78
+ processed [hyperlink .protocol ] = hyperlink
79
+ end
80
+ goto continue
81
+ end
82
+
83
+ if type (hyperlink ) == ' table' then
84
+ hyperlink = self :_process_link_table (protocol , hyperlink )
85
+ if hyperlink then
86
+ processed [hyperlink .protocol ] = hyperlink
87
+ end
88
+ end
89
+
90
+ :: continue::
91
+ end
92
+
93
+ return processed
94
+ end
95
+
96
+ function Config :_process_link_table (protocol , link )
97
+ if not link .parse or not (type (link .parse ) == ' function' ) then
98
+ utils .echo_warning (" A link must have a 'parse' function." )
99
+ return
100
+ end
101
+
102
+ if not link .follow or not (type (link .follow ) == ' function' ) then
103
+ utils .echo_warning (" A link must have a 'follow' method." )
104
+ return
105
+ end
106
+
107
+ if not link .protocol then
108
+ if not protocol then
109
+ utils .echo_warning (' A link must have a protocol.' )
110
+ return
111
+ end
112
+ link .protocol = protocol
113
+ end
114
+
115
+ return link
116
+ end
117
+
118
+ function Config :_process_link_alias (protocol , alias )
119
+ local components = {}
120
+ local expression = vim .regex ([[ %s\|%h\|%(.-)]] )
121
+ repeat
122
+ local start_special , end_special = expression :match_str (alias )
123
+ if not start_special then
124
+ table.insert (components , alias )
125
+ break
126
+ end
127
+
128
+ table.insert (components , alias :sub (0 , start_special ))
129
+ table.insert (components , alias :sub (start_special + 1 , end_special ))
130
+ alias = alias :sub (end_special + 1 )
131
+ until # alias <= 0
132
+
133
+ return Alias (protocol , components )
134
+ end
135
+
63
136
function Config :_are_priorities_valid (opts )
64
137
local high = opts .org_priority_highest
65
138
local low = opts .org_priority_lowest
@@ -97,7 +170,7 @@ function Config:_are_priorities_valid(opts)
97
170
)
98
171
return false
99
172
end
100
- -- one-char strings
173
+ -- one-char strings
101
174
elseif
102
175
(type (high ) == ' string' and # high == 1 )
103
176
and (type (low ) == ' string' and # low == 1 )
0 commit comments