Skip to content

Latest commit

 

History

History
97 lines (76 loc) · 3.46 KB

ome-golang.org

File metadata and controls

97 lines (76 loc) · 3.46 KB

Oh My Emacs golang

This is part of oh-my-emacs.

Prerequisites

PackageWindowsUbuntu/Debian/MintArchLinuxFedoraMac OS XMandatory?
go toolgoYes
godef[go]No
goflymake[go]No
gocode[go]No

El-get packages

PackageStatusDescription
go-modeRequiredThis is the Emacs mode for editing Go code

About Go

You can find all the necessary information about golang in the official site.

go-mode

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

Note

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.