Saturday, June 2, 2012

Setup emacs + gocode for golang editing with auto completion


from Go Source repository http://code.google.com/p/go/source/browse/misc/emacs/
download go-mode-load.el and go-mode.el, put both file into ~/.emacs.d

edit ~/.emacs to add
(add-to-list 'load-path "~/.emacs.d" t)
(require 'go-mode-load)

Go to ~/.emacs.d to compile go-mode.el
$emacs -batch -f batch-byte-compile go-mode.el

Install Autocomplete for emacs from http://cx4a.org/software/auto-complete/
Follow the user manual for instllation.

Copy emacs/go-autocomplete.el file from the gocode source distribution to ~/.emacs.d

edit ~/.emacs to add
(require 'go-autocomplete)
(require 'auto-complete-config)

Install gocode
$go get github.com/nsf/gocode
$go install github.com/nsf/gocode

All instllation is done. To test of gocode auto completion
$gocode -s 

then run emacs with a go file, test and enjoy it.

No comments: