I'm trying to use Emacs for golang programming. I downloaded the go-mode
package and installed it. My .emacs
is:
(require 'go-mode)
When I'm opening *.go
files, go-mode
enables correctly. But I can't save any *.go
files because when I'm trying to save *.go
files I'm getting an error in the minibuffer that says
gofmt
program not found.
Golang installed (version 1.3), gofmt
works from terminal.
How can I solve this problem?
Thank you.
Make sure you have gofmt in your PATH. (echo $PATH) to check, if you can't run gofmt in your shell, it is likely that emacs won't as well.
gofmt on my setup is in $GOBIN/gofmt, but I think it can be as well be in one of the $GOPATH/bin.
If you have it in your path, chances are that you have an emacs configuration that sets the path. Change as needed.
If you installed via a packet manager, chances are that gofmt will be somewhere else. (I think brew puts it in /usr/local/bin)
Small tip when this happen and you really need to save: switch back to text-mode (M-x text-mode
).
On OSX I'm usingthe following in .emacs/init.el
(use-package exec-path-from-shell
:ensure t
:init (exec-path-from-shell-initialize))
to insure that Emacs are using the correct path.