Skip to content

Commit caa0e0e

Browse files
committed
Some snippets for C11 and reordering
Reordering some of the snipppets for c. Created new snippets for the C11-standard operators _Static_assert and _Genecic. Added fori, fwrite and fread and other simple snippets.
1 parent ad0c0e6 commit caa0e0e

File tree

1 file changed

+125
-43
lines changed

1 file changed

+125
-43
lines changed

neosnippets/c.snip

Lines changed: 125 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
# Control structures {{{
12
snippet if
23
options head
34
abbr if () {}
45
if (${1:#:condition}) {
56
${0:TARGET}
67
}
78

8-
snippet else
9+
snippet else
910
options head
1011
else {
1112
${0:TARGET}
1213
}
1314

14-
snippet elseif
15+
snippet elseif
1516
options head
1617
else if (${1:#:condition}) {
1718
${0:TARGET}
@@ -33,6 +34,20 @@ abbr for () {}
3334
${0:#:TARGET}
3435
}
3536

37+
# Counter based for's (don't ask for the type or count start)
38+
snippet fori
39+
options head
40+
abbr for(int x;...){}
41+
for (int ${1:i} = 0; $1 < ${2}; $1++) {
42+
${0:#:TARGET}
43+
}
44+
45+
# For reverse counter
46+
snippet forri
47+
for (int ${1:i} = ${2}; $1 > 0; $1--) {
48+
${0:#:TARGET}
49+
}
50+
3651
snippet while
3752
options head
3853
abbr while () {}
@@ -56,11 +71,25 @@ abbr switch () {}
5671
break;
5772
}
5873

74+
snippet case
75+
options head
76+
abbr case: break;
77+
case ${1}:
78+
${0}
79+
break;
80+
81+
# Ternary conditional operator
82+
snippet conditional
83+
(${1:#:condition}) ? ${2:#:a} : ${3:#:b}
84+
85+
# }}}
86+
87+
# Definition bodies {{{
5988
snippet function
6089
options head
6190
alias func
6291
abbr func() {}
63-
${1:void} ${2:#:func_name}(${3:#:args}) {
92+
${1:void} ${2:#:func_name}(${3:#:void}) {
6493
${0:TARGET}
6594
}
6695

@@ -72,7 +101,7 @@ abbr struct {}
72101
};
73102

74103
# Typedef struct
75-
snippet struct_typedef
104+
snippet struct_typedef
76105
options head
77106
typedef struct ${1:#:name} {
78107
${0:TARGET:data}
@@ -86,55 +115,72 @@ abbr enum {}
86115
};
87116

88117
# hard-tab is necessary; C indent doesn't support this.
89-
snippet main
118+
snippet main
90119
options head
91120
int main(int argc, char const* argv[])
92121
{
93122
${0:TARGET}
94123
return 0;
95124
}
96125

126+
snippet helloworld
127+
options head
128+
#include <stdio.h>
129+
int main(int argc, char const* argv[])
130+
{
131+
puts("hello, world!");
132+
return 0;
133+
}
134+
135+
# }}}
136+
137+
# Preprocessing directives {{{
97138
# #include <...>
98-
snippet inc
139+
snippet inc
99140
options head
100-
alias #inc, #include
141+
alias #inc, #include
101142
#include <${1:stdio}.h>${0}
143+
102144
# #include "..."
103-
snippet inc2
145+
snippet inc2
104146
options head
105-
alias #inc2, #include2
147+
alias #inc2, #include2
106148
#include "${1}.h"${0}
107149

108-
snippet ifndef
150+
snippet ifdef
109151
options head
110-
alias #ifndef
152+
alias #ifdef
153+
abbr #ifdef ... #endif
154+
#ifdef $1
155+
${0}
156+
#endif
157+
158+
snippet ifndef
159+
options head
160+
alias #ifndef
111161
abbr #ifndef ... #define ... #endif
112162
#ifndef $1
113163
#define ${1:#:SYMBOL}
114164
#endif${0}
115165

116-
snippet def
166+
snippet def
117167
options head
118-
alias #def, #define
119-
#define
168+
alias #def, #define
169+
#define
120170

121171
# Include-Guard
122-
snippet once
172+
snippet once
123173
options head
124-
abbr include-guard
174+
abbr include-guard
125175
#ifndef ${1:SYMBOL}
126176
#define $1
127177

128178
${0:TARGET}
129179
#endif /* end of include guard */
130180

131-
# Ternary conditional operator
132-
snippet conditional
133-
(${1:#:condition}) ? ${2:#:a} : ${3:#:b}
134-
135-
snippet typedef
136-
typedef ${1:#:base_type} ${2:#:custom_type};
181+
# }}}
137182

183+
# Built-in function calls {{{
138184
snippet printf
139185
abbr printf("...\n", ...);
140186
printf("${1}\n", ${2});
@@ -143,33 +189,65 @@ snippet fprintf
143189
abbr fprintf(..., "...\n", ...);
144190
fprintf(${1:stderr}, "${2}\n"${3});
145191

146-
snippet comment
147-
alias /*
148-
/* ${1:#:comment} */
149-
${0}
192+
snippet fopen
193+
abbr fopen("...", "...");
194+
fopen("${1:PATH}", "${2:MODE}");
195+
${0:TARGET}
196+
fclose(${3:FD});
197+
198+
snippet fgets
199+
abbr fgets(row, length, file);
200+
fgets(${0:ROW}, ${1:LENGTH}, ${2:FILE});
201+
202+
snippet fscanf
203+
abbr fscanf(file, "...", ...);
204+
fscanf(${1:FILE}, "${2}", ${3});
205+
206+
snippet fwrite
207+
abbr fwrite(......, file)
208+
fwrite(${1:ARRAY}, sizeof(${2:TYPE}), ${3:N_MEMBERS}, ${4:FILE})
209+
210+
snippet fread
211+
abbr fread(......, file)
212+
fread(${1:ARRAY}, sizeof(${2:TYPE}), ${3:N_MEMBERS}, ${4:FILE})
213+
214+
snippet memcpy
215+
abbr memcpy(dest, src, nbytes)
216+
mempcy(${1:DEST}, ${2:SRC}, ${3:N_MEMBERS})
217+
218+
# }}}
219+
220+
# Built-in operators and alias {{{
221+
snippet typedef
222+
typedef ${1:#:base_type} ${2:#:custom_type};
150223

151224
snippet sizeof
152-
alias size
225+
alias size
153226
sizeof(${0:TARGET})
154227

155-
snippet helloworld
156-
options head
157-
#include <stdio.h>
158-
int main(int argc, char const* argv[])
159-
{
160-
puts("hello, world!");
161-
return 0;
162-
}
228+
snippet sizeof_array
229+
alias array_size
230+
(sizeof(${1:#:array}) / sizeof(*($1)))
163231

164-
snippet fopen
165-
abbr fopen("...", "...");
166-
fopen("${1:PATH}", "${2:MODE}");
167-
${0:TARGET}
168-
fclose(${3:FD});
232+
snippet _static_assert
233+
options head
234+
_Static_assert(${1:#:condition}, ${2:#:message})
169235

170-
snippet fgets
171-
abbr fgets(row, length, file);
172-
fgets(${0:ROW}, ${1:LENGTH}, ${2:FILE});
236+
snippet static_assert
237+
options head
238+
static_assert(${1:#:condition}, ${2:#:message})
239+
240+
snippet _Generic
241+
alias generic, select
242+
_Generic(${1:#:expression}, ${2:#:association-list})
243+
244+
# }}}
245+
246+
# Comments {{{
247+
snippet comment
248+
alias /*
249+
/* ${1:#:comment} */
250+
${0}
173251

174252
snippet doxy
175253
abbr /** @brief ...
@@ -183,3 +261,7 @@ options head
183261
*
184262
* @return ${4:return type}
185263
*/
264+
265+
# }}}
266+
267+
# vim: fdm=marker

0 commit comments

Comments
 (0)