From b632e02b9e05fef8ce69088a904884116a44aac0 Mon Sep 17 00:00:00 2001 From: CongNT3 Date: Mon, 12 Jan 2015 11:22:23 +0700 Subject: [PATCH] Add go-eldoc, go-autocomplete and go-oracle --- contrib/lang/go/README.md | 23 +++++++++++++++++- contrib/lang/go/extensions.el | 45 +++++++++++++++++++++++++++++++++++ contrib/lang/go/packages.el | 5 ++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 contrib/lang/go/extensions.el diff --git a/contrib/lang/go/README.md b/contrib/lang/go/README.md index 76330d5ac..3a5ce52cf 100644 --- a/contrib/lang/go/README.md +++ b/contrib/lang/go/README.md @@ -19,6 +19,8 @@ This layers adds extensive support for go. Features: - gofmt on file save +- Auto-completion using [go-autocomplete](https://github.com/nsf/gocode/tree/master/emacs) +- Source analysis using [go-oracle](http://golang.org/s/oracle-user-manual) ## Install @@ -34,7 +36,7 @@ To use this contribution add it to your `~/.spacemacs` ## Working with Go -Go commands (start with `m`): +### Go commands (start with `m`): Key Binding | Description ---------------------------|------------------------------------------------------------ @@ -45,3 +47,22 @@ Go commands (start with `m`): SPC m p b | go-play buffer SPC m p r | go-play region SPC m p d | download go-play snippet +SPC m g | go jump to definition + + +### Go Oracle + + Key Binding | Description +---------------------------|------------------------------------------------------------ +SPC m o o | go-oracle set analysis scope +SPC m o < | go-oracle show possible callers +SPC m o > | go-oracle show call targets +SPC m o c | go-oracle show channel sends/receives +SPC m o d | go-oracle show definition +SPC m o f | go-oracle show free variables +SPC m o g | go-oracle show callgraph +SPC m o i | go-oracle show implements relation +SPC m o p | go-oracle show what the select expression points to +SPC m o r | go-oracle show all references to object +SPC m o s | go-oracle show callstack +SPC m o t | go-oracle describe selected syntax, kind, type and methods diff --git a/contrib/lang/go/extensions.el b/contrib/lang/go/extensions.el new file mode 100644 index 000000000..e3a0ef502 --- /dev/null +++ b/contrib/lang/go/extensions.el @@ -0,0 +1,45 @@ +(defvar go-pre-extensions + '( + ;; pre extension gos go here + ) + "List of all extensions to load before the packages.") + +(defvar go-post-extensions + '( + ;; post extension gos go here + go-autocomplete + go-oracle + ) + "List of all extensions to load after the packages.") + +;; For each extension, define a function go/init- +;; +;; (defun go/init-my-extension () +;; "Initialize my extension" +;; ) +;; +;; Often the body of an initialize function uses `use-package' +;; For more info on `use-package', see readme: +;; https://github.com/jwiegley/use-package +(defun go/init-go-autocomplete() + (load-file "$GOPATH/src/github.com/nsf/gocode/emacs/go-autocomplete.el") +) + +(defun go/init-go-oracle() + (load-file "$GOPATH/src/code.google.com/p/go.tools/cmd/oracle/oracle.el") + (add-hook 'go-mode-hook 'go-oracle-mode) + (spacemacs|diminish go-oracle-mode " O") + (evil-leader/set-key-for-mode 'go-mode + "moo" 'go-oracle-set-scope + "mo<" 'go-oracle-callers + "mo>" 'go-oracle-callees + "moc" 'go-oracle-peers + "mod" 'go-oracle-definition + "mof" 'go-oracle-freevars + "mog" 'go-oracle-callgraph + "moi" 'go-oracle-implements + "mop" 'go-oracle-pointsto + "mor" 'go-oracle-referrers + "mos" 'go-oracle-callstack + "mot" 'go-oracle-describe + )) diff --git a/contrib/lang/go/packages.el b/contrib/lang/go/packages.el index 42fdfe9ec..87641d953 100644 --- a/contrib/lang/go/packages.el +++ b/contrib/lang/go/packages.el @@ -2,6 +2,7 @@ '( flycheck go-mode + go-eldoc ) "List of all packages to install and/or initialize. Built-in packages which require an initialization must be listed explicitly in the list.") @@ -22,7 +23,11 @@ which require an initialization must be listed explicitly in the list.") "mpb" 'go-play-buffer "mpr" 'go-play-region "mpd" 'go-download-play + "mg" 'godef-jump )) :config (add-hook 'before-save-hook 'gofmt-before-save) )) + +(defun go/init-go-eldoc() + (add-hook 'go-mode-hook 'go-eldoc-setup))