rice

personal dot files and scripts for linux and macOS
Log | Files | Refs | README | LICENSE

module-go.el (4279B)


      1 ;;; module-go.el --- Packages used for golang
      2 
      3 ;; Author: Mark Feller <mark.feller@member.fsf.org>
      4 
      5 ;; This file is not part of GNU Emacs.
      6 
      7 ;; This file is free software; you can redistribute it and/or modify
      8 ;; it under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation; either version 3, or (at your option)
     10 ;; any later version.
     11 
     12 ;; This file is distributed in the hope that it will be useful,
     13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;; GNU General Public License for more details.
     16 
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
     19 
     20 ;;; Commentary:
     21 
     22 ;;; Code:
     23 
     24 (defvar mjf/go-compile-command
     25   "go build -v && go vet && go test -covermode=count -coverprofile=out.cover")
     26 
     27 (defun mjf/go-prog-init ()
     28   "if go is install go get all dependencies for emacs go packages"
     29   (interactive)
     30   (if (not (eq (executable-find "go") nil))
     31       (progn
     32         (mapcar (lambda (pkg)
     33                   (let ((cmd (concat "go install " pkg)))
     34                     (call-process-shell-command cmd nil "*go-get-output*" t)))
     35                 '("github.com/nsf/gocode@latest"
     36                   "golang.org/x/tools/cmd/goimports@latest"
     37                   "github.com/rogpeppe/godef@latest"
     38                   "golang.org/x/lint@latest"
     39                   "golang.org/x/tools/cmd/gorename@latest"
     40                   "golang.org/x/tools/cmd/guru@latest"
     41                   "github.com/kisielk/errcheck@latest"
     42                   "golang.org/x/tools/gopls@latest")))
     43     (message "go executable not found, install go from https://golang.org/download")))
     44 
     45 (defun mjf/ginkgo-test (package)
     46   "Run ginkgo test suites recursively from a given go package"
     47   (interactive (list (read-directory-name "Package:")))
     48   (async-shell-command
     49    (concat "ginkgo -r " package) "*Ginkgo Tests*")
     50 
     51   ;; get out of evil insert mode and dont truncate text
     52   (switch-to-buffer "*Ginkgo Tests*")
     53   (local-set-key (kbd "q") 'kill-buffer-and-window)
     54   (evil-motion-state)
     55   (toggle-truncate-lines)
     56   (message nil)
     57   (previous-buffer))
     58 
     59 (defun mjf/go-cover ()
     60   (interactive)
     61   (shell-command "go tool cover -html=out.cover"))
     62 
     63 (defun mjf/setup-go-mode-compile ()
     64   "Customize compile command to run go build"
     65   (set (make-local-variable 'compile-command)
     66        mjf/go-compile-command))
     67 
     68 (defun mjf/go-init-company ()
     69   "Initialize company mode for go"
     70   (set (make-local-variable 'company-backends) '(company-go))
     71   (company-mode))
     72 
     73 (use-package go-mode
     74   :demand
     75   :bind
     76   (:map go-mode-map
     77         ("C-c C-g" . go-goto-imports)
     78         ("C-c C-c" . compile)
     79         ("C-c C-t" . ginkgo-test)
     80         ("C-c C"   . go-cover))
     81 
     82   :init
     83   (unless (getenv "GOPATH")
     84     (setenv "GOPATH" (concat (getenv "HOME") "/Development/go")))
     85 
     86   (setenv "PATH" (concat (getenv "PATH") ":"
     87                          (concat (getenv "GOPATH")"/bin")))
     88 
     89   :config
     90   (setq gofmt-command "goimports") ; use goimports instead of go-fmt
     91   (setq godoc-command "godoc")     ; use godoc instead of go doc
     92   (setq tab-width 4)
     93 
     94   ;; (add-hook 'go-mode-hook 'eglot-ensure)
     95   (add-hook 'go-mode-hook 'mjf/setup-go-mode-compile)
     96   (add-hook 'go-mode-hook 'subword-mode)
     97   (add-hook 'go-mode-hook 'hs-minor-mode)
     98   (add-hook 'before-save-hook 'gofmt-before-save)
     99   )
    100 
    101 ;; (use-package go-add-tags
    102 ;;   :after go-mode)
    103 
    104 ;; (use-package go-errcheck
    105 ;;   :after go-mode)
    106 
    107 ;; (use-package go-stacktracer)
    108 
    109 ;; (use-package go-guru
    110 ;;   :after go-mode
    111 ;;   :bind
    112 ;;   (:map go-mode-map
    113 ;;         ("M-."   . go-guru-definition)
    114 ;;         ("C-c d" . go-guru-describe)))
    115 
    116 ;; (use-package company-go
    117 ;;   :demand
    118 ;;   :config
    119 ;;   (add-hook 'go-mode-hook 'mjf/go-init-company))
    120 
    121 ;; (use-package go-eldoc
    122 ;;   :after (go-mode eldoc)
    123 ;;   :config
    124 ;;   (add-hook 'go-mode-hook 'go-eldoc-setup))
    125 
    126 ;; (use-package flycheck-gometalinter
    127 ;;   :disabled
    128 ;;   :after (go-mode flycheck-mode)
    129 ;;   :config
    130 ;;   (flycheck-gometalinter-setup)
    131 ;;   (setq flycheck-gometalinter-deadline "10s")
    132 ;;   (setq flycheck-gometalinter-fast t)
    133 ;;   (setq flycheck-gometalinter-disable-linters '("gotype" "gocyclo")))
    134 
    135 (provide 'module-go)
    136 
    137 ;;; module-go.el ends here