The packages that need to be downloaded before configuration:
- Godoc
- Godef
- Gocode
- Oracle
The environment variables need to be set before downloading the package:
# golangexport Goroot= $HOME/goexport gopath= $HOME/development/goexport PATH= $PATH: $ goroot/binexport PATH= $PATH: $GOPATH/bin
If the network is good, use this method:
Godoc:
Go get Golang.org/x/tools/cmd/godoc
This installs the Godoc binary into the $GOROOT/bin directory.
Godef:
This installs the Godef binary into the $GOPATH/bin directory.
Gocode Auto-Complete:
Go get-u github.com/nsf/gocode
This installs the Gocode binary into the $GOPATH/bin directory.
Go Oracle
Go get golang.org/x/tools/cmd/oracle
The Oracle binaries will appear in the $GOPATH/bin directory and will be moved to the $GOROOT/bin directory.
Here is the Golang configuration for Emacs:
;;; Init-go---Golang;;; Commentary:;; http://tleyden.github.io/blog/2014/05/22/configure-emacs-as-a-go-editor-from-scratch/;; Https//robinxiong.gitbooks.io/golang/content/section1/emacs.html;; http//studygolang.com/topics/583;;; Code: (Require-package'Go-mode)(Require-package'company-go)(Require'Go-mode);; Removes all unused imports (add-hook'Go-mode-hook'(Lambda () (Local-set-key (KBD"c-c c-r")'go-remove-unused-imports )));; Format the current buffer (add-hook'Go-mode-hook'(Lambda () (Local-set-key (KBD"c-c c-f")'gofmt )));; Format the buffer when save (add-hook'Before-save-hook'gofmt-before-save);; Show the Go Documentation fora given package;; Note:godoc depends on the Godoc utility.; It must is installed and on your $PATH.; toInstallIt Run:go get code.google.com/p/go.tools/cmd/Godoc. (Add-hook'Go-mode-hook'(Lambda () (Local-set-key (KBD"c-c c-k")'godoc )));; Gocode autocomplete;;( Add-hook'Go-mode-hook'company-mode) (Add-hook'Go-mode-hook'(Lambda () (Set ( Make-local-variable'company-backends)'(company-go)) ( Company-mode)); Go Oracle;; Note: $GOPATH'll defined In init-exec-path-from- Shell(load-file "$GOPATH/src/golang.org/x/tools/cmd/oracle/oracle.el") (Add-hook'Go-mode-hook'go-oracle-mode) (Provide'init-go);;; Init-go.el ends here
;;; Init-exec-path-from-shell---exec path form shell;;; Commentary:;; Let Emacs use. BASHRCfile, especially system $PATH.;;; Code: (Require-package'Exec-path-from-shell)(When (memq window-system'(Mac ns x))(exec-path-from-shell-initialize));;; forGolang(exec -path-from-shell-copy-env "Gopath" )(Provide'Init-exec-path-from-shell);;; Init-exec-path-from-shell.el ends here
Another way:
Note: The golang.org cloned from GitHub should be placed in the SRC directory!
~/DEVELOPMENT/GO/SRC git clone https://github.com/golang/tools golang.org/x/tools' golang.org/x/tools'15398done. In receive object: 8 % (1232/15398404.0169.00 kib/s
Compile Godoc:
Go Build Golang.org/x/tools/cmd/godoc
Note: The compiled Godoc binaries should be placed in the ~/development/go/bin directory!
Install the Golang tutorial (this is the English version):
git clone https://github.com/golang/tour
Go build golang.org/x/tour/gotourgolang.org/x/tools/playground/socket/socket.go:notoginseng:2 Find " Golang.org/x/net/websocket " inch Any of : /home/z/go/src/golang.org/x/net/WebSocket (from $GOROOT) /home/z/development/go/src/golang.org/x /net/websocket (from $GOPATH)
What to do?
? git clone https://github.com/golang/net
Note: The 2 directories and tools directories for Gotour and net are peers, both in the $gopath/src/golang.org/x directory.
X
├──net
├──tools
└──tour
? Go Build Golang.org/x/tour/gotour
To install the Chinese version of the tutorial:
git clone https://github.com/go-zh/tour github.com/go-zh/tourgit clone https:// Github.com/go-zh/tools Github.com/go-zh/tools
Note Tour and tools are sibling directories.
Github.com/go-zh
├──tools
└──tour
Compiling the Chinese version of the tutorial:
A gotour binary file appears in the $GOPATH/SRC directory, which is clipped to the $gopath/bin directory and renamed to Gotour-zh.
Execute in $gopath/bin:./gotour-zh to open the browser.
Install Godef:
git clone https://github.com/rogpeppe/godef github.com/rogpeppe/godef
Go Build github.com/rogpeppe/godef
Github.com/rogpeppe/godef/acme.go:11:2: Cannot find package "9FANS.NET/GO/ACME" in any of:
/HOME/Z/GO/SRC/9FANS.NET/GO/ACME (from $GOROOT)
/HOME/Z/DEVELOPMENT/GO/SRC/9FANS.NET/GO/ACME (from $GOPATH)
Workaround:
git clone https://
Then compile and install Godef:
Go Build github.com/rogpeppe/godef
Reference:
http://studygolang.com/topics/583
http://tleyden.github.io/blog/2014/05/22/configure-emacs-as-a-go-editor-from-scratch/https:// Robinxiong.gitbooks.io/golang/content/section1/emacs.html
--end--
Emacs Golang Configuration