请教各位emacs-startup-hook的正确使用方式

大家好,我正在研究 Doom 的配置来自己从零攒一个配置。

但是在我读到常见的 file-name-handler-alist 设为 nil 的启动优化的时候产生了一个疑问:为何 Doom 要将在启动后恢复其值的函数 hook 到 emacs-startup-hook 而不是 after-init-hook

我看 Emacs 文档写到 emacs-startup-hook 是:

This normal hook is run, once, just after handling the command line arguments. In batch mode, Emacs does not run this hook.

另外鉴于 emacs-startup-hook 在整个 Doom 中只在该处出现,我只能推测 Doom 的作者有意希望 file-name-handler-alist 在 Batch Mode 中值为 nil ,但是我完全不理解为什么要这样做。

本质上我不理解在什么场景需要使用 emacs-startup-hook,直觉上好像大部分情况都应该只使用 after-init-hook

感谢!

1 个赞

看官方文档https://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html#Startup-Summary

emacs-startup-hook在after-init-hook之后才执行。 我觉得Doom作者可能是想要在after-init-hook之后再恢复file-name-handler-alist

1 个赞