Emacs: 无法打开加载文件,go-autocomplete

huangapple go评论75阅读模式
英文:

Emacs: Cannot open load file, go-autocomplete

问题

我正在尝试在Emacs上安装gocode,但是收到了以下错误消息:

警告(初始化):加载`/home/darwin/.emacs'时发生错误:

文件错误:无法打开加载文件,没有这样的文件或目录,go-autocomplete

为了确保正常运行,您应该调查并删除初始化文件中的错误原因。使用`--debug-init'选项启动Emacs以查看完整的错误回溯。

当我使用--debug-init运行Emacs时,我收到了以下消息(不太美观):

调试器进入- Lisp错误:(文件错误“无法打开加载文件”“没有这样的文件或目录”“go-autocomplete”)
  require(go-autocomplete)
  eval-buffer(#<buffer  *load*> nil "/home/darwin/.emacs" nil t)  ; 在缓冲区位置1831处读取
  load-with-code-conversion("/home/darwin/.emacs" "/home/darwin/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "52�	6=3�70Q2;�	1=4�72Q2;�3745#3*�62;�3747#3:�0\nB12;�62321#02=3a�45677Q!\"321#02=3`�033�0!1233�2!13P4!3}�120�4!37�20�4231�5\&quot;37�67#001!06\f?50�43221#)27" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" (initialization "`_emacs' init file is deprecated, please use `.emacs'") "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7 "\n\n(fn)"]()
  command-line()
  normal-top-level()

我已经使用软件包管理器安装了Emacs(常规)自动完成版本,该版本是gocode所需的(顺便说一句,该管理器上没有gocode可用)。

如果有帮助的话,这是我的目录结构:
Emacs文件夹名为:.emacs.d

/.emacs.d
  /auto-save-list
  /elpa
  go-autocomplete.el

Emacs初始化文件夹:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes (quote (misterioso)))
 '(inhibit-startup-screen t))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
(when (>= emacs-major-version 24)
  (require 'package)
  (package-initialize)
 ; (add-to-list 'package-archives
					;	       '("melpa-stable" . "http://stable.melpa.org/packages/") t)
  (add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
  (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
  (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
  )


;; Update Emacs config for godoc
(setenv "PATH" "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin")
(setenv "GOPATH" "~/go")

;; calls gofmt before save
(setq exec-path (cons "/usr/local/go/bin" exec-path))
(add-to-list 'exec-path "/go/bin")
;(add-hook 'before-save-hook 'gofmt-before-save)
(defun my-go-mode-hook ()
  ; Call Gofmt before saving
  (add-hook 'before-save-hook 'gofmt-before-save)
  ; Customize compile command to run go build
  (if (not (string-match "go" compile-command))
      (set (make-local-variable 'compile-command)
           "go build -v && go test -v && go vet"))
  ; Godef jump key binding
  (local-set-key (kbd "M-.") 'godef-jump))
(add-hook 'go-mode-hook 'my-go-mode-hook)

;; Gocode: Go aware Autocomplete
(require 'go-autocomplete)
(require 'auto-complete-config)
;; Go eldoc (via package control) REQUIRES GOCODE
(require 'go-eldoc)
(add-hook 'go-mode-hook 'go-eldoc-setup)

如果有人能帮助我解决如何让gocode工作,那将非常棒。提前谢谢您的帮助。

附注:如果需要,我可以添加其他目录。

英文:

I'm trying to install gocode on Emacs currently and am receiving the current error message:

Warning (initialization): An error occurred while loading `/home/darwin/.emacs&#39;:

File error: Cannot open load file, no such file or directory, go-autocomplete

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init&#39; option to view a complete error backtrace.

And when I run Emacs with --debug-init, I receive this (it's not too pretty):

Debugger entered--Lisp error: (file-error &quot;Cannot open load file&quot; &quot;no such file or directory&quot; &quot;go-autocomplete&quot;)
  require(go-autocomplete)
  eval-buffer(#&lt;buffer  *load*&gt; nil &quot;/home/darwin/.emacs&quot; nil t)  ; Reading at buffer position 1831
  load-with-code-conversion(&quot;/home/darwin/.emacs&quot; &quot;/home/darwin/.emacs&quot; t t)
  load(&quot;~/.emacs&quot; t t)
  #[0 &quot;52�	6=3�70Q2;�	1=4�72Q2;�3745#3*�62;�3747#3:�0\nB12;�62321#02=3a�45677Q!\&quot;321#02=3`�033�0!1233�2!13P4!3}�120�4!37�20�4231�5\&quot;37�67#001!06\f?50�43221#)27&quot; [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos &quot;~&quot; &quot;/_emacs&quot; windows-nt &quot;/.emacs&quot; directory-files nil &quot;^\\.emacs\\(\\.elc?\\)?$&quot; &quot;~/.emacs&quot; &quot;^_emacs\\(\\.elc?\\)?$&quot; (initialization &quot;`_emacs&#39; init file is deprecated, please use `.emacs&#39;&quot;) &quot;~/_emacs&quot; t load expand-file-name &quot;init&quot; file-name-as-directory &quot;/.emacs.d&quot; file-name-extension &quot;elc&quot; file-name-sans-extension &quot;.el&quot; file-exists-p file-newer-than-file-p message &quot;Warning: %s is newer than %s&quot; sit-for 1 &quot;default&quot;] 7 &quot;\n\n(fn)&quot;]()
  command-line()
  normal-top-level()

I've installed the Emacs (regular) autocomplete version required for gocode using the package manager (gocode isn't available on this manager by the way).

My directories if they help:
Emacs folder is called: .emacs.d:

/.emacs.d
  /auto-save-list
  /elpa
  go-autocomplete.el

Emacs init folder:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won&#39;t work right.
 &#39;(custom-enabled-themes (quote (misterioso)))
 &#39;(inhibit-startup-screen t))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won&#39;t work right.
 )
(when (&gt;= emacs-major-version 24)
  (require &#39;package)
  (package-initialize)
 ; (add-to-list &#39;package-archives
					;	       &#39;(&quot;melpa-stable&quot; . &quot;http://stable.melpa.org/packages/&quot;) t)
  (add-to-list &#39;package-archives &#39;(&quot;marmalade&quot; . &quot;https://marmalade-repo.org/packages/&quot;))
  (add-to-list &#39;package-archives &#39;(&quot;melpa-stable&quot; . &quot;http://stable.melpa.org/packages/&quot;) t)
  (add-to-list &#39;package-archives &#39;(&quot;org&quot; . &quot;http://orgmode.org/elpa/&quot;) t)
  )


;; Update Emacs config for godoc
(setenv &quot;PATH&quot; &quot;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin&quot;)
(setenv &quot;GOPATH&quot; &quot;~/go&quot;)

;; calls gofmt before save
(setq exec-path (cons &quot;/usr/local/go/bin&quot; exec-path))
(add-to-list &#39;exec-path &quot;/go/bin&quot;)
;(add-hook &#39;before-save-hook &#39;gofmt-before-save)
(defun my-go-mode-hook ()
  ; Call Gofmt before saving
  (add-hook &#39;before-save-hook &#39;gofmt-before-save)
  ; Customize compile command to run go build
  (if (not (string-match &quot;go&quot; compile-command))
      (set (make-local-variable &#39;compile-command)
           &quot;go build -v &amp;&amp; go test -v &amp;&amp; go vet&quot;))
  ; Godef jump key binding
  (local-set-key (kbd &quot;M-.&quot;) &#39;godef-jump))
(add-hook &#39;go-mode-hook &#39;my-go-mode-hook)

;; Gocode: Go aware Autocomplete
(require &#39;go-autocomplete)
(require &#39;auto-complete-config)
;; Go eldoc (via package control) REQUIRES GOCODE
(require &#39;go-eldoc)
(add-hook &#39;go-mode-hook &#39;go-eldoc-setup)

If anyone could help me figure out how I can get gocode to work that would be fantastic. Thank you in advance.

P.S. I can add other directories if needed.
1: https://github.com/nsf/gocode

答案1

得分: 7

.emacs.d的根目录通常不是load-path的一部分,而且最近的Emacs版本甚至会向用户发出警告消息,不鼓励这样做。创建一个名为lisphello-world的子文件夹,将你的库放在其中,然后将lisphello-world目录添加到你的load-path中,并重新启动Emacs。这是有关load-path的相关文档链接:https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html

示例(放在.emacs文件中):

(add-to-list 'load-path "/path/to/my/lisp/library")
英文:

The root directory of .emacs.d is not generally a part of the load-path, and recent versions of Emacs will even give the user a warning message discouraging against doing it if in fact a user did it. Create a sub-folder called lisp or hello-world and put your library inside it and then add the lisp or hello-world directory to your load-path and restart Emacs. Here is a link to the related documentation for load-path:  https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html

Example (place inside .emacs file):

<!-- language: lang-lisp -->

(add-to-list &#39;load-path &quot;/path/to/my/lisp/library&quot;)

huangapple
  • 本文由 发表于 2014年12月31日 06:38:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/27713584.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定