Using Go on GNU Emacs 29 or later

The 29th version of GNU Emacs is probably going to be released sometime this year (2023). This version introduces awesome new features such as:

These features makes it possible to have a complete development environment for Go with built-in GNU Emacs packages. In order to have syntax highlight and other features1, use the following on your configuration file:

(use-package treesit
  :preface
  (dolist (mapping '((go-mode . go-ts-mode)))
    (add-to-list 'major-mode-remap-alist mapping))
  :init
  (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode))
  (add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode)))

For the LSP client, you can write the following to automatically connect to gopls when you open a Go file:

(use-package eglot
  :hook ((go-ts-mode . eglot-ensure))

This should be enough to give you LSP support, syntax highlighting and error diagnostics. All of this already bundled on GNU Emacs!


Links to this article


Articles from blogs I follow around the net

Trimming a Fake Object

A refactoring example. When I introduce the Fake Object testing pattern to people, a common concern is the maintenance burden of it. The point of the pattern is that you write some 'working' code only for test purposes. …

via ploeh blog November 20, 2023

Building a digital vigil for those we've lost

This post is hard to write in a lot of ways. It's more personal than most I've written. This is presumptively a tech blog, and this piece is about so much more than technology. But it's important. Making things, software or otherwise, is ultimatel…

via ntietz.com blog November 19, 2023

#122 Experimenting and Learning

Update on what happened across the GNOME project in the week from November 10 to November 17. GNOME Circle Apps and Libraries Workbench A sandbox to learn and prototype with GNOME technologies. Sonny says Workbench is a code playground and Library to learn, e…

via This Week in GNOME November 17, 2023

Generated by openring