doomemacs/modules/lang/go/config.el
Henrik Lissner 2dc52bc9be
💥 Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.

Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
  commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)

The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.

+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
  running `doom env enable` (`doom env clear` will reverse this and
  delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
  file. You won't need it if you're confident Emacs will always be
  started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
  doom/reload-env`. Note: this won't work if the Emacs session you're
  running it in doesn't have a correct SHELL set. i.e. don't use this to
  create your first env file!

The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.

This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 01:56:09 -04:00

66 lines
2.3 KiB
EmacsLisp

;;; lang/go/config.el -*- lexical-binding: t; -*-
;;
;; Packages
(after! go-mode
(set-docsets! 'go-mode "Go")
(set-repl-handler! 'go-mode #'gorepl-run)
(set-lookup-handlers! 'go-mode
:definition #'go-guru-definition
:references #'go-guru-referrers
:documentation #'godoc-at-point)
;; Redefines default formatter to *not* use goimports if reformatting a
;; region; as it doesn't play well with partial code.
(set-formatter! 'gofmt
'(("%s" (if (or +format-region-p
(not (executable-find "goimports")))
"gofmt"
"goimports"))))
(if (featurep! +lsp)
(add-hook 'go-mode-hook #'lsp!)
(add-hook 'go-mode-hook #'go-eldoc-setup))
(map! :map go-mode-map
:localleader
"e" #'+go/play-buffer-or-region
"i" #'go-goto-imports ; Go to imports
(:prefix ("h" . "help")
"." #'godoc-at-point ; Lookup in godoc
"d" #'go-guru-describe ; Describe this
"v" #'go-guru-freevars ; List free variables
"i" #'go-guru-implements ; Implements relations for package types
"p" #'go-guru-peers ; List peers for channel
"P" #'go-guru-pointsto ; What does this point to
"r" #'go-guru-referrers ; List references to object
"e" #'go-guru-whicherrs ; Which errors
"w" #'go-guru-what ; What query
"c" #'go-guru-callers ; Show callers of this function
"C" #'go-guru-callees) ; Show callees of this function
(:prefix ("ri" . "imports")
"a" #'go-import-add
"r" #'go-remove-unused-imports)
(:prefix ( "b" . "build")
:desc "go run ." "r" (λ! (compile "go run ."))
:desc "go build" "b" (λ! (compile "go build"))
:desc "go clean" "c" (λ! (compile "go clean")))
(:prefix ("t" . "test")
"t" #'+go/test-rerun
"a" #'+go/test-all
"s" #'+go/test-single
"n" #'+go/test-nested)))
(def-package! gorepl-mode
:commands gorepl-run-load-current-file)
(def-package! company-go
:when (and (featurep! :completion company)
(not (featurep! +lsp)))
:after go-mode
:config
(set-company-backend! 'go-mode 'company-go)
(setq company-go-show-annotation t))