Browse Source

Add go support

main
parent
commit
6985a14825
  1. 75
      README.org
  2. 98
      modules/projects.org

75
README.org

@ -132,81 +132,6 @@ Here's a complete list of all of the options configurable for each host, and the
#+end_src
** Passwords
Pass makes managing passwords extremely easy, encrypring them in a file structure and providing easy commands for generating, modify, and copying passwords. =password-store.el= provides a wrapper for the functionality within Emacs.
#+begin_src emacs-lisp
(use-package password-store
:custom (password-store-dir dotfiles/passwords))
#+end_src
Configure keybindings behind =SPC p=.
+ Copy with =p=
+ Rename with =r=
+ Generate with =g=
#+begin_src emacs-lisp
(dotfiles/leader
"p" '(:ignore t :which-key "Passwords")
"pp" '(password-store-copy :which-key "Copy")
"pr" '(password-store-rename :which-key "Rename")
"pg" '(password-store-generate :which-key "Generate"))
#+end_src
** Languages
Support for individual languages are implemented here.
*** Go
Install the =gopls= language server.
#+begin_src sh :tangle no
GO111MODULE=on go get golang.org/x/tools/gopls@latest
#+end_src
Set the ~GOPATH~ environment variable prior to loading, this allows us to change the default value of ~$HOME/go~ to ~$HOME/.go~.
#+begin_src emacs-lisp
(setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
#+end_src
Additionally, include the =bin= subdirectory of the ~$GOPATH~ in the ~$PATH~ variable, adding compiled golang programs.
#+begin_src emacs-lisp
(setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
#+end_src
Finally we can include the =go-mode= package, integrating it with =lsp=.
#+begin_src emacs-lisp
(use-package go-mode
:hook (go-mode . lsp)
:custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
#+end_src
Apply some custom behaviour before saving:
+ Format buffer
+ Organize imports
#+begin_src emacs-lisp
(defun dotfiles/go-hook ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
#+end_src
#+begin_src emacs-lisp
(add-hook 'go-mode-hook #'dotfiles/go-hook)
#+end_src
Add a golang source code block structure template with ~<go~:
#+begin_src emacs-lisp
(add-to-list 'org-structure-template-alist '("go" . "src go"))
#+end_src
*** HTTP
Instead of the popular =restclient= package, I use [[https://github.com/zweifisch/ob-http][ob-http]] as a lightweight alternative.

98
modules/projects.org

@ -3,7 +3,8 @@
#+EMAIL: chris@chrishayward.xyz
#+PROPERTY: header-args:emacs-lisp :tangle projects.el :comments org
#+PROPERTY: header-args :results silent :eval no-export :comments org
#+PROPERTY: header-args:shell :tangle no
#+PROPERTY: header-args :results silent :eval no-export :comments org
#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
@ -51,7 +52,6 @@ Integrate with *Lsp mode*[fn:5] to provide completion candidates through the *La
:custom (company-backend 'company-lsp))
#+end_src
* DAP
*Dap mode*[fn:7] provides support for the *Debug Adapter Protocol*[fn:3] inside of Emacs.
@ -77,6 +77,29 @@ Open the container management screen with =SPC k=.
"k" '(docker :which-key "Docker"))
#+end_src
* Passwords
*Pass*[fn:12] makes managing passwords extremely easy, encrypring them in a file structure and providing easy commands for generating, modify, and copying passwords. *Password-store.el*[fn:13] provides a wrapper for the functionality within Emacs.
#+begin_src emacs-lisp
(use-package password-store
:custom (password-store-dir dotfiles/passwords))
#+end_src
Configure keybindings behind =SPC p=.
+ Copy with =p=
+ Rename with =r=
+ Generate with =g=
#+begin_src emacs-lisp
(dotfiles/leader
"p" '(:ignore t :which-key "Passwords")
"pp" '(password-store-copy :which-key "Copy")
"pr" '(password-store-rename :which-key "Rename")
"pg" '(password-store-generate :which-key "Generate"))
#+end_src
* Management
Configure *Projectile*[fn:11], a project interaction library for Emacs. It provides a nice set of features for operating on a project level without introducing external dependencies.
@ -87,6 +110,73 @@ Configure *Projectile*[fn:11], a project interaction library for Emacs. It provi
:config (projectile-mode))
#+end_src
* Languages
Support for individual programming languages are implemented here. They can be either:
+ LSP / DAP compliant
+ Emacs-mode compliant
+ Third-party module
** Go
Golang is supported using the *Debug Adapter Protocol*[fn:3] and *Language Server Protocol*[fn:4].
*** Setup
Get started by installing *gopls*[fn:14].
#+begin_src shell
GO111MODULE=on go get golang.org/x/tools/gopls@latest
#+end_src
**** Overriding the =$GOPATH=
Set the =$GOPATH= environment variable prior to loading, this is to allow modification of the default value from ~$HOME/go~ to ~$HOME/.go~.
#+begin_src emacs-lisp
(setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
#+end_src
**** Adding =$GOBIN= to the =$PATH=
Additionally, include the ~bin~ subdirectory of the =$GOPATH= in the =$PATH= variable, adding compiled golang programs to the systems path.
#+begin_src emacs-lisp
(setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
#+end_src
*** Configuration
Finally we can include the *Go-mode*[fn:15] package, adding integration with *Lsp-mode*[fn:5].
#+begin_src emacs-lisp
(use-package go-mode
:hook (go-mode . lsp)
:custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
#+end_src
Apply some custom behaviour before saving buffers:
+ Format buffer
+ Organize imports
#+begin_src emacs-lisp
(defun dotfiles/go-hook ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
#+end_src
#+begin_src emacs-lisp
(add-hook 'go-mode-hook #'dotfiles/go-hook)
#+end_src
Add a golang source code block structure template with ~<go~:
#+begin_src emacs-lisp
(add-to-list 'org-structure-template-alist '("go" . "src go"))
#+end_src
* Resources
[fn:1] https://en.wikipedia.org/wiki/Integrated_development_environment
@ -100,3 +190,7 @@ Configure *Projectile*[fn:11], a project interaction library for Emacs. It provi
[fn:9] https://github.com/Silex/docker.el
[fn:10] https://company-mode.github.io/
[fn:11] https://projectile.mx
[fn:12] https://passwordstore.org
[fn:13] https://git.zx2c4.com/password-store/tree/contrib/emacs
[fn:14] https://pkg.go.dev/golang.org/x/tools/gopls
[fn:15] https://emacswiki.org/emacs/GoMode
Loading…
Cancel
Save