@@ -72,6 +72,8 @@ endsnippet
72
72
snippet df " defer someFunction()"
73
73
defer ${1: func } (${2} )
74
74
${0}
75
+ endsnippet
76
+
75
77
snippet def " defer func() { ... }"
76
78
defer func() {
77
79
${0}
@@ -90,22 +92,21 @@ endsnippet
90
92
# gpl
91
93
snippet gpl
92
94
/*
93
- * This program is free software; you can redistribute it and/or modify
94
- * it under the terms of the GNU General Public License as published by
95
- * the Free Software Foundation; either version 2 of the License, or
96
- * (at your option) any later version.
97
- *
98
- * This program is distributed in the hope that it will be useful,
99
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
100
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101
- * GNU General Public License for more details.
102
- *
103
- * You should have received a copy of the GNU General Public License
104
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
105
- *
106
- * Copyright (C) ${1: Author } , `strftime (" %Y" ) `
107
- */
108
-
95
+ * This program is free software; you can redistribute it and/or modify
96
+ * it under the terms of the GNU General Public License as published by
97
+ * the Free Software Foundation; either version 2 of the License, or
98
+ * (at your option) any later version.
99
+ *
100
+ * This program is distributed in the hope that it will be useful,
101
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
102
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103
+ * GNU General Public License for more details.
104
+ *
105
+ * You should have received a copy of the GNU General Public License
106
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
107
+ *
108
+ * Copyright (C) ${1: Author } , `strftime (" %Y" ) `
109
+ */
109
110
${0}
110
111
endsnippet
111
112
@@ -131,23 +132,27 @@ if ${1:condition} {
131
132
endsnippet
132
133
133
134
# else snippet
134
- abbr else { ... }
135
135
snippet else
136
136
else {
137
137
${0}
138
138
}
139
139
endsnippet
140
140
141
141
# error snippet
142
- snippet er " if err != nil { ... } "
142
+ snippet errn " Error return " !b
143
143
if err != nil {
144
- ${0}
144
+ return err
145
145
}
146
- snippet errn "if err != nil { return [...], err }"
147
- if ${1: err } != nil {
148
- return ${2}$1
146
+ ${0}
147
+ endsnippet
148
+
149
+ snippet errn, " Error return with two return values" !b
150
+ if err != nil {
151
+ return ${1: nil } , err
149
152
}
150
153
${0}
154
+ endsnippet
155
+
151
156
snippet json " \`json:key\`"
152
157
\` json:"${1: keyName } "\`
153
158
endsnippet
@@ -178,31 +183,6 @@ for ${2:k}, ${3:v} := range ${1} {
178
183
}
179
184
endsnippet
180
185
181
- global !p
182
-
183
- import re
184
-
185
- # Automatically wrap return types with parentheses
186
-
187
- def return_values (s ):
188
- # remove everything wrapped in parentheses
189
- s = re.sub(" \(.*?\)|\([^)]*$" , " " , s)
190
- return len (s.split(" ," ))
191
-
192
- def opening_par (snip , pos ):
193
- if return_values(t[pos]) > 1 and not t[pos].startswith(" (" ):
194
- snip.rv = " ("
195
- else :
196
- snip.rv = " "
197
-
198
- def closing_par (snip , pos ):
199
- if return_values(t[pos]) > 1 :
200
- snip.rv = " )"
201
- else :
202
- snip.rv = " "
203
-
204
- endglobal
205
-
206
186
# function
207
187
snippet func " func Function(...) [error] { ... }"
208
188
func ${1: name } (${2: params } )${3 / (. + ) / / }`!p opening_par(snip, 3 ) ` $3 `!p closing_par(snip, 3 ) ` {
@@ -250,8 +230,7 @@ func main() {
250
230
endsnippet
251
231
252
232
# method
253
- snippet method " func (self Type) Method(...) [error] { ... }"
254
- regexp /^meth/
233
+ snippet meth " func (self Type) Method(...) [error] { ... }"
255
234
func (${1: receiver } ${2: type } ) ${3: name } (${4: params } )${5 / (. + ) / / }`!p opening_par(snip, 5 ) ` $5 `!p closing_par(snip, 5 ) ` {
256
235
${0: ${VISUAL} }
257
236
}
@@ -260,7 +239,7 @@ endsnippet
260
239
# ok
261
240
snippet ok " if !ok { ... }"
262
241
if !ok {
263
- ${0}
242
+ ${0}
264
243
}
265
244
endsnippet
266
245
@@ -272,16 +251,12 @@ ${0}
272
251
endsnippet
273
252
274
253
# panic
275
- snippet panic
276
- alias pn
277
- abbr panic("...")
278
- panic("${0}")
254
+ snippet pn " panic()"
255
+ panic("${0: msg } ")
279
256
endsnippet
280
257
281
258
# return
282
- snippet return
283
- alias rt
284
- abbr return ...
259
+ snippet rt " return"
285
260
return ${0}
286
261
endsnippet
287
262
@@ -294,7 +269,7 @@ case ${1:v1} := <-${2:chan1}
294
269
endsnippet
295
270
296
271
# struct
297
- snippet struct " type T struct { ... }"
272
+ snippet st " type T struct { ... }"
298
273
type ${1: Type } struct {
299
274
${0}
300
275
}
@@ -319,10 +294,10 @@ go ${1:funcName}(${0})
319
294
endsnippet
320
295
321
296
# goroutine anonymous function
322
- snippet gof " go func(... ) { ... }(... )"
323
- go func(${1} ) {
324
- ${3 : /* TODO */ }
325
- }(${2} )
297
+ snippet gof " go func() { ... }()"
298
+ go func() {
299
+ ${1 }
300
+ }()
326
301
endsnippet
327
302
328
303
# test function
@@ -344,4 +319,31 @@ ${1:x} ${2:Type}${3: = ${0:value\}}
344
319
)
345
320
endsnippet
346
321
322
+ global !p
323
+
324
+ import re
325
+
326
+ # Automatically wrap return types with parentheses
327
+
328
+ def return_values(s):
329
+ # remove everything wrapped in parentheses
330
+ s = re.sub("\( .*?\) |\( [^)]*$", "", s)
331
+ return len(s.split(","))
332
+
333
+ def opening_par(snip, pos):
334
+ if return_values(t[pos]) > 1 and not t[pos].startswith("("):
335
+ snip.rv = "("
336
+ else:
337
+ snip.rv = ""
338
+
339
+ def closing_par(snip, pos):
340
+ if return_values(t[pos]) > 1:
341
+ snip.rv = ")"
342
+ else:
343
+ snip.rv = ""
344
+
345
+ endglobal
346
+
347
+
347
348
# vim:ft=snippets:
349
+
0 commit comments