【问题标题】:Emacs: Cannot open load file, go-autocompleteEmacs:无法打开加载文件,自动完成
【发布时间】:2015-02-27 02:21:26
【问题描述】:

我目前正在尝试在 Emacs 上安装 [gocode][1] 并收到当前的错误消息:

Warning (initialization): An error occurred while loading `/home/darwin/.emacs':

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' option to view a complete error backtrace.

当我使用 --debug-init 运行 Emacs 时,我收到了这个(不太漂亮):

Debugger entered--Lisp error: (file-error "Cannot open load file" "no such file or directory" "go-autocomplete")
  require(go-autocomplete)
  eval-buffer(#<buffer  *load*> nil "/home/darwin/.emacs" nil t)  ; Reading at buffer position 1831
  load-with-code-conversion("/home/darwin/.emacs" "/home/darwin/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262�    \306=\203�\307\310Q\202;�   \311=\204�\307\312Q\202;�\313\307\314\315#\203*�\316\202;�\313\307\314\317#\203:�\320\nB\321\202;�\316\322\323\322\211#\210\322=\203a�\324\325\326\307\327Q!\"\323\322\211#\210\322=\203`�\210\203\243�\330!\331\232\203\243�\332!\211\333P\334!\203}�\211\202\210�\334!\203\207�\202\210�\314\262\203\241�\335\"\203\237�\336\337#\210\340\341!\210\266\f?\205\260�\314\323\342\322\211#)\262\207" [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()

我已经使用包管理器安装了 gocode 所需的 Emacs(常规)自动完成版本(顺便说一下,此管理器上没有 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 工作,那就太好了。提前谢谢你。

附:如果需要,我可以添加其他目录。 [1]:https://github.com/nsf/gocode

【问题讨论】:

  • 我认为@lawlist 想说的是:(1)go-autocomplete.el 不在你的load-path 中;它需要。 (2)go-autocomplete.el可以在任何地方;您只需要将其目录添加到load-path

标签: emacs autocomplete go virtualbox ubuntu-14.04


【解决方案1】:

.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")

【讨论】:

  • 我是否将文件夹放在 .emacs.d 中?还是我完全制作新文件夹?
  • Emacs 会在主目录中创建 .emacs.d 文件夹,除非您更改了它的位置。包含用户的elisp 库的lisphome-world 目录通常放在那里,尽管只要load-path 正确,它几乎可以在计算机上的任何位置。
  • Cool 错误不再出现。 Gocode 不工作,但无论如何,这解决了提出的问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-02-26
  • 1970-01-01
  • 2011-09-14
  • 2014-06-06
  • 1970-01-01
  • 2015-03-08
  • 2023-03-03
  • 1970-01-01
相关资源
最近更新 更多