Last active
March 31, 2019 16:21
-
-
Save samertm/8bccfeb30c0902194de5 to your computer and use it in GitHub Desktop.
Tricking Out Emacs for Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) |
Wow! Thank you so much!
Thank you...
FYI the installation command for goimports command has changed:
go get golang.org/x/tools/cmd/goimports
and the new command for installing godef can be found here
go get github.com/rogpeppe/godef
http://stackoverflow.com/questions/31867347/i-am-having-trouble-getting-golang-org-x-tools-cmd-goimports
http://stackoverflow.com/questions/35401625/where-to-get-godef-binary:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yup! Thanks for catching that!