Tweak the Go programming setup

This commit is contained in:
Gerard Vermeulen 2025-01-11 18:52:30 +01:00
parent 33fc757a43
commit 8fc0ebbb62

View File

@ -4492,8 +4492,16 @@ changes the semantics of calling `beginning-of-defun'."
:CUSTOM_ID: sec:go-programming
:END:
Links for further investigation are:
1. [[https://gobyexample.com/][Go by example]] is a showcase of short examples with explanations.
[[https://jorge.olano.dev/blog/getting-started-with-go-and-emacs/][Getting started with Go and Emacs]] looks interesting but this setup uses ~eglot~
~go-ts-mode~ (instead of ~go-mode~) and my hardware is too old to use [[https://brew.sh/][HomeBrew]].
This setup uses the following links to install [[https://go.dev/][Go]] and [[https://pkg.go.dev/golang.org/x/tools/gopls][gopls]] on [[https://en.wikipedia.org/wiki/Darwin_(operating_system)][Darwin]]:
1. [[https://go.dev/dl/][Go - all releases - featured downloads]] contains binary and source packages.
2. [[https://go.dev/doc/install][Go installation]] explains how to setup your system.
3. Install [[https://pkg.go.dev/golang.org/x/tools/gopls][gopls]] following the [[https://pkg.go.dev/golang.org/x/tools/gopls#section-readme][installation instructions in the GoPLS README]].
Links to learn [[https://go.dev/][Go]] are:
1. [[https://www.golangprograms.com/go-language.html][Go programming language]] contains a tutorial and a reference.
2. [[https://gobyexample.com/][Go by example]] is a showcase of short examples with explanations.
#+caption[Setup Go programming]:
#+caption: Setup Go programming.
@ -4501,8 +4509,6 @@ Links for further investigation are:
#+begin_src emacs-lisp -n :results silent
(when (featurep 'treesit)
(setopt go-ts-mode-indent-offset 2)
(add-hook 'go-ts-mode-hook (lambda ()
(setq-local tab-width 2)))
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
#+end_src
@ -5249,16 +5255,15 @@ contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][
:END:
Listing [[lst:configure-electric-operator]] configures =electric-operator-mode= to
add spaces around operators for compatibility with for instance the [[https://black.readthedocs.io/en/stable/][Black code
formatter for Python]].
add spaces around operators for [[https://go.dev/][Go]] and [[https://www.python.org/][Python]] (compatibility with [[https://black.readthedocs.io/en/stable/][Black]]!).
#+caption[Configure =electric-operator=]:
#+caption: Configure =electric-operator=.
#+name: lst:configure-electric-operator
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'electric-operator)
(add-hook 'c-mode-common-hook #'electric-operator-mode)
(add-hook 'python-mode-hook #'electric-operator-mode))
(add-hook 'go-ts-mode-hook #'electric-operator-mode)
(add-hook 'python-mode-hook #'electric-operator-mode))
#+end_src
** [[https://joaotavora.github.io/yasnippet/][Smart snippets]]