1
- #[ cfg( feature = "neovim-nightly" ) ]
2
- use oxi_types:: Boolean ;
3
- use oxi_types:: {
4
- self as nvim,
5
- conversion:: ToObject ,
6
- Function ,
7
- Integer ,
8
- Object ,
9
- } ;
1
+ use oxi_types as types;
2
+ use types:: conversion:: ToObject ;
10
3
11
4
use crate :: types:: {
12
5
CommandAddr ,
@@ -17,71 +10,90 @@ use crate::types::{
17
10
} ;
18
11
use crate :: Buffer ;
19
12
20
- /// Options passed to
21
- /// [`Buffer::create_user_command()`](crate::Buffer::create_user_command).
22
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
23
- #[ derive( Clone , Debug , Default ) ]
24
- #[ repr( C ) ]
25
- pub struct CreateCommandOpts {
26
- bar : Object ,
27
- addr : Object ,
28
- bang : Object ,
29
- desc : Object ,
30
- count : Object ,
31
- force : Object ,
32
- nargs : Object ,
33
- range : Object ,
34
- preview : Object ,
35
- complete : Object ,
36
- register_ : Object ,
37
- keepscript : Object ,
38
- }
39
-
40
13
/// Options passed to [`create_user_command`](crate::create_user_command) and
41
14
/// [`Buffer::create_user_command()`](crate::Buffer::create_user_command).
42
15
#[ cfg( feature = "neovim-nightly" ) ]
43
- #[ derive( Clone , Debug , Default ) ]
16
+ #[ derive( Clone , Debug , Default , oxi_macros :: OptsBuilder ) ]
44
17
#[ repr( C ) ]
45
18
pub struct CreateCommandOpts {
19
+ #[ builder( mask) ]
46
20
mask : u64 ,
47
21
48
- /// 2nd in the mask.
49
- addr : Object ,
50
-
51
- /// 3rd in the mask.
52
- bang : Boolean ,
22
+ #[ builder( argtype = "CommandAddr" , inline = "{0}.to_object().unwrap()" ) ]
23
+ addr : types:: Object ,
53
24
54
- /// 1st in the mask.
55
- bar : Boolean ,
25
+ # [ builder ( argtype = "bool" ) ]
26
+ bang : types :: Boolean ,
56
27
57
- /// 10th in the mask.
58
- complete : Object ,
28
+ # [ builder ( argtype = "bool" ) ]
29
+ bar : types :: Boolean ,
59
30
60
- /// 5th in the mask.
61
- count : Object ,
31
+ #[ builder(
32
+ argtype = "CommandComplete" ,
33
+ inline = "{0}.to_object().unwrap()"
34
+ ) ]
35
+ complete : types:: Object ,
62
36
63
- /// 4th in the mask.
64
- desc : Object ,
37
+ // TODO: fix `builder(Into)`.
38
+ #[ builder(
39
+ generics = "C: Into<types::Integer>" ,
40
+ argtype = "C" ,
41
+ inline = "{0}.into().into()"
42
+ ) ]
43
+ count : types:: Object ,
65
44
66
- /// 6th in the mask.
67
- force : Boolean ,
68
-
69
- /// 12th in the mask.
70
- keepscript : Boolean ,
71
-
72
- /// 7th in the mask.
73
- nargs : Object ,
74
-
75
- /// 9th in the mask.
76
- preview : Object ,
77
-
78
- /// 8th in the mask.
79
- range : Object ,
45
+ /// Description for the command.
46
+ #[ builder(
47
+ generics = "C: Into<types::String>" ,
48
+ argtype = "C" ,
49
+ inline = "{0}.into().into()"
50
+ ) ]
51
+ desc : types:: Object ,
52
+
53
+ #[ builder( argtype = "bool" ) ]
54
+ force : types:: Boolean ,
55
+
56
+ #[ builder( argtype = "bool" ) ]
57
+ keepscript : types:: Boolean ,
58
+
59
+ #[ builder( argtype = "CommandNArgs" , inline = "{0}.to_object().unwrap()" ) ]
60
+ nargs : types:: Object ,
61
+
62
+ #[ builder(
63
+ generics = r#"F: Into<types::Function<(CommandArgs, Option<u32>, Option<Buffer>), u8>>"# ,
64
+ argtype = "F" ,
65
+ inline = "{0}.into().into()"
66
+ ) ]
67
+ preview : types:: Object ,
68
+
69
+ #[ builder( argtype = "CommandRange" , inline = "{0}.to_object().unwrap()" ) ]
70
+ range : types:: Object ,
71
+
72
+ #[ builder( method = "register" , argtype = "bool" ) ]
73
+ register_ : types:: Boolean ,
74
+ }
80
75
81
- /// 11th in the mask.
82
- register_ : Boolean ,
76
+ /// Options passed to
77
+ /// [`Buffer::create_user_command()`](crate::Buffer::create_user_command).
78
+ #[ cfg( any( feature = "neovim-0-8" , feature = "neovim-0-9" ) ) ]
79
+ #[ derive( Clone , Debug , Default ) ]
80
+ #[ repr( C ) ]
81
+ pub struct CreateCommandOpts {
82
+ bar : types:: Object ,
83
+ addr : types:: Object ,
84
+ bang : types:: Object ,
85
+ desc : types:: Object ,
86
+ count : types:: Object ,
87
+ force : types:: Object ,
88
+ nargs : types:: Object ,
89
+ range : types:: Object ,
90
+ preview : types:: Object ,
91
+ complete : types:: Object ,
92
+ register_ : types:: Object ,
93
+ keepscript : types:: Object ,
83
94
}
84
95
96
+ #[ cfg( any( feature = "neovim-0-8" , feature = "neovim-0-9" ) ) ]
85
97
impl CreateCommandOpts {
86
98
#[ inline( always) ]
87
99
/// Creates a new [`CreateCommandOptsBuilder`].
@@ -90,151 +102,87 @@ impl CreateCommandOpts {
90
102
}
91
103
}
92
104
105
+ #[ cfg( any( feature = "neovim-0-8" , feature = "neovim-0-9" ) ) ]
93
106
#[ derive( Clone , Default ) ]
94
107
pub struct CreateCommandOptsBuilder ( CreateCommandOpts ) ;
95
108
109
+ #[ cfg( any( feature = "neovim-0-8" , feature = "neovim-0-9" ) ) ]
96
110
impl CreateCommandOptsBuilder {
97
111
#[ inline]
98
112
pub fn addr ( & mut self , addr : CommandAddr ) -> & mut Self {
99
113
self . 0 . addr = addr. to_object ( ) . unwrap ( ) ;
100
- #[ cfg( feature = "neovim-nightly" ) ]
101
- {
102
- self . 0 . mask |= 0b101 ;
103
- }
104
114
self
105
115
}
106
116
107
117
#[ inline]
108
118
pub fn bang ( & mut self , bang : bool ) -> & mut Self {
109
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
110
- {
111
- self . 0 . bang = bang. into ( ) ;
112
- }
113
- #[ cfg( feature = "neovim-nightly" ) ]
114
- {
115
- self . 0 . bang = bang;
116
- self . 0 . mask |= 0b1001 ;
117
- }
119
+ self . 0 . bang = bang. into ( ) ;
118
120
self
119
121
}
120
122
121
123
#[ inline]
122
124
pub fn bar ( & mut self , bar : bool ) -> & mut Self {
123
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
124
- {
125
- self . 0 . bar = bar. into ( ) ;
126
- }
127
- #[ cfg( feature = "neovim-nightly" ) ]
128
- {
129
- self . 0 . bar = bar;
130
- self . 0 . mask |= 0b11 ;
131
- }
125
+ self . 0 . bar = bar. into ( ) ;
132
126
self
133
127
}
134
128
135
129
#[ inline]
136
130
pub fn complete ( & mut self , complete : CommandComplete ) -> & mut Self {
137
131
self . 0 . complete = complete. to_object ( ) . unwrap ( ) ;
138
- #[ cfg( feature = "neovim-nightly" ) ]
139
- {
140
- self . 0 . mask |= 0b10000000001 ;
141
- }
142
132
self
143
133
}
144
134
145
135
#[ inline]
146
- pub fn count ( & mut self , count : impl Into < Integer > ) -> & mut Self {
136
+ pub fn count ( & mut self , count : impl Into < types :: Integer > ) -> & mut Self {
147
137
self . 0 . count = count. into ( ) . into ( ) ;
148
- #[ cfg( feature = "neovim-nightly" ) ]
149
- {
150
- self . 0 . mask |= 0b100001 ;
151
- }
152
138
self
153
139
}
154
140
155
141
/// Description for the command.
156
142
#[ inline]
157
- pub fn desc ( & mut self , desc : impl Into < nvim :: String > ) -> & mut Self {
143
+ pub fn desc < S : Into < types :: String > > ( & mut self , desc : S ) -> & mut Self {
158
144
self . 0 . desc = desc. into ( ) . into ( ) ;
159
- #[ cfg( feature = "neovim-nightly" ) ]
160
- {
161
- self . 0 . mask |= 0b10001 ;
162
- }
163
145
self
164
146
}
165
147
166
148
#[ inline]
167
149
pub fn force ( & mut self , force : bool ) -> & mut Self {
168
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
169
- {
170
- self . 0 . force = force. into ( ) ;
171
- }
172
- #[ cfg( feature = "neovim-nightly" ) ]
173
- {
174
- self . 0 . force = force;
175
- self . 0 . mask |= 0b1000001 ;
176
- }
150
+ self . 0 . force = force. into ( ) ;
177
151
self
178
152
}
179
153
180
154
#[ inline]
181
155
pub fn keepscript ( & mut self , keepscript : bool ) -> & mut Self {
182
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
183
- {
184
- self . 0 . keepscript = keepscript. into ( ) ;
185
- }
186
- #[ cfg( feature = "neovim-nightly" ) ]
187
- {
188
- self . 0 . keepscript = keepscript;
189
- self . 0 . mask |= 0b1000000000001 ;
190
- }
156
+ self . 0 . keepscript = keepscript. into ( ) ;
191
157
self
192
158
}
193
159
194
160
#[ inline]
195
161
pub fn nargs ( & mut self , nargs : CommandNArgs ) -> & mut Self {
196
162
self . 0 . nargs = nargs. to_object ( ) . unwrap ( ) ;
197
- #[ cfg( feature = "neovim-nightly" ) ]
198
- {
199
- self . 0 . mask |= 0b10000001 ;
200
- }
201
163
self
202
164
}
203
165
204
166
#[ inline]
205
167
pub fn preview < F > ( & mut self , fun : F ) -> & mut Self
206
168
where
207
- F : Into < Function < ( CommandArgs , Option < u32 > , Option < Buffer > ) , u8 > > ,
169
+ F : Into <
170
+ types:: Function < ( CommandArgs , Option < u32 > , Option < Buffer > ) , u8 > ,
171
+ > ,
208
172
{
209
173
self . 0 . preview = fun. into ( ) . into ( ) ;
210
- #[ cfg( feature = "neovim-nightly" ) ]
211
- {
212
- self . 0 . mask |= 0b1000000001 ;
213
- }
214
174
self
215
175
}
216
176
217
177
#[ inline]
218
178
pub fn range ( & mut self , range : CommandRange ) -> & mut Self {
219
179
self . 0 . range = range. to_object ( ) . unwrap ( ) ;
220
- #[ cfg( feature = "neovim-nightly" ) ]
221
- {
222
- self . 0 . mask |= 0b100000001 ;
223
- }
224
180
self
225
181
}
226
182
227
183
#[ inline]
228
184
pub fn register ( & mut self , register : bool ) -> & mut Self {
229
- #[ cfg( not( feature = "neovim-nightly" ) ) ]
230
- {
231
- self . 0 . register_ = register. into ( ) ;
232
- }
233
- #[ cfg( feature = "neovim-nightly" ) ]
234
- {
235
- self . 0 . register_ = register;
236
- self . 0 . mask |= 0b100000000001 ;
237
- }
185
+ self . 0 . register_ = register. into ( ) ;
238
186
self
239
187
}
240
188
0 commit comments