doutuan6158 2014-10-15 10:02
浏览 32

从emacs调用时,goimports的行为有所不同

I'm observing a puzzling behaviour of the goimports command called from emacs. I'm using the svgo go package, and a minimal program example in the doc imports "github.com/ajstarks/svgo"

The code works fine. The goimports command is a "Tool to fix (add, remove) your Go imports automatically". Since the "github.com/ajstarks/svgo" is needed, I don't expect goimports to remove it. And it's true when I call it from the terminal:

$ head gg.go 

package main

import (
    "os"
    "github.com/ajstarks/svgo"
)


func main() {

then:

$ goimports gg.go | head

package main

import (
    "os"

    "github.com/ajstarks/svgo"
)

func main() {

as expected, it just rearranged the imports following the "first the standard library, then the external packages". Now the funny part: when I call goimports from emacs, it deletes the "github.com/ajstarks/svgo" line! (and the program no longer compiles).

Here's (the relevant part of) my .init file:

(setq exec-path (cons "/usr/local/go/bin" exec-path))
(add-to-list 'exec-path "~/go/bin")

(defun my-go-mode-hook ()
  (setq gofmt-command "goimports")  ; Use goimports instead of go-fmt
  (add-hook 'before-save-hook 'gofmt-before-save))

(add-hook 'go-mode-hook 'my-go-mode-hook)

If I comment the (setq gofmt-command "goimports") line, the svgo import doesn't get deleted.

How's this possible?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改