aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/UltiSnips/d.snippets
blob: 9ce27513026b4c156a684f86302f3f7322d56b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# Simple shortcuts

priority -50

snippet imp "import (imp)" b
import ${1:std.stdio};
endsnippet

snippet pimp "public import (pimp)" b
public import ${1:/*module*/};
endsnippet

snippet over "override (over)" b
override ${1:/*function*/}
endsnippet

snippet al "alias (al)"
alias ${1:/*orig*/} ${2:/*alias*/};
endsnippet

snippet mixin "mixin (mixin)" b
mixin ${1:/*mixed_in*/} ${2:/*name*/};
endsnippet

snippet new "new (new)"
new ${1}(${2});
endsnippet

snippet scpn "@safe const pure nothrow (scpn)"
@safe const pure nothrow
endsnippet

snippet spn "@safe pure nothrow (spn)"
@safe pure nothrow
endsnippet

snippet cont "continue (cont)"
continue;
endsnippet

snippet dis "@disable (dis)" b
@disable ${1:/*method*/};
endsnippet

snippet pub "public (pub)" b
public:
	${1:/*members*/}
endsnippet

snippet priv "private (priv)" b
private:
	${1:/*members*/}
endsnippet

snippet prot "protected (prot)" b
protected:
	${1:/*members*/}
endsnippet

snippet pack "package (pack)" b
package:
	${1:/*members*/}
endsnippet

snippet ret "return (ret)"
return ${1:/*value to return*/};
endsnippet

snippet auto "auto (auto)" b
auto ${1:/*variable*/} = ${2:/*value*/};
endsnippet

snippet con "const (con)" b
const ${1:/*variable*/} = ${2:/*value*/};
endsnippet

snippet siz "size_t (siz)" b
size_t ${1:/*variable*/} = ${2:/*value*/};
endsnippet

snippet sup "super (sup)" b
super(${1:/*args*/});
endsnippet

# Phobos

snippet tup "tuple (tup)"
tuple(${1:/*args*/})
endsnippet

snippet wr "writeln (wr)"
writeln(${1:/*args*/});
endsnippet

snippet to "to (to)"
to!(${1:/*type*/})(${2:/*arg*/})
endsnippet

snippet enf "enforce (enf)" b
enforce(${1:/*condition*/},
	new ${2}Exception(${3:/*args*/}));
endsnippet

# Branches

snippet if "if .. (if)"
if(${1:/*condition*/})
{
	${VISUAL}${0}
}
endsnippet

snippet ife "if .. else (ife)" b
if(${1:/*condition*/})
{
	${2}
}
else
{
	${3:/*else*/}
}
endsnippet

snippet el "else (el)" b
else
{
	${VISUAL}${1}
}
endsnippet

snippet elif "else if (elif)" b
else if(${1:/*condition*/})
{
	${VISUAL}${0}
}
endsnippet

snippet sw "switch (sw)"
switch(${1:/*var*/})
{
	case ${2:/*value*/}:
		${3}
		break;
	case ${4:/*value*/}:
		${5}
		break;
	${7:/*more cases*/}
	default:
		${6:assert(false);}
}
endsnippet

snippet fsw "final switch (fsw)"
final switch(${1:/*var*/})
{
	case ${2:/*value*/}:
		${3}
		break;
	case ${4:/*value*/}:
		${5}
		break;
	${7:/*more cases*/}
}
endsnippet

snippet case "case (case)" b
case ${1:/*value*/}:
	${2}
	break;
endsnippet

snippet ?: "ternary operator (?:)"
${1:/*condition*/} ? ${2:/*then*/} : ${3:/*else*/}$4
endsnippet

# Loops

snippet do "do while (do)" b
do
{
	${VISUAL}${2}
} while(${1:/*condition*/});
endsnippet

snippet wh "while (wh)" b
while(${1:/*condition*/})
{
	${VISUAL}${2}
}
endsnippet

snippet for "for (for)" b
for (${4:size_t} ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
	${VISUAL}${0}
}
endsnippet

snippet forever "forever (forever)" b
for(;;)
{
	${VISUAL}${0}
}
endsnippet

snippet fore "foreach (fore)"
foreach(${1:/*elem*/}; ${2:/*range*/})
{
	${VISUAL}${3}
}
endsnippet

snippet forif "foreach if (forif)" b
foreach(${1:/*elem*/}; ${2:/*range*/}) if(${3:/*condition*/})
{
	${VISUAL}${4}
}
endsnippet

# Contracts
snippet in "in contract (in)" b
in
{
	assert(${1:/*condition*/}, "${2:error message}");
	${3}
}
body
endsnippet

snippet out "out contract (out)" b
out${1:(result)}
{
	assert(${2:/*condition*/}, "${3:error message}");
	${4}
}
body
endsnippet

snippet inv "invariant (inv)" b
invariant()
{
	assert(${1:/*condition*/}, "${2:error message}");
	${3}
}
endsnippet

# Functions (generic)

snippet fun "function definition (fun)"
${1:void} ${2:/*function name*/}(${3:/*args*/}) ${4:@safe pure nothrow}
{
	${VISUAL}${5}
}
endsnippet

snippet void "void function definition (void)"
void ${1:/*function name*/}(${2:/*args*/}) ${3:@safe pure nothrow}
{
	${VISUAL}${4}
}
endsnippet

snippet this "ctor (this)" w
this(${1:/*args*/})
{
	${VISUAL}${2}
}
endsnippet

snippet get "getter property (get)"
@property ${1:/*type*/} ${2:/*member_name*/}() const pure nothrow {return ${3:$2_};}
endsnippet

snippet set "setter property (set)"
@property void ${1:/*member_name*/}(${2:/*type*/} rhs) pure nothrow {${3:$1_} = rhs;}
endsnippet

# Functions (concrete)

snippet main "Main" b
void main(string[] args)
{
	${VISUAL}${0: /*code*/}
}
endsnippet

# Mixins

snippet signal "signal (signal)" b
mixin Signal!(${1:/*args*/}) ${2:/*name*/};
endsnippet

# Scope

snippet scope "scope (scope)" b
scope(${1:exit})
{
	${VISUAL}${2}
}
endsnippet

# With

snippet with "with (with)"
with(${1})
{
	${VISUAL}${2}
}
endsnippet

# Exception handling

snippet try "try/catch (try)" b
try
{
	${VISUAL}${1:/*code to try*/}
}
catch(${2}Exception e)
{
	${3:/*handle exception*/}
}
endsnippet

snippet tryf "try/catch/finally (tryf)" b
try
{
	${VISUAL}${1:/*code to try*/}
}
catch(${2}Exception e)
{
	${3:/*handle exception*/}
}
finally
{
	${4:/*cleanup*/}
}
endsnippet

snippet catch "catch (catch)" b
catch(${1}Exception e)
{
	${2:/*handle exception*/}
}
endsnippet

snippet thr "throw (thr)"
throw new ${1}Exception("${2}");
endsnippet


# Type declarations

snippet struct "struct (struct)"
struct ${1:`!p snip.rv = (snip.basename or "name")`}
{
	${2}
}
endsnippet

snippet union "union (union)"
union ${1:`!p snip.rv = (snip.basename or "name")`}
{
	${2}
}
endsnippet

snippet class "class (class)"
class ${1:`!p snip.rv = (snip.basename or "name")`}
{
	${2}
}
endsnippet

snippet inter "interface (inter)"
interface ${1:`!p snip.rv = (snip.basename or "name")`}
{
	${2}
}
endsnippet

snippet enum "enum (enum)"
enum ${1:`!p snip.rv = (snip.basename or "name")`}
{
	${2}
}
endsnippet


# Exception declarations

snippet exc "exception declaration (exc)" b
/// ${3:/*documentation*/}
class ${1}Exception : ${2}Exception
{
	public this(string msg, string file = __FILE__, int line = __LINE__)
	{
		super(msg, file, line);
	}
}
endsnippet


# Conditional compilation

snippet version "version (version)" b
version(${1:/*version name*/})
{
	${VISUAL}${2}
}
endsnippet

snippet debug "debug" b
debug
{
	${VISUAL}${1}
}
endsnippet


# Templates

snippet temp "template (temp)" b
template ${2:/*name*/}(${1:/*args*/})
{
	${3}
}
endsnippet


# Asserts

snippet ass "assert (ass)" b
assert(${1:false}, "${2:TODO}");

endsnippet


# Unittests

snippet unittest "unittest (unittest)" b
unittest
{
	${1}
}
endsnippet


# Common member functions

snippet opDis "opDispatch (opDis)" b
${1:/*return type*/} opDispatch(string s)()
{
	${2};
}
endsnippet

snippet op= "opAssign (op=)" b
void opAssign(${1} rhs) ${2:@safe pure nothrow}
{
	${2}
}
endsnippet

snippet opCmp "opCmp (opCmp)" b
int opCmp(${1} rhs) @safe const pure nothrow
{
	${2}
}
endsnippet

snippet opApply "opApply (opApply)" b
int opApply(int delegate(ref ${1:/*iterated type/s*/}) dg)
{
	int result = 0;
	${2:/*loop*/}
	{
		result = dg(${3:/*arg/s*/});
		if(result){break;}
	}
	return result;
}
endsnippet

snippet toString "toString (toString)" b
string toString() @safe const pure nothrow
{
	${1}
}
endsnippet


# Comments


snippet todo "TODO (todo)"
// TODO: ${1}
endsnippet


# DDoc

snippet doc "generic ddoc block (doc)" b
/// ${1:description}
///
/// ${2:details}
endsnippet

snippet fdoc "function ddoc block (fdoc)" b
/// ${1:description}
///
/// ${2:Params:  ${3:param} = ${4:param description}
///			 ${5}}
///
/// ${6:Returns: ${7:return value}}
///
/// ${8:Throws:  ${9}Exception ${10}}
endsnippet

snippet Par "Params (Par)"
Params:  ${1:param} = ${2:param description}
///			${3}
endsnippet

snippet Ret "Returns (Ret)"
Returns:  ${1:return value/s}
endsnippet

snippet Thr "Throws (Thr)"
Throws:  ${1}Exception ${2}
endsnippet

snippet Example "Examples (Example)"
Examples:
/// --------------------
/// ${1:example code}
/// --------------------
endsnippet


# License blocks

snippet gpl "GPL (gpl)" b
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Copyright (C) ${1:Author}, `!v strftime("%Y")`

${2}
endsnippet

snippet boost "Boost (boost)" b
//          Copyright ${1:Author} `!v strftime("%Y")`.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

${2}
endsnippet


# New module

snippet module "New module (module)" b
//          Copyright ${1:Author} `!v strftime("%Y")`.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

module ${2}.`!v vim_snippets#Filename('$1', 'name')`;


${3}
endsnippet