-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-go.el
55 lines (47 loc) · 1.7 KB
/
config-go.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;; package --- Summary
;;; Commentary:
;;; Code:
(require 'eshell)
(require 'go-mode)
(load-relative "./go-guru")
(defun set-exec-path-from-shell-PATH ()
"Set the path from the shell."
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))
(if (or (eq system-type 'gnu/linux) (eq system-type 'darwin))
(progn
(if (eq system-type 'darwin)
(set-exec-path-from-shell-PATH))
(setenv "GOPATH" (expand-file-name "~/gocode"))
(add-to-list 'exec-path (expand-file-name "~/gocode/bin"))
))
(defun my-go-mode-hook ()
"Enable go mode features."
; Use goimports instead of gofmt
(setq gofmt-command "goimports")
; Call Gofmt before saving
(add-hook 'before-save-hook 'gofmt-before-save)
; Customize compile command to run go build
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
; uniform jump key binding
(local-set-key (kbd "M-.") 'godef-jump)
(local-set-key (kbd "<s-left>") 'pop-tag-mark)
(local-set-key (kbd "M-m") 'go-guru-expand-region)
(local-set-key (kbd "M-,") 'go-guru-callers)
)
(add-hook 'go-mode-hook 'my-go-mode-hook)
;; autocomplete
(defun auto-complete-for-go ()
"Set up autocomplete."
(auto-complete-mode 1))
(add-hook 'go-mode-hook 'auto-complete-for-go)
(with-eval-after-load 'go-mode
(require 'go-autocomplete))
;;; config-go.el ends here