简体   繁体   English

我无法在emacs上加载.el软件包

[英]I can't load an .el package on emacs

So I downloaded an .el file, I put it on the ~/.emacs.d/elpa/ folder, but it won't appear on the Mx list-packages . 因此,我下载了.el文件,将其放在~/.emacs.d/elpa/文件夹中,但不会出现在Mx list-packages How do I make it appear there or how can I install this file/package? 如何使它出现在这里或如何安装此文件/软件包?

There are two ways of installing an Emacs package: either type Mx list-packages and install it from the list, letting Emacs download it for you, or download the package yourself and install it with Mx package-install-file . 有两种安装Emacs软件包的方法:键入Mx list-packages并从列表中安装它,让Emacs为您下载它,或者自己下载该软件包并使用Mx package-install-file

Installing from a package archive 从软件包存档安装

In the first case, note that there are several different package archives. 在第一种情况下,请注意有几个不同的程序包档案。 The default value for the variable package-archives only contains GNU ELPA , but most people want to add MELPA to that list since it has more packages. 变量package-archives的默认值仅包含GNU ELPA ,但是大多数人都希望将MELPA添加到该列表中,因为它包含更多的软件包。 To do that, you need to add the following to your .emacs file (copied from the MELPA web page): 为此,您需要将以下内容添加到.emacs文件(从MELPA网页复制):

(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line

After that, typing Mx list-packages should list more packages than you'll ever need :) 之后,键入Mx list-packages应该列出比您需要的更多包:)

Installing from a downloaded file 从下载的文件安装

There are two types of packages: single-file packages and multi-file packages. 程序包有两种类型:单文件程序包和多文件程序包。 The former can be downloaded as a single .el file, while the latter are distributed as tarballs ( .tar ). 前者可以作为单个.el文件下载,而后者则作为tarball( .tar )分发。 Both types can be installed with Mx package-install-file . 两种类型都可以与Mx package-install-file一起Mx package-install-file

Note that not every .el file can be installed as a package. 请注意,并非每个.el文件都可以作为软件包安装。 The comments at the beginning of the file need to follow a certain convention, documented in the Simple packages node of the Emacs Lisp reference manual. 文件开头的注释需要遵循某些约定,这些约定记录在Emacs Lisp参考手册的“ 简单软件包”节点中。


That leaves the possibility that the .el file you've downloaded is not installable as a package. 这样就可能导致您下载的.el文件无法作为软件包安装。 In that case, you should put it in some other directory ( ~/.emacs.d/elpa is meant for installed packages only), add that directory to the load-path variable, and require the package. 在这种情况下,您应该将其放在其他目录中( ~/.emacs.d/elpa仅用于已安装的软件包),将该目录添加到load-path变量中,并require该软件包。 If you have foo.el and put it in ~/path/to/foo , it would look something like this: 如果您拥有foo.el并将其放在~/path/to/foo ,它将看起来像这样:

(add-to-list 'load-path "~/path/to/foo")
(require 'foo)

An .el file is not a package. .el文件不是软件包。 Installing it via ELPA is probably vastly preferrable to manually downloading a static .el file; 通过ELPA安装它可能比手动下载静态.el文件更.el perhaps the maintainer has a home page with ELPA (or Marmalade, etc) instructions. 维护者可能会在首页上看到ELPA(或果酱等)说明。

In particular, a package will receive updates as they are made available, so you will not be forever stuck on an increasingly obsolete, unmanaged version (though quiet, fully automatic updates are not yet available or feasible, AFAICT). 特别是,程序包将在更新可用时接收更新,因此您不会永远停留在日益陈旧,不受管理的版本上(尽管AFAICT尚无可用的安静,全自动更新,或尚不可行)。

But if you have to get by with just the file you already downloaded, you can put it pretty much anywhere you like, as long as that directory is included in the load-path . 但是,如果您只需要处理已经下载的文件,则可以将其放置在任意位置,只要该目录包含在load-path Manually mucking with the elpa directory is a bad idea, though; 但是,用elpa目录手动处理是个坏主意。 put it somewhere else. 放在其他地方。

Look for comments near the top of the file for any additional instructions; 在文件顶部附近查找注释,以获取其他说明; any autoloads, for example, will probably have to be configured separately, and usually completely manually. 例如,任何自动加载可能都必须分别进行配置,并且通常是完全手动配置。

This used to be how you always did things in older versions of Emacs, so you should find that the Internet is still practically bulging with guides and tutorials which explain the finer details of this mechanism, if this answer alone isn't sufficient. 这曾经是您总是在较旧版本的Emacs中执行操作的方式,因此,如果仅靠这个答案还不够的话,您应该发现Internet实际上仍在充实指导和教程的内容,这些指南和教程解释了该机制的详细信息。

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

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