Emacs config utilizing prelude as a base
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
# Prelude Go
This module builds on top of the shared [Programming](programming.md)module, as well as the [Prelude-LSP](lsp.md) module.
The following keybindings are set by default, which are not present ineach mode's default bindings:
* <kbd>C-c a</kbd> (`go-test-current-project`)* <kbd>C-c m</kbd> (`go-test-current-file`)* <kbd>C-c .</kbd> (`go-test-current-test`)* <kbd>C-c b</kbd> (`go-run`)* <kbd>C-h f</kbd> (`godoc-at-point`)
Run <kbd>C-h m</kbd> for all the key bindings and other documentation.
There are two ways to manage projects in Go: `$GOPATH` and with Gomodules. Modules are the newer, recommended method. Read [Using GoModules](https://go.dev/blog/using-go-modules) to learn about this, ifyou are unfamiliar with the subject. Many of the tools used by PreludeGo may provide functions that are broken with modules. There isusually another function that will work properly; when in doubt, use afunction provided by `lsp-mode` which is documented below.
Generics were added to Go in 1.18. `gopls`, the backend for `lsp-mode`setup herein, supports generics as long as `gopls` itself was builtwith 1.18+. Other minor modes may not support generics yet.
## Go Mode
`prelude-go` builds on several useful Go tools, and establishes sensibledefaults. The major mode is `go-mode`. Documentation is available at [github.com/dominikh/go-mode.el](https://github.com/dominikh/go-mode.el)
## Go Projectile
[Projectile](https://github.com/bbatsov/projectile) integration isprovided by [go-projectile](https://github.com/dougm/go-projectile).
This provides:
* Projectile integration* Switching GOPATH if desired per project (customizable via `customize`)* Ability to download all commonly used `go` tools via <kbd>M-x go-projectile-install-tools</kbd> and update them via <kbd>M-x go-projectile-update-tools</kbd>* Very basic refactoring via `go-projectile-rewrite` (uses `gofmt -r`)* Support for `go get` and `go get -u` via `go-projectile-get` and `go-projectile-update`.
See its documentation for details.
## LSP Mode and LSP UI
[LSP](https://microsoft.github.io/language-server-protocol/) (LanguageServer Protocol) is a protocol that allows editors to use an external"language server" to provide features like autocompletion,documentation, and code navigation rather than implementing thesefeatures separately in each editor. Emacs supports LSP via`lsp-mode`. The language server used is[gopls](https://github.com/golang/tools/tree/master/gopls).
To install `gopls`, change to a directory outside of `$GOPATH` or anymodule (e.g., `/tmp`) and execute:
```go install golang.org/x/tools/gopls@latest```
Ensure that `gopls` is in your `$PATH`.
Excellent documentation for `lsp-mode` and `lsp-ui` are provided at [emacs-lsp.github.io/lsp-mode/](https://emacs-lsp.github.io/lsp-mode/)
If a feature, such as documentation, refactoring, indenting, etc. isprovided by `lsp`, you should use it instead of calling to anothertool. `gopls` is the officially maintained tool that supercedesfunctionality in other tools, like `gocode`, and works properly withmodules and generics.
Company support is automatically added that works with `lsp`.
## GoTest
[gotest](https://github.com/nlamirault/gotest.el) is also providedwhile editing Go files in order to run tests more easily. The bindingsprovided by `prelude-go` are listed at the top because `gotest` doesnot set any.
|