简体   繁体   English

在emacs中使用不同的软件包存储库

[英]use different package repository in emacs

I have a .emacs file in which I use package-install to automatically install needed packages from a repository at initialization. 我有一个.emacs文件,在其中使用package-install在初始化时自动从存储库中安装所需的软件包。 Up to now, I was using the http://melpa.milkbox.net/packages/ repository, which I got from an online tutorial. 到目前为止,我正在使用http://melpa.milkbox.net/packages/存储库,该存储库是从在线教程中获得的。 At some point, I tried to install the auctex package and got an error message which told me the package was not available under that repository. 在某个时候,我尝试安装auctex软件包,并收到一条错误消息,告诉我该软件包在该存储库中不可用。 I checked and it is true. 我检查了,这是真的。 I found out the the auctex package is available under the GNU repository: http://elpa.gnu.org/packages/ instead. 我发现auctex在GNU存储库下找到: http://elpa.gnu.org/packages/ : http://elpa.gnu.org/packages/

What I tried to do is the following: add a second package repository (GNU ELPA in this case) to my .emacs file from which package-install can feed if it needs to install packages not available under the first repository (MELPA). 我试图做的是以下操作:将第二个软件包存储库(在这种情况下为GNU ELPA)添加到我的.emacs文件中,如果它需要安装第一个存储库(MELPA)下不可用的软件包,则可以从package-install中获取数据。

I am not an expert (in fact, I am a pure beginner) in Elisp and I browsed various threads to find a solution. 我不是Elisp的专家(实际上,我是纯粹的初学者),并且浏览了各种主题以找到解决方案。 Here is my actual code: 这是我的实际代码:

(package-initialize)

(require 'package)

(add-to-list 'package-archives
             '(("melpa" . "http://melpa.milkbox.net/packages/")
               ("gnu" . "http://elpa.gnu.org/packages/")) t)

(package-refresh-contents)

(dolist (package '(use-package))
  (unless (package-installed-p package)
           (package-install package)))

(use-package paredit :ensure t)

(dolist (package '(auctex         ; <-- Not available under MELPA!
                   auto-complete
                   auto-complete-c-headers
                   magit
                   sr-speedbar
                   yasnippet
                   ))

  (unless (package-installed-p package)
    (package-install package))
     (require package))

With this code in my .emacs file, when I boot emacs up, my configurations are ignored. 在我的.emacs文件中使用此代码后,当我启动emacs时,将忽略我的配置。 I get this error message: error: Required feature 'auctex' was not provided . 我收到此错误消息: error: Required feature 'auctex' was not provided

How can I modify my code to see the auctex package from GNU ELPA? 如何修改我的代码以查看来自GNU ELPA的auctex软件包?

For your information, I use Ubuntu 16.04 with GNU Emacs 24.5.1. 供您参考,我将Ubuntu 16.04与GNU Emacs 24.5.1一起使用。


EDIT: Just to add a few words on what Stefan proposed: there were several problems with my code and splitting my add-to-list 'package-archives ...) in two calls did not seem, to work (although it is the right thing to do, of course). 编辑:只是在Stefan的建议上增加了几句话:我的代码存在一些问题,并且在两次调用add-to-list 'package-archives ...)我的add-to-list 'package-archives ...)分割开了,似乎没有用(尽管它是当然,正确的做法)。 This was due to my (require package ) line was trying to do: (require auctex) at some point. 这是由于我的(require package )行试图这样做: (require auctex)在某个时候。 See this post to see why that is a problem. 看到这篇文章 ,看看为什么这是一个问题。

I read on the fact that (require 'package-name) is not needed after package installation. 我读过一个事实,即在安装软件包之后(require 'package-name) This post explains why. 这篇文章解释了为什么。 removing this line made sure that auctex was loaded correctly, because it was automatically loaded. 删除此行可确保auctex已正确加载,因为它已自动加载。

From then on, everything worked fine, no more errors or warnings. 从那时起,一切正常,不再出现错误或警告。 I then tried to remove my lines: 然后,我尝试删除行:

(add-to-list 'package-archives
             '("gnu" . "http://elpa.gnu.org/packages/"))

and auctex package was still loaded correctly. 并且auctex软件包仍然正确加载。

Your 你的

(add-to-list 'package-archives
             '(("melpa" . "http://melpa.milkbox.net/packages/")
               ("gnu" . "http://elpa.gnu.org/packages/")) t)

doesn't add 2 entries to the list: add-to-list only adds a single element to a list. 不会在列表中添加2个条目:“ add-to-list仅将单个元素添加到列表中。 In this case it will add the element (("melpa" . "http://melpa.milkbox.net/packages/") ("gnu" . "http://elpa.gnu.org/packages/")) which is not a valid element. 在这种情况下,它将添加元素(("melpa" . "http://melpa.milkbox.net/packages/") ("gnu" . "http://elpa.gnu.org/packages/"))这不是有效的元素。

You'd want 你想要

(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives
             '("gnu" . "http://elpa.gnu.org/packages/"))

But note that the second add-to-list should be redundant because package-archives by default contains ("gnu" . "http://elpa.gnu.org/packages/") already. 但是请注意,第二个add-to-list应该是多余的,因为默认情况下, package-archives已经包含("gnu" . "http://elpa.gnu.org/packages/")

One more thing: you should not need to require those packages after installing them (like you do on the last line of your code), because the packages should come with enough autoloads to make such require unneeded (and harmful in the sense that it will slowdown your startup). 还有一两件事:你不应该需要require这些软件包安装它们(像你做你的代码的最后一行)之后,由于包应该有足够的自动加载,使这种require不需要(并且在这个意义上有害的,它会降低启动速度)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM