arenzana.org

Emacs Go Mode

January 21, 2019

You will notice how much I use “me” and “I” on this post. This because your emacs configuration is extremely personal. You are creating a “dream editor”, and the options that I pick might not be of your preference. Feel free to make it your own!

Back on topic. I started writing Go in late 2015. At first, I used Sublime Text, which I like a lot, but I was a little jealous of those using vim-go and I figured there would be a way to make myself at home writing Go in Emacs. This is how the adventure began.

Find a Mode!

The first thing I had to do was find a major mode for Go on emacs. It didn’t take me long to find go-mode. Installation is not hard, as it’s available as a package in the MELPA repository. A simple M-x package-install go-mode sufficed. Configuring it was a bit harder.

This block enables go-mode and makes sure it runs gofmt before saving. gofmt allows our code to be nice and tidy and to let go-mode take care of importing the required packages. Nifty, huh? Makes coding nicer.

Making life even easier

Some extra elements to make our lives easier. Not necessary, but nice to have.

How about a simple command to comment out big blocks of code? C-c C-c. Also, compilation-scroll-output simply scrolls the compilation buffer all the way to the end.

What’s left?

This is my current set up. It works really well for my needs, but it might not be yours. Something I’ll work on is to integrate delve (golang debugger) into the editor, but I suppose I’m quite old school.

I also have Magit integrated into my workflow, but that’s a topic for a different episode. To be honest, I don’t miss anything from Sublime (or Atom or MS Code), plus it already makes use of my favorite editor. A simple .emacs file gives me all the customization that I need and I know I always have MY set up everywhere.