53

I am using prelude as a base Emacs configuration. I have installed lots of packages from the package manager, and I want to use my settings on another machine.

I don't want to carry the installed packages and also I don't want to create a list manually.

What is the way of saving a list all the installed packages into prelude-package.el or any other file so that when I take this configuration to my other machine, they automatically get installed there on first use?

4

4 回答 4

72

您可以从变量中获取当前安装的包(不包括内置包)的列表package-activated-list。要在启动时自动安装它们,请参阅这个问题:如何通过指定包名称列表来自动安装 emacs 包?

更具体地说,如果你这样做C-h v package-activated-list,复制显示的值,并将其作为 的值插入prelude-packages,emacs 将自动确保在启动时安装这些包。

于 2012-12-13T19:29:15.127 回答
17

规范方法是最好的(由 ataylor 描述)。这是一个更笨拙的方法。

M-x list-packages. C-s installed直到你找到安装包的第一行。开始选择C-SPC。向下直到你到达内置包。用 复制M-wC-x b用于新缓冲区。用 粘贴C-yC-x C-s保存文件。

我看到的唯一优点是这更具描述性。显示您的包裹的简短描述。当您安装一些软件包并忘记它时很有用。

于 2014-04-03T04:57:54.577 回答
5

正如在如何通过指定包名称列表来自动安装 emacs 包中提到的那样?,最好也记录下你需要的包的版本。为此,您可以使用以下功能:

(defun list-packages-and-versions ()
  "Returns a list of all installed packages and their versions"
  (mapcar
   (lambda (pkg)
     `(,pkg ,(package-desc-version
                (cadr (assq pkg package-alist)))))
   package-activated-list))

这会给你一个(NAME VERSION)配对列表。不幸的是,我还没有找到安装特定版本软件包的方法。它似乎package.el总是抓住最新的可用。我现在正在做的是:

(defun install-packages-with-specific-versions (package-version-list)
  "Install the packages in the given list with specific versions.
PACKAGE-VERSION-LIST should be a list of (NAME VERSION) lists,
where NAME is a symbol identifying the package and VERSION is
the minimum version to install."
  (package-download-transaction
   (package-compute-transaction () package-version-list)))

我编写了一个更长的函数来安装与确切版本号匹配的包,但它失败了,因为package.el默认情况下只检索每个包可用的最新版本。要旨

于 2016-10-04T15:01:33.167 回答
1

如上所述,使用 emacs 普通模式。这是另一种邪恶模式的做法:

Mx 列表包;/installed(它们将被突出显示);v(视觉模式);j(选择它们);y(复制它们);打开一个新的缓冲区并粘贴它们。

于 2019-09-15T11:55:40.700 回答