在配置前需要下载用到的包:

  1. godoc
  2. godef
  3. gocode
  4. oracle

在下载包之前需要设置好环境变量:

# Golang
export GOROOT=$HOME/go
export GOPATH=$HOME/development/go
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin

如果网络良好的话使用这种方法:
godoc:

go get golang.org/x/tools/cmd/godoc

这样会将godoc二进制文件安装到$GOROOT/bin目录里。

godef:

go get github.com/rogpeppe/godef 

这样会将godef二进制文件安装到$GOPATH/bin目录里。

gocode 自动完成:

go get -u github.com/nsf/gocode

这样会将gocode二进制文件安装到$GOPATH/bin目录里。

go oracle

go get golang.org/x/tools/cmd/oracle

oracle二进制文件将出现在$GOPATH/bin目录里,将它移动到$GOROOT/bin目录里。

下面是emacs的golang配置:

;;; 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 for a given package
;; Note: godoc depends on the godoc utility.
;; It must be installed and on your $PATH.
;; To install it 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 will 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 .bashrc file,especially system $PATH.
;;; Code: (require-package 'exec-path-from-shell) (when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)) ;;; for golang
(exec-path-from-shell-copy-env "GOPATH") (provide 'init-exec-path-from-shell)
;;; init-exec-path-from-shell.el ends here

另一种方法:
注意:从github克隆的golang.org应该放在src目录里!

~/development/go/src  ᐅ git clone https://github.com/golang/tools golang.org/x/tools
正克隆到 'golang.org/x/tools'...
remote: Counting objects: , done.
接收对象中: % (/), 404.01 KiB | 69.00 KiB/s

编译godoc:

go build golang.org/x/tools/cmd/godoc

注意:编译出的godoc二进制文件应该放在 ~/development/go/bin目录里!

安装golang教程(这个是英文版的):

git clone https://github.com/golang/tour
go build golang.org/x/tour/gotour
golang.org/x/tools/playground/socket/socket.go::: cannot find package "golang.org/x/net/websocket" in 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)

怎么办?

ᐅ git clone https://github.com/golang/net

注意:gotour和net这2个目录和tools目录是平级的,它们都在$GOPATH/src/golang.org/x 目录下。
x
├── net
├── tools
└── tour
ᐅ go build golang.org/x/tour/gotour

安装中文版的教程:

git clone https://github.com/Go-zh/tour github.com/Go-zh/tour
git clone https://github.com/Go-zh/tools github.com/Go-zh/tools

注意tour和tools是同级目录。

github.com/Go-zh
├── tools
└── tour

编译中文版教程:

go build github.com/Go-zh/tour/gotour 

这时会在$GOPATH/src目录中出现一个gotour二进制文件,把它剪切到$GOPATH/bin目录中并重命名为gotour-zh。
在$GOPATH/bin中执行:./gotour-zh 即可开启浏览器。

安装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)

解决方法:

git clone https://github.com/9fans/go 9fans.net/go 

然后再编译安装godef:

go build github.com/rogpeppe/godef

参考:

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 配置的更多相关文章

  1. [daily][emacs][go] 配置emacs go-mode的编辑环境以及环境变量问题

    1. 安装go 安装go-mode 使用emacs编辑go代码的时候,你需要有正常可运行的go环境. 并且有emacs的go-mode package https://www.emacswiki.or ...

  2. Emacs 安装配置使用教程

    Emacs 安装配置使用教程 来源 https://www.jianshu.com/u/a27b97f900f7 序|Preface 先来一篇有趣的简介:Emacs和Vim:神的编辑器和编辑器之神 - ...

  3. Viper--方便好用的Golang 配置库

    前言 本文主要是为读者介绍一个轻便好用的Golang配置库viper 正文 viper 的功能   viper 支持以下功能:   1. 支持Yaml.Json. TOML.HCL 等格式的配置   ...

  4. ubuntu14.04 下emacs 24 配置

    目的: 配置emacs 24 适合编程开发 主要参考JerryZhang的配置(Emacs 简易教程) http://www.perfect-is-shit.com/emacs-simple-tuto ...

  5. CentOS编译安装emacs并配置

    Liunxs中CentOS系列一向以稳定为目标,然而也会存在版本太旧的问题,emacs就是其中的一个,目前emacs都发行到25.2了,而CentOS上的emacs版本却还是23.1.所以需要下载源代 ...

  6. Emacs编辑器配置

    以前总是用的vim编辑器,今天突然想换emacs 用下.折腾了很久终于搞定.使用的是windows测试环境 emacs下载地址http://ftp.gnu.org/gnu/emacs/windows/ ...

  7. Emacs考场配置

    当年\(NOip\)考场配置不记得啦 存在这里搞事情 (set-background-color "gray15") (set-foreground-color "gra ...

  8. 我的emacs考场配置

    豪华配置(复制的神犇的,已膜改) (global-set-key [f9] 'compile-file) (global-set-key [f10] 'gud-gdb) (global-set-key ...

  9. visual code golang配置

    前言 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org), 导致一些包无法安装,最终会导致环境搭建失败,跟据这个教程几步,我们将可以快速的构建golang ...

随机推荐

  1. 原生JS修改标签样式为带阴影效果

    代码如下: JS部分 //点击时候,改变样式 function GetCategoryInfo(value) { var getInfo = value.toString().split(','); ...

  2. VM VirtualBox 上安装 CentOs6.4(详细)

    在网上下载:CentOS-6.4-i386-bin-DVD1.iso镜像. 这是我在VBox上安装CentOs6.4的过程: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12 ...

  3. 转载:Flash AS3.0 加载外部资源(图片,MP3,SWF)的两种方式

    Flash AS3.0 加载外部资源(图片,MP3,SWF)的两种方式 出自:http://www.cnblogs.com/top5/archive/2012/08/04/2623464.html 关 ...

  4. js 中使用工厂方法和构造器方法

    1 直接创建对象 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...

  5. spring 切面 前置后置通知 环绕通知demo

    环绕通知: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  6. 开发过程中常用的Linux命令

    做Java开发好几年了,部署JavaWeb到服务器上,一般都选择Linux,Linux作为服务器真是不二之选,高性能,只要熟悉Linux,操作快捷,效率很高. 总结一下工作中常用的Linux命令备忘: ...

  7. IOS学习经验总结--来自知乎网友

    转自知乎:http://www.zhihu.com/question/20016551 我当时刚学iOS开发的时候一样的感觉 总想知道原理 内部怎么回事 感觉在像在雾里但是iOS开发就是这样 他是封闭 ...

  8. 将Excel另存为CSV格式文件

    直接将Excel另存为CSV,速度很快: $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand ...

  9. SAP Connector 3.0 .Net 开发

    在VS2010中使用控制台应用程序使用SAP Connector 3.0开发时,当程序运行到实例化RfcConfigParameters时报错 (RfcConfigParametersrefcon = ...

  10. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...