• Stars
    star
    1,358
  • Rank 33,243 (Top 0.7 %)
  • Language
    Emacs Lisp
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Emacs mode for the Go programming language

This is go-mode, the Emacs mode for editing Go code.

It is a complete rewrite of the go-mode that shipped with Go 1.0.3 and before, and was part of Go 1.1 until Go 1.3. Beginning with Go 1.4, editor integration will not be part of the Go distribution anymore, making this repository the canonical place for go-mode.

Features

In addition to normal features, such as fontification and indentation, and close integration with familiar Emacs functionality (for example syntax-based navigation like beginning-of-defun), go-mode comes with the following extra features to provide an improved experience:

  • Integration with gofmt by providing a command of the same name, and gofmt-before-save, which can be used in a hook to format Go buffers before saving them.

    • Setting the gofmt-command variable also allows using goimports.
    • Setting the gofmt-args variable with a list of arguments allows using e.g. gofmt -s.
  • Integration with godoc via the functions godoc and godoc-at-point.

  • Integration with the Playground

    • go-play-buffer and go-play-region to send code to the Playground
    • go-download-play to download a Playground entry into a new buffer
  • Managing imports

    • A function for jumping to the file's imports (go-goto-imports - C-c C-f i)
    • A function for adding imports, including tab completion (go-import-add, bound to C-c C-a)
    • It is recommended that you use goimports or the organize-imports feature of gopls to manage adding/removing/organizing imports automatically.
  • Integration with godef

    • godef-describe (C-c C-d) to describe expressions
    • godef-jump (C-c C-j) and godef-jump-other-window (C-x 4 C-c C-j) to jump to declarations
    • This requires you to install godef via go install github.com/rogpeppe/godef@latest.
  • Basic support for imenu (functions and variables)

  • Built-in support for displaying code coverage as calculated by go test (go-coverage)

  • Several functions for jumping to and manipulating the individual parts of function signatures. These functions support anonymous functions, but are smart enough to skip them when required (e.g. when jumping to a method receiver or docstring.)

    • Jump to the argument list (go-goto-arguments - C-c C-f a)
    • Jump to the docstring, create it if it does not exist yet (go-goto-docstring - C-c C-f d).
    • Jump to the function keyword (go-goto-function - C-c C-f f)
    • Jump to the function name (go-goto-function-name - C-c C-f n)
    • Jump to the return values (go-goto-return-values - C-c C-f r)
    • Jump to the method receiver, adding a pair of parentheses if no method receiver exists (go-goto-method-receiver - C-c C-f m).

    All of these functions accept a prefix argument (C-u), causing them to skip anonymous functions.

Installation

MELPA

The recommended way of installing go-mode is via ELPA, the Emacs package manager, and the MELPA Stable repository, which provides an up-to-date version of go-mode.

If you're not familiar with ELPA yet, consider reading this guide.

Manual

To install go-mode manually, check out the go-mode.el repository in a directory of your choice, add it to your load path and configure Emacs to automatically load it when opening a .go file:

(add-to-list 'load-path "/place/where/you/put/it/")
(autoload 'go-mode "go-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))

Either evaluate the statements with C-x C-e, or restart Emacs.

Other extensions

There are several third party extensions that can enhance the Go experience in Emacs.

Gopls integration

Gopls is the official language server protocol (lsp) implementation provided by the Go team. It is intended to replace the existing third party tools for code formatting (gofmt), automatic imports (goimports), code navigation (godef/guru), type and function descriptions (godoc/godef), error checking, auto completion (gocode), variable and type renaming (rename), and more. Once gopls is stable the older tools will no longer be supported.

Gopls is a supported backend for lsp-mode. It will be used automatically by lsp-mode if gopls is found in your PATH. You can install gopls via: go install golang.org/x/tools/gopls@latest. To enable lsp-mode for go buffers:

(add-hook 'go-mode-hook 'lsp-deferred)

Syntax/error checking

There are two ways of using flymake with Go:

  1. goflymake, which internally uses go build to capture all errors that a regular compilation would also produce
  2. flymake-go for a more lightweight solution that only uses gofmt and as such is only able to catch syntax errors. Unlike goflymake, however, it does not require an additional executable.

Additionally, there is flycheck, a modern replacement for flymake, which comes with built-in support for Go. In addition to using go build or gofmt, it also has support for go vet, golint and errcheck.

Auto completion

For auto completion, take a look at gocode.

eldoc

https://github.com/syohex/emacs-go-eldoc provides eldoc functionality for go-mode.

Snippets

I maintain a set of YASnippet snippets for go-mode at https://github.com/dominikh/yasnippet-go

Integration with errcheck

https://github.com/dominikh/go-errcheck.el provides integration with errcheck.

Stability

go-mode.el has regular, tagged releases and is part of the MELPA Stable repository. These tagged releases are intended to provide a stable experience. APIs added in tagged releases will usually not be removed or changed in future releases.

Changes made on the master branch, which is tracked by the normal MELPA repository, however, are under active development. New APIs are experimental and may be changed or removed before the next release. Furthermore, there is a higher chance for bugs.

If you want a stable experience, use MELPA Stable. If you want cutting edge features, or "beta-test" future releases, use MELPA or the master branch.

More Repositories

1

go-tools

Staticcheck - The advanced Go linter
Go
5,848
star
2

gotraceui

Go execution trace frontend
Go
918
star
3

go-staticcheck

396
star
4

go-unused

341
star
5

go-structlayout

242
star
6

go-js-dom

Go
237
star
7

go-simple

230
star
8

xcapture

The command-line window recorder
Go
93
star
9

tmux-ruby

ruby library to control tmux
Ruby
81
star
10

filesize

filesize is a small ruby class for handling filesizes with both the SI and binary prefixes, allowing conversion from any size to any other size.
Ruby
80
star
11

staticcheck-action

Staticcheck's official GitHub Action
72
star
12

implements

Check which interfaces a Go type implements
Go
66
star
13

yasnippet-go

48
star
14

go-errcheck.el

Emacs Lisp
42
star
15

go-vanity

Go
39
star
16

wayland-go

Wayland in Go
Go
26
star
17

everything

The semantic desktop search engine
Go
25
star
18

go-augeas

Go bindings for augeas
Go
21
star
19

weechat-ruby

A ruby wrapper around the (not so nice) WeeChat API
Ruby
20
star
20

go-js-xhr

Go
19
star
21

go-vk

Go bindings for Vulkan
Go
19
star
22

netstat-nat

Go
17
star
23

go-keyify

15
star
24

wayfarer

Experiments involving a Zig Wayland compositor.
Zig
13
star
25

gamayun

Torrent client designed for seeding tens of thousands of torrents.
Go
13
star
26

go-nut

Go
12
star
27

go-rdeps

11
star
28

go-js-console

Go
9
star
29

go-transmission

Go
9
star
30

go-vfat

VFAT library for Go
Go
6
star
31

idxgrep

Indexed grep
Go
6
star
32

dmenu-ruby

A Ruby OOP wrapper around dmenu
Ruby
5
star
33

go-challenge-solutions

Go
5
star
34

go-pcap

Go
5
star
35

go-quickcheck

Go
4
star
36

go-irc

Go
4
star
37

go-collectd

Go
4
star
38

go-helpers

A random collection of Go helpers and scripts
Shell
4
star
39

uses

Go
4
star
40

gosu-changdul

a widget set and window manager for gosu
Ruby
3
star
41

go-xmpp

Go
3
star
42

c3_xbmc

nfo files and rename scripts for Chaos Communication Congress recordings so XBMC can add them as a show
Shell
3
star
43

orlydb

Ruby
3
star
44

go-id3

Go
3
star
45

go-conntrack

Go
3
star
46

omapi

Go implementation of the OMAPI protocol to control the ISC DHCP server
Go
3
star
47

go-js-d3

Go
3
star
48

dk-comment-toggle

Ruby
2
star
49

weechat-scripts

A bunch of WeeChat scripts
Ruby
2
star
50

gwm

A stacking window manager
Go
2
star
51

go-flood-exporter

Go
2
star
52

go-cups

Go
2
star
53

go-ident

Go
2
star
54

go-styx

Go implementation of the 9P protocol
2
star
55

go-js-http

Go
2
star
56

emacs-yard

emacs font locking for YARD documentation
Emacs Lisp
1
star
57

ryzom

Go libraries for writing tools for Ryzom
Go
1
star
58

simple-router

JavaScript
1
star
59

go-uzbl

Go
1
star
60

go-js-util

Go
1
star
61

nft-traffic-stats-collector

Go
1
star
62

facharbeit

My "Facharbeit"
PHP
1
star
63

go-sndprint

Go
1
star
64

sketchup-selection_manager

Ruby
1
star
65

rubyircd

Ruby
1
star
66

go-js-cubism

Go
1
star
67

gemtester

Ruby
1
star
68

langfmt.el

An emacs library for adding gofmt-like functionality to programming modes
Emacs Lisp
1
star
69

keyword_arguments

named_arguments comes with a bunch of convenient methods for making "named arguments" (hashes as method arguments) in Ruby less painfull
Ruby
1
star
70

ident

A Ruby library for querying identd servers
Ruby
1
star
71

go-pcsensor

Go
1
star
72

gutter

1
star