简体   繁体   中英

Emacs can't find gofmt in go-mode

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.

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.

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 ( Mx text-mode ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM