Moving to Doom Emacs!

This commit is contained in:
Derek Taylor
2019-12-16 20:21:19 -06:00
parent d9f2f456f1
commit d4b4c33550
683 changed files with 51877 additions and 100 deletions

View File

@@ -0,0 +1,97 @@
#+TITLE: lang/go
#+DATE: January 16, 2017
#+SINCE: v2.0
#+STARTUP: inlineimages
* Table of Contents :TOC:
- [[#description][Description]]
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#go][Go]]
- [[#dependencies][Dependencies]]
- [[#features][Features]]
- [[#configuration][Configuration]]
- [[#troubleshooting][Troubleshooting]]
* Description
This module adds [[https://golang.org][Go]] support.
+ Code completion (~gocode~)
+ Documentation lookup (~godoc~)
+ Eldoc support (~go-eldoc~)
+ REPL (~gore~)
+ Syntax-checking (~flycheck~)
+ Auto-formatting on save (~gofmt~)
+ Code navigation & refactoring (~go-guru~)
+ [[../../editor/file-templates/templates/go-mode][File templates]]
+ [[https://github.com/hlissner/doom-snippets/tree/master/go-mode][Snippets]]
+ Generate testing code (~go-gen-test~)
+ Code checking (~flycheck-golangci-lint~)
** Module Flags
+ =+lsp= Enables integration for the gopls LSP server.
** Plugins
+ [[https://github.com/dominikh/go-mode.el][go-mode]]
+ [[https://github.com/syohex/emacs-go-eldoc][go-eldoc]]
+ [[https://github.com/dominikh/go-mode.el][go-guru]]
+ [[https://github.com/manute/gorepl-mode][gorepl-mode]]
+ [[https://github.com/brantou/emacs-go-tag][go-tag]]
+ [[https://github.com/mdempsky/gocode][company-go]]*
+ [[https://github.com/s-kostyaev/go-gen-test][go-gen-test]]
+ [[https://github.com/weijiangan/flycheck-golangci-lint][flycheck-golangci-lint]] (if =:tools flycheck= is enabled)
* Prerequisites
** Go
To get started with Go, you need the ~go~ tool:
*** MacOS
#+BEGIN_SRC bash
brew install go
#+END_SRC
*** Arch Linux
#+BEGIN_SRC bash
sudo pacman -S go
#+END_SRC
*** openSUSE
#+BEGIN_SRC sh :dir /sudo::
sudo zypper install go
#+END_SRC
** Dependencies
This module requires a valid ~GOPATH~, and the following Go packages:
+ ~gocode~ (for code completion & eldoc support)
+ ~godoc~ (for documentation lookup)
+ ~gorename~ (for extra refactoring commands)
+ ~gore~ (for the REPL)
+ ~guru~ (for code navigation & refactoring commands)
+ ~goimports~ (optional: for auto-formatting code on save & fixing imports)
+ ~gotests~ (for generate test code)
+ ~gomodifytags~ (for manipulating tags)
#+BEGIN_SRC sh
export GOPATH=~/work/go
go get -u github.com/motemen/gore/cmd/gore
go get -u github.com/mdempsky/gocode
go get -u golang.org/x/tools/cmd/godoc
go get -u golang.org/x/tools/cmd/goimports
go get -u golang.org/x/tools/cmd/gorename
go get -u golang.org/x/tools/cmd/guru
go get -u github.com/cweill/gotests/...
go get -u github.com/fatih/gomodifytags
#+END_SRC
+ ~golangci-lint~ (optional: for flycheck to integrate golangci-lint results)
it is recommended to *not* use go get to install this one, check the
[[https://github.com/golangci/golangci-lint#binary-release][documentation]].
* TODO Features
* TODO Configuration
* TODO Troubleshooting

View File

@@ -0,0 +1,50 @@
;;; lang/go/autoload.el -*- lexical-binding: t; -*-
;;
;; Tests
(defvar +go-test-last nil
"The last test run.")
(defun +go--spawn (cmd)
(save-selected-window
(compile cmd)))
(defun +go--run-tests (args)
(let ((cmd (concat "go test " args)))
(setq +go-test-last (concat "cd " default-directory ";" cmd))
(+go--spawn cmd)))
;;;###autoload
(defun +go/test-rerun ()
(interactive)
(if +go-test-last
(+go--spawn +go-test-last)
(+go/test-all)))
;;;###autoload
(defun +go/test-all ()
(interactive)
(+go--run-tests ""))
;;;###autoload
(defun +go/test-nested ()
(interactive)
(+go--run-tests "./..."))
;;;###autoload
(defun +go/test-single ()
(interactive)
(if (string-match "_test\\.go" buffer-file-name)
(save-excursion
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)")
(+go--run-tests (concat "-run" "='" (match-string-no-properties 2) "'")))
(error "Must be in a _test.go file")))
;;;###autoload
(defun +go/play-buffer-or-region (&optional beg end)
"TODO"
(interactive "r")
(if (use-region-p)
(go-play-region beg end)
(go-play-buffer)))

View File

@@ -0,0 +1,75 @@
;;; 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-local-vars-hook #'lsp!)
(add-hook 'go-mode-hook #'go-eldoc-setup))
(map! :map go-mode-map
:localleader
"a" #'go-tag-add
"d" #'go-tag-remove
"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
"g" #'go-gen-test-dwim
"G" #'go-gen-test-all
"e" #'go-gen-test-exported)))
(use-package! gorepl-mode
:commands gorepl-run-load-current-file)
(use-package! company-go
:when (featurep! :completion company)
:unless (featurep! +lsp)
:after go-mode
:config
(set-company-backend! 'go-mode 'company-go)
(setq company-go-show-annotation t))
(use-package! flycheck-golangci-lint
:when (featurep! :tools flycheck)
:hook (go-mode . flycheck-golangci-lint-setup))

View File

@@ -0,0 +1,23 @@
;; -*- lexical-binding: t; no-byte-compile: t; -*-
;;; lang/go/doctor.el
(assert! (or (not (featurep! +lsp))
(featurep! :tools lsp))
"This module requires (:tools lsp)")
(unless (executable-find "guru")
(warn! "Couldn't find guru. Refactoring commands (go-guru-*) won't work"))
(unless (executable-find "gore")
(warn! "Couldn't find gore. REPL will not work"))
(unless (executable-find "gotests")
(warn! "Couldn't find gotests. Generating tests will not work"))
(unless (executable-find "gomodifytags")
(warn! "Couldn't find gomodifytags. Manipulating struct tags will not work"))
(when (featurep! :completion company)
(require 'company-go)
(unless (executable-find company-go-gocode-command)
(warn! "Couldn't find gocode. Code completion won't work")))

View File

@@ -0,0 +1,15 @@
;; -*- no-byte-compile: t; -*-
;;; lang/go/packages.el
(package! go-eldoc)
(package! go-guru)
(package! go-mode)
(package! gorepl-mode)
(package! go-tag)
(package! go-gen-test)
(when (featurep! :completion company)
(package! company-go))
(when (featurep! :tools flycheck)
(package! flycheck-golangci-lint))