I showed you my source code, pls respond
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.

75 lines
2.2 KiB

  1. #+TITLE: Go
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle go.el :comments org
  5. #+PROPERTY: header-args:shell :tangle no
  6. #+PROPERTY: header-args :results silent :eval no-export :comments org
  7. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  8. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  9. Go is an open source programming language that makes it easy to build simple, reliable, and efficient software[fn:1]
  10. * Setup
  11. Install ~golang~[fn:1] on your system, and configure your environment prior to loading this module.
  12. #+begin_src shell
  13. RUN apt install -y golang
  14. #+end_src
  15. ** Language server
  16. Get started by installing the ~gopls~[fn:2] language server.
  17. #+begin_src shell
  18. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  19. #+end_src
  20. ** Setup the environment
  21. Make some modifications to the environment. Set the =$GOPATH= variable prior to loading, allowing modification of the default value. Include the =bin= subdirectory of the =$GOPATH= in the =$PATH= variable, adding compiled golang applications to the system path.
  22. #+begin_src emacs-lisp
  23. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  24. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  25. #+end_src
  26. * Config
  27. Use the ~go-mode~[fn:3] package for integration with ~lsp-mode~, manually setting the path to ~gopls~[fn:2] before loading.
  28. #+begin_src emacs-lisp
  29. (use-package go-mode
  30. :hook (go-mode . lsp)
  31. :custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
  32. #+end_src
  33. ** Before save hooks
  34. Apply some custom behaviour when saving ~golang~[fn:1] buffers. Format and organize the imports before saving.
  35. #+begin_src emacs-lisp
  36. (defun dotfiles/go-hook ()
  37. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  38. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  39. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  40. #+end_src
  41. ** Babel structure templates
  42. Configure the ~babel~ engine to support ~golang~[fn:1] source blocks.
  43. #+begin_src emacs-lisp
  44. (add-to-list 'org-structure-template-alist '("go" . "src go"))
  45. #+end_src
  46. * Footnotes
  47. [fn:1] https://golang.org
  48. [fn:2] https://pkg.go.dev/golang.org/x/tools/gopls
  49. [fn:3] https://emacswiki.org/emacs/GoMode