63

I don't seem to be able to enable a go mode for emacs. C mode doesn't work without semicolons. The best I have found is the JavaScript mode by Karl Landstrom, since JavaScript also doesn't require semicolons.

Braiam
  • 1
  • 11
  • 47
  • 78

5 Answers5

79

Try misc/emacs/go-mode.el (web link) in the Go distribution.

If you are using Emacs 24 and marmalade repo, use M-x package-install <RET> go-mode to install it directly.

Community
  • 1
  • 1
  • 4
    Just to clarify, it's in the Go distribution, not the Emacs distribution. For me it was in ~/go/misc/emacs. – gregsabo Nov 13 '09 at 21:53
  • 2
    You really should *not* use marmalade to install go-mode right now. The version on there is terribly outdated. – Dominik Honnef Oct 08 '13 at 15:15
  • What can we do to make sure that it's _not_ terribly outdated? Using package mode is tremendously convenient... – Viktor Haag Jan 01 '14 at 19:12
  • 1) Could've used a different repository, such as MELPA 2) It's been taken care of. the marmalade version isn't terribly outdated anymore – Dominik Honnef Jan 07 '14 at 19:10
  • 1
    As of now I think the right place to find that link is here: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins (yours is now a 404). – nc. Feb 05 '15 at 04:22
  • 1
    Note https://github.com/dominikh/go-mode.el is now the canonical location of the Emacs mode for Go as it has been removed from the Go distribution. The most up-to-date version is now in the MELPA repository and can indeed be installed with `M-x package-install go-mode`. –  Aug 25 '16 at 10:28
24

If your Go installs to /usr/local/go then add the following to your .emacs file.

;; go mode                                                                                           
(setq load-path (cons "/usr/local/go/misc/emacs" load-path))                                         
(require 'go-mode-load)
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
Spyplane
  • 435
  • 4
  • 7
7

Update from 2014 for Linux users

You can now download the golang-mode for Emacs from your package manager:

  • Fedora: yum install emacs-golang
  • Debian: apt-get install golang-mode
  • Ubuntu: apt-get install golang-mode

I only checked on Fedora, but the package is automatically installed and you have nothing to do except enjoying your new golang mode! And it is also updated as any other package of your system.

There are probably packages on other Linux distributions too.

Stephen Kitt
  • 2,786
  • 22
  • 32
julienc
  • 19,087
  • 17
  • 82
  • 82
5

Read Writing Go in Emacs and its follow-up, written by Dominik Honnef, the author of the official go-mode.

There he explains the story of go-mode and ways to install it, how to read Go documentation from inside Emacs, how to manage import statements of Go files in Emacs, how to setup autocomplete, on-the-fly syntax checking, snippets, and a lot of other super useful features for developing Go in Emacs.

Mostafa
  • 26,886
  • 10
  • 57
  • 52
4

Yes, there is. It is in the source code, inside the misc/emacs dir.

Felix Yan
  • 14,841
  • 7
  • 48
  • 61
Mike
  • 49
  • 1