From b086b2d467f670b6ecb9c22698afcaad25ec1f35 Mon Sep 17 00:00:00 2001 From: afolmert Date: Wed, 22 Jun 2011 09:44:04 +0200 Subject: [PATCH 1/2] Added Go snippets --- AUTHORS | 1 + snippets/go.snippets | 188 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 snippets/go.snippets diff --git a/AUTHORS b/AUTHORS index e0333fe..eaeff8a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ +Adam Folmert Alberto Pose Angel Alonso Ben Orenstein diff --git a/snippets/go.snippets b/snippets/go.snippets new file mode 100644 index 0000000..c49faec --- /dev/null +++ b/snippets/go.snippets @@ -0,0 +1,188 @@ +# append +snippet ap + append(${1:slice}, ${2:value}) +# byte +snippet b + byte +# break +snippet br + break +# channel +snippet ch + chan ${1:int} +# const +snippet cs + const ${1:NAME} = ${2:value} +# constants with iota +snippet cst + const ( + ${1:NAME1} = iota + ${2:NAME2} + ) +# continue +snippet cn + continue +# defer +snippet df + defer ${1:func}() +# defer recover +snippet dfr + defer func() { + if err := recover(); err != nil { + ${1:/* code */} + } + }() +# gpl +snippet gpl + /* + * 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}, `strftime("%Y")` + */ + + ${2} +# int +snippet i + int +# import +snippet im + import ( + "${1:package}" + ) +# interface +snippet in + interface{} +# full interface snippet +snippet inf + interface ${1:name} { + ${2:/* methods */} + }${3} +# if condition +snippet if + if ${1:/* condition */} { + ${2:/* code */} + } +# else snippet +snippet el + else { + ${1} + } +# error snippet +snippet ir + if err != nil { + return err + } + ${1} +# false +snippet fa + false +# fallthrough +snippet fth + fallthrough +# float +snippet fl + float32 +# if else +snippet ie + if ${1:/* condition */} { + ${2:/* code */} + } else { + ${3} + } +# for loop +snippet fo + for ${2:i} = 0; $2 < ${1:count}; $2${3:++} { + ${4:/* code */} + } +# for range loop +snippet fr + for ${1:k}, ${2:v} := range ${3} { + ${4:/* code */} + } +# function simple +snippet fun + func ${1:funcName}(${2}) ${3:os.Error} { + ${4:/* code */} + } +# function on receiver +snippet fum + func (self ${1:type}) ${2:funcName}(${3}) ${4:os.Error} { + ${5:/* code */} + } +# make +snippet mk + make(${1:[]string}, ${2:0}) +# map +snippet mp + map[${1:string}]${2:int} +# main() +snippet main + func main() { + ${1:/* code */} + } +# new +snippet nw + new(${1:type}) +# panic +snippet pn + panic("${1:msg}") +# print +snippet pr + fmt.Printf("${1:%s}\n", ${2:var})${3} +# range +snippet rn + range ${1} +# return +snippet rt + return ${1} +# result +snippet rs + result +# select +snippet sel + select { + case ${1:v1} := <-${2:chan1} + ${3:/* code */} + case ${4:v2} := <-${5:chan2} + ${6:/* code */} + default: + ${7:/* code */} + } +# string +snippet sr + string +# struct +snippet st + struct ${1:name} { + ${2:/* data */} + }${4} +# switch +snippet sw + switch ${1:var} { + case ${2:value1}: + ${3:/* code */} + case ${4:value2}: + ${5:/* code */} + default: + ${6:/* code */} + } +snippet sp + fmt.Sprintf("${1:%s}", ${2:var})${3} +# true +snippet tr + true +# variable declaration +snippet v + var ${1:t} ${2:string} From efec3786f7be2ed75a116b77e7f384746bba75d3 Mon Sep 17 00:00:00 2001 From: afolmert Date: Fri, 24 Jun 2011 10:09:28 +0200 Subject: [PATCH 2/2] Tweaked Go snippets --- snippets/go.snippets | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/snippets/go.snippets b/snippets/go.snippets index c49faec..0e4fe61 100644 --- a/snippets/go.snippets +++ b/snippets/go.snippets @@ -1,8 +1,11 @@ # append snippet ap append(${1:slice}, ${2:value}) +# bool +snippet bl + bool # byte -snippet b +snippet bt byte # break snippet br @@ -10,11 +13,15 @@ snippet br # channel snippet ch chan ${1:int} -# const +# case snippet cs - const ${1:NAME} = ${2:value} + case ${1:value}: + ${2:/* code */} +# const +snippet c + const ${1:NAME} = ${2:0} # constants with iota -snippet cst +snippet co const ( ${1:NAME1} = iota ${2:NAME2} @@ -86,14 +93,20 @@ snippet ir } ${1} # false -snippet fa +snippet f false # fallthrough -snippet fth +snippet ft fallthrough # float snippet fl float32 +# float32 +snippet f3 + float32 +# float64 +snippet f6 + float64 # if else snippet ie if ${1:/* condition */} { @@ -151,7 +164,7 @@ snippet rt snippet rs result # select -snippet sel +snippet sl select { case ${1:v1} := <-${2:chan1} ${3:/* code */} @@ -181,7 +194,7 @@ snippet sw snippet sp fmt.Sprintf("${1:%s}", ${2:var})${3} # true -snippet tr +snippet t true # variable declaration snippet v