简体   繁体   English

如何让我的自定义emacs加载速度更快?

[英]How to make my customized emacs load faster?

As I add more and more plugins and configurations to my emacs' init.el , it's startup is getting more and more slow. 随着我向emacs的init.el添加越来越多的插件和配置,它的启动变得越来越慢。 Is there any way to avoid this? 有什么方法可以避免这种情况吗?

Your .emacs or init.el shouldn't have many require or load commands, it should mostly have autoload . 你的.emacsinit.el不应该有很多requireload命令,它应该主要有autoload The autoload function tells Emacs “if you ever need this function, load that file”. autoload功能告诉Emacs“如果您需要此功能,请加载该文件”。 This way, the file is only loaded when and if you actually use the function. 这样,只有在您实际使用该函数时才会加载该文件。 You only need require (or very rarely load ) in two cases: 你只需要require (或很少load )在两种情况下:

  • if there's a customization that needs to go into effect immediately (eg (require 'cl) , a color theme); 如果有需要立即生效的定制(例如(require 'cl) ,颜色主题);
  • if what you're loading is a small file that contains the autoloads and other start-up definitions of a package (eg (require 'tex-site) . 如果您要加载的是一个包含autoloads和包的其他启动定义的小文件(例如(require 'tex-site)

If you're not doing this already, calling autoload for things like mode-specific customizations can cut your startup time down significantly, because Emacs will have to load fewer files. 如果您还没有这样做,那么调用autoload以进行模式特定的自定义可以显着缩短启动时间,因为Emacs将不得不加载更少的文件。

Furthermore, make sure your files are byte-compiled; 此外,确保您的文件是字节编译的; they'll load a little faster (less CPU time). 它们的加载速度会更快(CPU时间更短)。 Call Mx emacs-lisp-byte-compile on each .el file, or Mx byte-recompile-directory (these commands are in the Emacs-Lisp menu). 在每个.el文件或Mx byte-recompile-directory上调用Mx emacs-lisp-byte-compile (这些命令在Emacs-Lisp菜单中)。

Finally, note that load times don't matter so much because you should be starting Emacs at most once per session . 最后请注意,加载时间并不重要,因为每个会话最多应该启动一次Emacs Start Emacs automatically when you log in, either with a window or in the background with the --daemon option. 登录时自动启动Emacs,使用窗口或使用--daemon选项在后台登录。 Then, to edit a file, run emacsclient . 然后,要编辑文件,请运行emacsclient You can also tell emacsclient to start Emacs if it's not running yet if you'd rather not start it when you log in. 你也可以告诉emacsclient启动Emacs,如果它还没有运行,如果你不想在登录时启动它。

您可以将其编译为.elc文件(Mx byte-compile-file)

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

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