├── .gitignore ├── README.md └── go-mode ├── append ├── benchmark ├── case ├── constructor ├── error ├── example ├── for ├── forrange ├── func ├── import ├── init ├── interface ├── main ├── package ├── printf ├── struct ├── switch ├── test ├── testmain └── tests /.gitignore: -------------------------------------------------------------------------------- 1 | .yas-compiled-snippets.el 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yasnippet for golang 2 | 3 | This is yasnippet for emacs go-mode. 4 | 5 | YASnippet is here : https://github.com/capitaomorte/yasnippet 6 | 7 | # Installation 8 | 9 | Clone this repository: 10 | 11 | $ git clone https://github.com/atotto/yasnippet-golang.git 12 | 13 | Add the following in your `.emacs` file: 14 | 15 | ```elisp 16 | (add-to-list 'yas-snippet-dirs "path/to/yasnippet-golang") 17 | ``` 18 | 19 | # License 20 | 21 | MIT License 22 | -------------------------------------------------------------------------------- /go-mode/append: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for append 3 | # key: append 4 | # contributor : @atotto 5 | # -- 6 | $1 = append($1, $0) -------------------------------------------------------------------------------- /go-mode/benchmark: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: benchmark 3 | # key: bench 4 | # contributor : @atotto 5 | # -- 6 | func Benchmark$1(b *testing.B) { 7 | for i := 0; i < b.N; i++ { 8 | $0 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /go-mode/case: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for switch case 3 | # key: case 4 | # contributor : @atotto 5 | # -- 6 | case $1: 7 | $0 -------------------------------------------------------------------------------- /go-mode/constructor: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for constructor 3 | # key: new 4 | # contributor : @atotto 5 | # -- 6 | // New$1 returns a new $1. 7 | func New$1() *$1 { 8 | $2 := &$1{$0} 9 | return $2 10 | } 11 | -------------------------------------------------------------------------------- /go-mode/error: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: error 3 | # key: err 4 | # contributor : @atotto 5 | # -- 6 | if err != nil { 7 | $0 8 | } -------------------------------------------------------------------------------- /go-mode/example: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: example 3 | # key: example 4 | # contributor : @atotto 5 | # -- 6 | func Example$1() { 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/for: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for 3 | # key: for 4 | # contributor : @atotto 5 | # -- 6 | for { 7 | $0 8 | } -------------------------------------------------------------------------------- /go-mode/forrange: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for range 3 | # key: range 4 | # contributor : @atotto 5 | # -- 6 | for ${3:key}, ${2:value} := range ${1:target} { 7 | $0 8 | } -------------------------------------------------------------------------------- /go-mode/func: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: func append 3 | # key: func 4 | # contributor : @atotto 5 | # -- 6 | // 7 | func ($2) $1() { 8 | $0 9 | } 10 | -------------------------------------------------------------------------------- /go-mode/import: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: import 3 | # key: import 4 | # contributor : @atotto 5 | # -- 6 | import ( 7 | "$0" 8 | ) 9 | -------------------------------------------------------------------------------- /go-mode/init: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: init 3 | # key: init 4 | # contributor : @atotto 5 | # -- 6 | func init(){ 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/interface: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: interface 3 | # key: type 4 | # contributor : @atotto 5 | # -- 6 | type $1 interface { 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/main: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: func main 3 | # key: main 4 | # contributor : @atotto 5 | # -- 6 | func main() { 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/package: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: package 3 | # key: pack 4 | # contributor : @atotto 5 | # -- 6 | // 7 | package ${1:main} 8 | -------------------------------------------------------------------------------- /go-mode/printf: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: print 3 | # key: printf 4 | # contributor : @atotto 5 | # -- 6 | fmt.Printf("%+v$0\n",$1) -------------------------------------------------------------------------------- /go-mode/struct: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: struct 3 | # key: type 4 | # contributor : @atotto 5 | # -- 6 | type $1 struct { 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/switch: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for switch 3 | # key: switch 4 | # contributor : @atotto 5 | # -- 6 | switch $1 { 7 | case $2: 8 | $0 9 | default: 10 | } -------------------------------------------------------------------------------- /go-mode/test: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: test 3 | # key: test 4 | # contributor : @atotto 5 | # -- 6 | func Test$1(t *testing.T) { 7 | $0 8 | } 9 | -------------------------------------------------------------------------------- /go-mode/testmain: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: testmain 3 | # key: testmain 4 | # contributor : @atotto 5 | # -- 6 | func TestMain(m *testing.M) { 7 | setup() 8 | ret := m.Run() 9 | if ret == 0 { 10 | teardown() 11 | } 12 | os.Exit(ret) 13 | } 14 | 15 | func setup() { 16 | $1 17 | } 18 | 19 | func teardown() { 20 | $2 21 | } -------------------------------------------------------------------------------- /go-mode/tests: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: tests 3 | # key: tests 4 | # contributor : @atotto 5 | # -- 6 | tests := []struct { 7 | expected 8 | }{ 9 | {}, 10 | } 11 | 12 | for n, tt := range tests { 13 | actual := 14 | if tt.expected != actual { 15 | t.Errorf("#%d want %v, got %v", n, tt.expected, actual) 16 | } 17 | } 18 | --------------------------------------------------------------------------------