Skip to content

Instantly share code, notes, and snippets.

@Y-LyN-10
Forked from samertm/.emacs
Created September 22, 2015 16:45
Show Gist options
  • Save Y-LyN-10/8fc6696ee4e26a20c2b2 to your computer and use it in GitHub Desktop.
Save Y-LyN-10/8fc6696ee4e26a20c2b2 to your computer and use it in GitHub Desktop.
Tricking Out Emacs for Go
;; from https://www.youtube.com/watch?v=r6j2W5DZRtA
;; get the following packages ("M-x package-list-packages"):
;; go-mode
;; go-eldoc
;; company-mode
;; company-go
;; get the following go programs (run each line in your shell):
;; go get golang.org/x/tools/cmd/godoc
;; go get golang.org/x/tools/cmd/goimports
;; go get github.com/rogpeppe/godef
;; go get github.com/nsf/gocode
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(setq company-idle-delay nil)
(setq gofmt-command "goimports")
;; UPDATE: gofmt-before-save is more convenient then having a command
;; for running gofmt manually. In practice, you want to
;; gofmt/goimports every time you save anyways.
(add-hook 'before-save-hook 'gofmt-before-save)
(global-set-key (kbd "C-c M-n") 'company-complete)
(global-set-key (kbd "C-c C-n") 'company-complete)
(defun my-go-mode-hook ()
;; UPDATE: I commented the next line out because it isn't needed
;; with the gofmt-before-save hook above.
;; (local-set-key (kbd "C-c m") 'gofmt)
(local-set-key (kbd "M-.") 'godef-jump))
(set (make-local-variable 'company-backends) '(company-go)))
(add-hook 'go-mode-hook 'my-go-mode-hook)
(add-hook 'go-mode-hook 'go-eldoc-setup)
(add-hook 'go-mode-hook 'company-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment