首页 > 解决方案 > 在 go-mode emacs 会话中找不到 Godef

问题描述

我通过安装 godef

go get github.com/rogpeppe/godef

我安装了 emacs go-mode,并在我的 .bashrc 中导出了以下内容:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

godef 在这个意义上被发现

godef -h # appears to work.

如:

$ godef -h
usage: godef [flags] [expr]
  -A    print all type and members information
  -a    print public type and member information
  -acme
        use current acme window
  -debug
        debug mode
  -f string
        Go source filename
  -i    read file from stdin
  -json
        output location in JSON format (-t flag is ignored)
  -o int
        file offset of identifier in stdin (default -1)
  -t    print type information

当我C-c C-d在我的 emacs 会话中运行一个文件时,它应该调用一个godef-describe函数

https://github.com/dominikh/go-mode.el

我预计:

Integration with godef

    godef-describe (C-c C-d) to describe expressions
    godef-jump (C-c C-j) and godef-jump-other-window (C-x 4 C-c C-j) to jump to declarations
    This requires you to install godef via go get github.com/rogpeppe/godef.

酷,一切就绪。但是当我尝试在 go 文件中使用 Cc Cd 时,我得到:

Could not run godef binary

我可以在命令行上运行它,它看起来定义正确。发生了什么?

我发现:

M-x godoc

// then
godoc: OSReadDir // for example

生产

godoc: /bin/bash: go: command not found

这向我表明,即使 godef 和 godoc 在普通 shell 中找到,emacs 中可能存在一些路径问题?我该如何检查或修复?

标签: goemacs

解决方案


又是这个:

https://askubuntu.com/questions/1045712/emacs-launched-from-favorites-doesnt-read-bashrc

如果从 Ubuntu 启动器启动 emacs,它不会加载 .bashrc。

你必须打开一个终端,然后打电话

$ emacs

弹出的 emacs 将从你的 shell 继承你的 .bashrc。


推荐阅读