@@ -34,10 +34,95 @@ function Config:extend(opts)
34
34
self .todo_keywords = nil
35
35
opts = opts or {}
36
36
self :_deprecation_notify (opts )
37
+ if not self :_are_priorities_valid (opts ) then
38
+ opts .org_priority_highest = self .opts .org_priority_highest
39
+ opts .org_priority_lowest = self .opts .org_priority_lowest
40
+ opts .org_priority_default = self .opts .org_priority_default
41
+ end
37
42
self .opts = vim .tbl_deep_extend (' force' , self .opts , opts )
38
43
return self
39
44
end
40
45
46
+ function Config :_are_priorities_valid (opts )
47
+ local high = opts .org_priority_highest
48
+ local low = opts .org_priority_lowest
49
+ local default = opts .org_priority_default
50
+
51
+ if high or low or default then
52
+ -- assert that all three options are set
53
+ if not (high and low and default ) then
54
+ utils .echo_warning (
55
+ ' org_priority_highest, org_priority_lowest and org_priority_default can only be set together.'
56
+ .. ' Falling back to default priorities'
57
+ )
58
+ return false
59
+ end
60
+
61
+ -- numbers
62
+ if type (high ) == ' number' and type (low ) == ' number' and type (default ) == ' number' then
63
+ if high < 0 or low < 0 or default < 0 then
64
+ utils .echo_warning (
65
+ ' org_priority_highest, org_priority_lowest and org_priority_default cannot be negative.'
66
+ .. ' Falling back to default priorities'
67
+ )
68
+ return false
69
+ end
70
+ if high > low then
71
+ utils .echo_warning (
72
+ ' org_priority_highest cannot be bigger than org_priority_lowest. Falling back to default priorities'
73
+ )
74
+ return false
75
+ end
76
+ if default < high or default > low then
77
+ utils .echo_warning (
78
+ ' org_priority_default must be bigger than org_priority_highest and smaller than org_priority_lowest.'
79
+ .. ' Falling back to default priorities'
80
+ )
81
+ return false
82
+ end
83
+ -- one-char strings
84
+ elseif
85
+ (type (high ) == ' string' and # high == 1 )
86
+ and (type (low ) == ' string' and # low == 1 )
87
+ and (type (default ) == ' string' and # default == 1 )
88
+ then
89
+ if not high :match (' %a' ) or not low :match (' %a' ) or not default :match (' %a' ) then
90
+ utils .echo_warning (
91
+ ' org_priority_highest, org_priority_lowest and org_priority_default must be letters.'
92
+ .. ' Falling back to default priorities'
93
+ )
94
+ return false
95
+ end
96
+
97
+ high = string.byte (high )
98
+ low = string.byte (low )
99
+ default = string.byte (default )
100
+ if high > low then
101
+ utils .echo_warning (
102
+ ' org_priority_highest cannot be bigger than org_priority_lowest. Falling back to default priorities'
103
+ )
104
+ return false
105
+ end
106
+ if default < high or default > low then
107
+ utils .echo_warning (
108
+ ' org_priority_default must be bigger than org_priority_highest and smaller than org_priority_lowest.'
109
+ .. ' Falling back to default priorities'
110
+ )
111
+ return false
112
+ end
113
+ else
114
+ utils .echo_warning (
115
+ ' org_priority_highest, org_priority_lowest and org_priority_default must be either of type'
116
+ .. " 'number' or of type 'string' of length one. All three options need to agree on this type."
117
+ .. ' Falling back to default priorities'
118
+ )
119
+ return false
120
+ end
121
+ end
122
+
123
+ return true
124
+ end
125
+
41
126
function Config :_deprecation_notify (opts )
42
127
local messages = {}
43
128
if
0 commit comments