关于emacs27 的 early-init.el 的使用问题?

最近在使用27.0.50的开发版的daily-building 时候发现了 emacs27可以使用early-init.el进行对于已安装的packge的初始化加载设置,原文我是在 emacs的 emacs-news 中看到的,内容如下:

  • Startup Changes in Emacs 27.1

+++

** Emacs can now be configured using an early init file. The file is called ‘early-init.el’, in ‘user-emacs-directory’. It is loaded very early in the startup process: before graphical elements such as the tool bar are initialized, and before the package manager is initialized. The primary purpose is to allow customizing how the package system is initialized given that initialization now happens before loading the regular init file (see below).

+++

** Installed packages are now activated before loading the init file. This is part of a change intended to eliminate the behavior of package.el inserting a call to ‘package-initialize’ into the init file, which was previously done when Emacs was started. As a result of this change, it is no longer necessary to call ‘package-initialize’ in your init file.

However, if your init file changes the values of ‘package-load-list’ or ‘package-user-dir’, or sets ‘package-enable-at-startup’ to nil then it won’t work right without some adjustment:

  • you can move that code to the early init file (see above), so those settings apply before Emacs tries to activate the packages.
  • you can use the new 'package-quickstart` so activation of packages does not need to pay attention to ‘package-load-list’ or ‘package-user-dir’ any more.

我习惯设置 package-user-dir 为其他自定义位置(当然我使用的绝对路径)来方便自己管理elpa包的配置。 于是我按照对原文的理解把这个设置放到了 .emacs.d/early-init.el 中,可是问题来了:

emacs启动时并没有改变其elpa包的集合位置,仍然是默认位置 .emacs.d/elpa , 这就尴尬了,因为这样一来,emacs就会重新下载所有的包,更无法加载use-package,由于我所有的包都是通过use-package来管理的,这就很不和谐了。

我想请求各位大佬帮助,这个问题怎么解决?

并且我没有使用 package-quickstart 这个把所有autoloads都写到一个文件中以便加速启动的feature。

没看明白,楼主是要加速启动吗?是的话用 27 的 dump 功能吧,应该是终极解决方案了,300~400个包启动时间可以缩短到 0.5s 左右。(我没有用,是看其它人的数据)

事实上我并不是想要加速启动,只是尝试一下这个新的feature。

另外:

请问emacs 27 的dump 可以用于gui吗? 好像我之前看论坛里的回答 说25.3的dump是不能用于gui的,只能用于终端。

还有很惭愧的就是 我之前dump从来没成功过 按照reddit的一个链接里的方式 。

27 修改了 dump 功能,GUI 也可以使用。

当然可以,推荐用 spacemacs,下面的EXPERIMENT.org 文件是详细的用法说明

@LdBeth @et2010

谢谢帮助,我看一下这个新的dump机制,对了 你们有用这个early-init.el吗(在emacs27下)

没有,没时间尝试那么多的新功能

好的,我正好这几天 win10 18030的ime让我奔溃,所以尝试一下新的版本,看一下是否修复了,结果RBL。

那个spacemacs的哪个分支有这个你引用的介绍文件呢?

develop分支

Ok TKS!:unicorn:

我看了你这个贴子之后试用了一下,将

(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

这三个挪到了 early-init.el 里速度提高了 0.2 s 左右

:sweat_smile: 零点二 哇塞 这个 。。。。。。 除非我有特异功能 不然 真感觉不出来 这种 ‘大’ 提升。

我现在整个 emacs 启动的时间也就 0.9 ~ 1.0s 左右,所以 0.2s 对我来说还是很大的提升的 :joy:

我看了那个文档,它只是涉及启动选择dump文件,并没有介绍如何dump配置(dump实在spacemacs内部完成的)?

怎么把这个dump方案转移至个人emacs配置?

你描述的问题听起来很奇怪——在 ~/.emacs.d/early-init.el 中加入

(setq package-user-dir "~/.emacs.d/elpa-27")

然后启动 Emacs 这个变量的值依旧是 ~/.emacs.d/elpa。怎么可能?估计多半是你的操作问题。

早上好 :sunny:, 谢大佬提醒 :dark_sunglasses:,我决定明天再重新查一下配置, 顺便再做一个 reproduce。