Skip to content

Commit f00b1b5

Browse files
committed
Merge pull request xiaohanyu#162 from chuchao333/feature/ome-golang
Add a module ome-golang.org to support golang development under emacs
2 parents c94814a + 583f947 commit f00b1b5

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

modules/ome-golang.org

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#+TITLE: Oh My Emacs golang
2+
#+OPTIONS: toc:2 num:nil ^:nil
3+
4+
This is part of [[https://github.com/xiaohanyu/oh-my-emacs][oh-my-emacs]].
5+
6+
* Prerequisites
7+
:PROPERTIES:
8+
:CUSTOM_ID: golang-prerequisites
9+
:END:
10+
11+
#+NAME: golang-prerequisites
12+
#+CAPTION: Prerequisites for ome-golang module
13+
| Package | Windows | Ubuntu/Debian/Mint | ArchLinux | Fedora | Mac OS X | Mandatory? |
14+
|---------+---------+--------------------+-----------+--------+----------+------------|
15+
| [[https://golang.org/cmd/go][go tool]] | | go | | | | Yes |
16+
| [[https://github.com/rogpeppe/godef][godef]] | | [go] | | | | No |
17+
| [[https://github.com/dougm/goflymake][goflymake]] | | [go] | | | | No |
18+
| [[https://github.com/nsf/gocode][gocode]] | | [go] | | | | No |
19+
20+
* El-get packages
21+
:PROPERTIES:
22+
:CUSTOM_ID: golang-el-get-packages
23+
:END:
24+
25+
#+NAME: golang-el-get-packages
26+
#+CAPTION: El-get packages for ome-golang module
27+
| Package | Status | Description |
28+
|--------------+----------+---------------------------------------------------|
29+
| [[https://github.com/dominikh/go-mode.el][go-mode]] | Required | This is the Emacs mode for editing Go code |
30+
31+
* About Go
32+
You can find all the necessary information about golang in the official [[https://golang.org][site]].
33+
34+
* go-mode
35+
:PROPERTIES:
36+
:CUSTOM_ID: go-mode
37+
:END:
38+
39+
Beginning with Go 1.4, editor integration will not be part of the Go distribution
40+
anymore, making the github repository the canonical place for go-mode. Please refer
41+
the repo for all the features and other information for the go-mode.
42+
43+
#+NAME: go-mode
44+
#+BEGIN_SRC emacs-lisp
45+
(defun ome-go-mode-setup ()
46+
47+
; set the GOPATH here if not already
48+
; (setenv "GOPATH" "/home/chuchao/gowork")
49+
50+
;; enable the go-mode
51+
(require 'go-mode)
52+
(add-hook 'before-save-hook 'gofmt-before-save)
53+
54+
; key binding for go-remove-unused-imports
55+
(add-hook 'go-mode-hook '(lambda ()
56+
(local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)))
57+
58+
; key binding for go-goto-imports
59+
(add-hook 'go-mode-hook '(lambda ()
60+
(local-set-key (kbd "C-c C-g") 'go-goto-imports)))
61+
62+
; bind C-c C-f for gofmt
63+
(add-hook 'go-mode-hook '(lambda ()
64+
(local-set-key (kbd "C-c C-f") 'gofmt)))
65+
66+
; godoc
67+
(when (executable-find "godoc")
68+
(add-hook 'go-mode-hook '(lambda ()
69+
(local-set-key (kbd "C-c C-k") 'godoc))))
70+
71+
; goflymake
72+
(when (executable-find "goflymake")
73+
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/dougm/goflymake"))
74+
(require 'go-flymake)
75+
(require 'go-flycheck))
76+
77+
; go-code
78+
(when (executable-find "gocode")
79+
80+
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/nsf/gocode/emacs-company"))
81+
(require 'company-go)
82+
83+
(add-hook 'go-mode-hook 'company-mode)
84+
(add-hook 'go-mode-hook (lambda ()
85+
(set (make-local-variable 'company-backends) '(company-go))
86+
(company-mode)))))
87+
88+
(when (executable-find "go")
89+
(ome-install 'go-mode))
90+
#+END_SRC
91+
92+
* Note
93+
The settings listed above are mainly referred from the blog post
94+
[[http://yousefourabi.com/blog/2014/05/emacs-for-go/][Emacs for Go]], adapted to
95+
the oh-my-emacs framework with some other configurations. Credits also go to the
96+
original author of the blog post and also the authros of the awesome golang
97+
related emacs modes.

ome.org

+2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ you really need it.
468468
- [[file:modules/ome-experimental.org][ome-experimental.org]]: some experimental packages, such as sppedbar, minimap, etc. Not stable yet now.
469469
- [[file:modules/ome-haskell.org][ome-haskell.org]]: settings for haskell
470470
- [[file:modules/ome-sml.org][ome-sml.org]]: settings for sml
471+
- [[file:modules/ome-golang.org][ome-golang.org]]: settings for golang
471472

472473
#+NAME: load various ome files
473474
#+BEGIN_SRC emacs-lisp
@@ -494,6 +495,7 @@ you really need it.
494495
;; (ome-load "modules/ome-experimental.org" "smooth-scrolling" "sublimity")
495496
(ome-load "modules/ome-haskell.org")
496497
(ome-load "modules/ome-sml.org")
498+
(ome-load "modules/ome-golang.org")
497499
#+END_SRC
498500

499501
** Load User/System Specific Files

0 commit comments

Comments
 (0)