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.

87 lines
3.3 KiB

  1. # Prelude Go
  2. This module builds on top of the shared [Programming](programming.md)
  3. module, as well as the [Prelude-LSP](lsp.md) module.
  4. The following keybindings are set by default, which are not present in
  5. each mode's default bindings:
  6. * <kbd>C-c a</kbd> (`go-test-current-project`)
  7. * <kbd>C-c m</kbd> (`go-test-current-file`)
  8. * <kbd>C-c .</kbd> (`go-test-current-test`)
  9. * <kbd>C-c b</kbd> (`go-run`)
  10. * <kbd>C-h f</kbd> (`godoc-at-point`)
  11. Run <kbd>C-h m</kbd> for all the key bindings and other documentation.
  12. There are two ways to manage projects in Go: `$GOPATH` and with Go
  13. modules. Modules are the newer, recommended method. Read [Using Go
  14. Modules](https://go.dev/blog/using-go-modules) to learn about this, if
  15. you are unfamiliar with the subject. Many of the tools used by Prelude
  16. Go may provide functions that are broken with modules. There is
  17. usually another function that will work properly; when in doubt, use a
  18. function provided by `lsp-mode` which is documented below.
  19. Generics were added to Go in 1.18. `gopls`, the backend for `lsp-mode`
  20. setup herein, supports generics as long as `gopls` itself was built
  21. with 1.18+. Other minor modes may not support generics yet.
  22. ## Go Mode
  23. `prelude-go` builds on several useful Go tools, and establishes sensible
  24. defaults. The major mode is `go-mode`. Documentation is available at [github.com/dominikh/go-mode.el](https://github.com/dominikh/go-mode.el)
  25. ## Go Projectile
  26. [Projectile](https://github.com/bbatsov/projectile) integration is
  27. provided by [go-projectile](https://github.com/dougm/go-projectile).
  28. This provides:
  29. * Projectile integration
  30. * Switching GOPATH if desired per project (customizable via
  31. `customize`)
  32. * Ability to download all commonly used `go` tools via <kbd>M-x
  33. go-projectile-install-tools</kbd> and update them via <kbd>M-x
  34. go-projectile-update-tools</kbd>
  35. * Very basic refactoring via `go-projectile-rewrite` (uses `gofmt -r`)
  36. * Support for `go get` and `go get -u` via `go-projectile-get` and
  37. `go-projectile-update`.
  38. See its documentation for details.
  39. ## LSP Mode and LSP UI
  40. [LSP](https://microsoft.github.io/language-server-protocol/) (Language
  41. Server Protocol) is a protocol that allows editors to use an external
  42. "language server" to provide features like autocompletion,
  43. documentation, and code navigation rather than implementing these
  44. features separately in each editor. Emacs supports LSP via
  45. `lsp-mode`. The language server used is
  46. [gopls](https://github.com/golang/tools/tree/master/gopls).
  47. To install `gopls`, change to a directory outside of `$GOPATH` or any
  48. module (e.g., `/tmp`) and execute:
  49. ```
  50. go install golang.org/x/tools/gopls@latest
  51. ```
  52. Ensure that `gopls` is in your `$PATH`.
  53. Excellent documentation for `lsp-mode` and `lsp-ui` are provided at [emacs-lsp.github.io/lsp-mode/](https://emacs-lsp.github.io/lsp-mode/)
  54. If a feature, such as documentation, refactoring, indenting, etc. is
  55. provided by `lsp`, you should use it instead of calling to another
  56. tool. `gopls` is the officially maintained tool that supercedes
  57. functionality in other tools, like `gocode`, and works properly with
  58. modules and generics.
  59. Company support is automatically added that works with `lsp`.
  60. ## GoTest
  61. [gotest](https://github.com/nlamirault/gotest.el) is also provided
  62. while editing Go files in order to run tests more easily. The bindings
  63. provided by `prelude-go` are listed at the top because `gotest` does
  64. not set any.