1

When I compile a simple (incorrect) go program like this from emacs

package main

func main() int {
}

I get this result

-*- mode: compilation; default-directory: "~/Go/" -*-
Compilation started at Mon Aug 12 22:37:46

go run assert.go
# command-line-arguments
./assert.go:3:6: func main must have no arguments and no return values
./assert.go:4:1: missing return at end of function

Compilation exited abnormally with code 2 at Mon Aug 12 22:37:46

The problem is easier to see in a screenshot

compilation results

Notice how only the part of the filename and line number up to the second : is red. This means that when I use goto-error emacs jumps to the start of the line, whereas the compile info has the column in it too.

This looks like a pretty standard compiler output so I would have thought emacs should be doing this by itself.

Is this a bug? Or is it something I should be configuring?

I'm using emacs 1:26.1+1-3.2ubuntu2 from ubuntu 19.04.

1 Answers1

1

The compilation mode documentation says the following:

To parse messages from the compiler, Compilation mode uses the variable compilation-error-regexp-alist which lists various error message formats and tells Emacs how to extract the locus from each. A similar variable, grep-regexp-alist, tells Emacs how to parse output from a grep command (see Grep Searching).

Basically compilation-error-regexp-alist-alist defines a list of named regexps and compilation-error-regexp-alist says which of those compilation mode should try to use to match errors in your compilation buffer.

It seems that for whatever reason your emacs is configured in such a way that it isn't picking a regexp that properly matches filename:line_num:col_num. The default 'gnu regexp should match that. You try temporarily changing the value of compilation-error-regexp-alist to be just (gnu) and see if that fixes it for you:

M-; (setq  compilation-error-regexp-alist '(gnu))

Assuming that that works you probably then want to look at what the other regexp values are in compilation-error-regexp-alist and reorder them so that 'gnu matches before which ever other one you are currently matching against.

psanford
  • 176
  • 2
  • Setting `(setq compilation-error-regexp-alist '(gnu))` did work thank you :-) I guess I have a mode installed which has messed with the list. Will investigate further. Thank you very much for your help. – Nick Craig-Wood Aug 13 '19 at 07:37
  • I found the problem eventually... it was in my `.emacs` :blush: Some time in the last 10 years I had obviously put in a crazy regexp for some reason. I removed it and all is good! – Nick Craig-Wood Aug 15 '19 at 16:46