这个问题已经在这里有了答案:
已关闭8年。
Possible Duplicate:
Emacs 24 Package System Initialization Problems
我正在使用Emacs24。我添加了ELPA和Marmalade仓库。使用“包”,我安装了“自动完成”。我在init.el中添加了以下几行:
(require 'auto-complete-config)
(ac-config-default)
当我启动Emacs时,出现错误
File error: Cannot open load file, auto-complete-config
但是后来我用
M-x load-file
并加载相同的〜/.emacs.d/init.el文件,然后按提示进行正常工作
Loading /home/user/.emacs.d/init.el (source)...done
通常的加载与“M-x加载文件”命令有何不同?在init.el文件的开头,我执行以下操作,这会以某种方式影响程序包的加载。
(add-to-list 'load-path "~/.emacs.d")
(load "custom_code")
最佳答案
如下面的评论中所述:phils对duplicate question的回答可能比这个更有用
这几乎可以肯定意味着您的init.el
文件在对package.el
软件包进行分类的代码之前开始运行。后面的代码将带有自动完成库的目录添加到您的加载路径。
我仍在使用ELPA,而不是package.el。使用elpa时,有一个看起来像这样的代码段,它安装在.emacs
的底部。
;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
就像评论所建议的那样,您可能希望将等效的
package.el
初始化代码放在加载init.el
的东西之前。最后:我注意到您提到将
.emacs.d
添加到load-path
。 Emacs的加载路径不是递归的,因此可能无法满足您的需要(假设您的库位于子目录中)。多年前,我编写了此代码片段,以加载我编写的各种elisp代码库。您可能会发现它很有用。 (显然,它只能在带有shell和find命令的unixy系统上工作。它相当慢,但这似乎是shell-command-to-string
,即使运行“echo hello”之类也要花费几毫秒的时间)(defun find-elisp-dirs (dir)
"Find all directories below DIR containing elisp sources, ignoring those"
(split-string
(shell-command-to-string
(format "find %s -iname '*.el' -printf '%%h\\n' | sort -u"
(expand-file-name dir t)))))
关于emacs - 加载通过Emacs24中的 'package.el'安装的软件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12053598/