emacs23 / elisp:如何正确自动加载这个库?
我正在升级到 emacs23。我发现我的 emacs.el 加载速度慢得多。
确实是我自己的错...我里面有很多东西。
因此,我也尝试自动加载 emacs.el 当前“需要”的所有可能内容。
我有一个公开 12 个入口点的模块 - 我可以调用的交互式函数。
为了确保无论我调用哪个函数都加载模块,正确的方法是调用 12 次 autoload
吗?这种方法有什么问题吗?它会带来性能问题吗?
如果不是那种方法,那么又会怎样呢?
I am upgrading to emacs23. I find that my emacs.el loads much more slowly.
It's my own fault really... I have a lot of stuff in there.
So I am also trying to autoload everything possible that is currently "required" by my emacs.el.
I have a module that exposes 12 entry points - interactive functions I can call.
Is the correct approach to have 12 calls to autoload
in order to insure that the module is loaded regardless of which function I call? Are there any problems with this approach? Will it present performance issues?
If not that approach, then what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您真正想要的是自动为您生成自动加载,以便您的 .emacs 文件保持原始状态。大多数包中已经有
;;;###autoload
行,如果没有,您可以轻松添加它们。要管理它,您可以将所有包放在一个目录中,例如
~/emacs/lisp
,其中有一个名为update-auto-loads.el
的文件包含:如果将
'update-autoloads-in-package-area
添加到kill-emacs-hook
中,则loaddefs.el
将每次退出 Emacs 时都会自动更新。并且,为了将它们结合在一起,请将其添加到您的
.emacs
中:现在,当您下载新包时,只需将其保存在
~/emacs/lisp
目录中,通过 Mx update-autoloads-in-package-area 更新 loaddef(或退出 emacs),下次运行 Emacs 时即可使用。无需再更改.emacs
来加载内容。请参阅此问题以了解加速 Emacs 启动的其他替代方法: How can I make Emacs 启动速度更快?
What you really want is to get the autoloads generated for you automatically, so that your .emacs file remains pristine. Most packages have the
;;;###autoload
lines in them already, and if not, you can easily add them.To manage this, you can put all the packages in a directory, say
~/emacs/lisp
, and in there have a file namedupdate-auto-loads.el
which contains:If you add
'update-autoloads-in-package-area
to yourkill-emacs-hook
, then theloaddefs.el
will automatically be updated every time you exit Emacs.And, to tie it all together, add this to your
.emacs
:Now, when you download a new package, just save it in the
~/emacs/lisp
directory, update the loaddefs viaM-x update-autoloads-in-package-area
(or exit emacs), and it'll be available the next time you run Emacs. No more changes to your.emacs
to load things.See this question for other alternatives to speeding up Emacs startup: How can I make Emacs start-up faster?
好吧,谁在乎它开始得有多慢呢?
之一进行连接
emacs --daemon &
启动它,然后使用emacsclient -c /some/file.ext
或emacsclient -nw
code>我分别为它们创建了别名
emx
和emt
。继续一次编辑会话变得更加理智......Well, who cares how slowly it starts?
Fire it up via
emacs --daemon &
and then connect using either one ofemacsclient -c /some/file.ext
, oremacsclient -nw
I created aliases for both these as
emx
andemt
, respectively. Continuing once editing session is so much saner...理想情况下,您的
.emacs
文件中不应该有任何load
或require
。您应该使用
autoload
。 .例如,
您将需要使用
eval-after-load
来执行任何特定于库的配置,但结果是您不需要等待所有这些预先加载,或者在不具有相同功能的 Emacs 版本上导致错误。 (例如基于终端,或不同的平台等)虽然这现在可能不会影响您,但将来您可能会希望在使用 Emacs 的所有计算机/环境上使用相同的配置,所以这是一件非常好的事情让您的配置准备好飞行。
还可以使用
(start-server)
并使用emacsclient 将外部文件打开到 Emacs
- 这样就可以避免重新启动 Emacs。Ideally you shouldn't have any
load
orrequire
in your.emacs
file.You should be using
autoload
instead...e.g.
You will need to use
eval-after-load
to do any library specific config, but the upshot is that you won't need to wait for all this to load up front, or cause errors on versions of Emacs that don't have the same functionality. (e.g. Terminal based, or a different platform etc.)While this may not affect you right now, chances are, in future you will want to use the same config on all machines / environments where you use Emacs, so it's a very good thing to have your config ready to fly.
Also use
(start-server)
and open external files into Emacs usingemacsclient
- So you avoid restarting Emacs.