错误:package.el尚未初始化。

12

我正在整理我的.emacs文件,以更好地跟踪我添加到其中的所有内容。

在这样做的过程中,我遇到了标题中描述的错误,而且我不确定究竟是为什么。

这是我的.emacs文件:(大量注释只是为了方便自己参考)

;;;; Emacs config file

;; convenience function for loading multiple libs in a single call
(defun load-libs (&rest libs) 
  (dolist (lib libs) 
    (load-library lib)))

;; path to custom libraries as well as the libraries themselves
(add-to-list 'load-path "~/.emacs.d/lisp/")
(load-libs "convenience" "editor-behaviour")

;; Add support for the package manager
(require 'package)
;; Add various package archives
(add-to-list 'package-archives
         '("marmalade" . "http://marmalade-repo.org/packages/")
         '("melpa" . "http://melpa.milkbox.net/packages/"))

;; Installs packages if they aren't already
(package-refresh-and-install        ; from convenience.el
 'scala-mode2 'sbt-mode 'haskell-mode 'geiser 'auto-complete 'ac-geiser 'cider)

;; Initialise packages
(package-initialize)

;; libs dependent on the packages being initialized go here
(load-library "autocomplete-config")

;; Enable Haskell indentation
(custom-set-variables 
 '(haskell-mode-hook '(turn-on-haskell-indentation)))

运行emacs .emacs --debug-init命令后,我得到以下输出:
Debugger entered--Lisp error: (error "package.el is not yet initialized!")
  signal(error ("package.el is not yet initialized!"))
  error("package.el is not yet initialized!")
  package-installed-p(scala-mode2)
  (if (package-installed-p pkg) nil (package-refresh-contents) (package-install pkg))
  (while --dolist-tail-- (setq pkg (car --dolist-tail--)) (if (package-installed-p pkg) $
  (let ((--dolist-tail-- pkgs) pkg) (while --dolist-tail-- (setq pkg (car --dolist-tail-$
  package-refresh-and-install(scala-mode2 sbt-mode haskell-mode geiser auto-complete ac-$
  eval-buffer(#<buffer  *load*> nil "/Users/ElectricCoffee/.emacs" nil t)  ; Reading at $
  load-with-code-conversion("/Users/ElectricCoffee/.emacs" "/Users/ElectricCoffee/.emacs$
  load("~/.emacs" t t)
  #[0 "^H\205\262^@     \306=\203^Q^@\307^H\310Q\202;^@ \311=\204^^^@\307^H\312Q\202;^@\$
  command-line()
  normal-top-level()

这似乎(据我理解)与convenience.el有关,但那里面只有这些内容:

(defun package-refresh-and-install (&rest pkgs)
  "Utility function to refresh package contents and install several packages at once"
  (dolist (pkg pkgs)
    (unless (package-installed-p pkg)
      (package-refresh-contents)
      (package-install pkg))))

我不确定我在哪里出现了错误... 有人可以帮忙吗?

1个回答

17

在调用 package-refresh-and-install 之前,您需要先调用 package-initialize


package-initialize的整个目的不就是初始化我们刚刚安装的包吗? - Electric Coffee
4
除其他事项外,package-initialize 还填充了已安装软件包的列表,因此在调用 package-installed-p 之前显然需要先调用它。 - user355252

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接