This is part of oh-my-emacs.
Package | Windows | Ubuntu/Debian/Mint | ArchLinux | Fedora | Mac OS X | Mandatory? |
---|---|---|---|---|---|---|
go tool | go | Yes | ||||
godef | [go] | No | ||||
goflymake | [go] | No | ||||
gocode | [go] | No |
Package | Status | Description |
---|---|---|
go-mode | Required | This is the Emacs mode for editing Go code |
You can find all the necessary information about golang in the official site.
Beginning with Go 1.4, editor integration will not be part of the Go distribution anymore, making the github repository the canonical place for go-mode. Please refer the repo for all the features and other information for the go-mode.
(defun ome-go-mode-setup ()
; set the GOPATH here if not already
; (setenv "GOPATH" "/home/chuchao/gowork")
;; enable the go-mode
(require 'go-mode)
(add-hook 'before-save-hook 'gofmt-before-save)
; key binding for go-remove-unused-imports
(add-hook 'go-mode-hook '(lambda ()
(local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)))
; key binding for go-goto-imports
(add-hook 'go-mode-hook '(lambda ()
(local-set-key (kbd "C-c C-g") 'go-goto-imports)))
; bind C-c C-f for gofmt
(add-hook 'go-mode-hook '(lambda ()
(local-set-key (kbd "C-c C-f") 'gofmt)))
; godoc
(when (executable-find "godoc")
(add-hook 'go-mode-hook '(lambda ()
(local-set-key (kbd "C-c C-k") 'godoc))))
; goflymake
(when (executable-find "goflymake")
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/dougm/goflymake"))
(require 'go-flymake)
(require 'go-flycheck))
; go-code
(when (executable-find "gocode")
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/nsf/gocode/emacs-company"))
(require 'company-go)
(add-hook 'go-mode-hook 'company-mode)
(add-hook 'go-mode-hook (lambda ()
(set (make-local-variable 'company-backends) '(company-go))
(company-mode)))))
(when (executable-find "go")
(ome-install 'go-mode))
The settings listed above are mainly referred from the blog post Emacs for Go, adapted to the oh-my-emacs framework with some other configurations. Credits also go to the original author of the blog post and also the authros of the awesome golang related emacs modes.