在emacs中使用autoload卸载定义的目的是什么?为什么不自动加载缓慢? [英] What is the purpose of off-loading definitions with autoload in emacs? Why not autoloading is slow?

查看:140
本文介绍了在emacs中使用autoload卸载定义的目的是什么?为什么不自动加载缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ELisp中,您可以使用autoload cookie跳过定义的评估。定义仅在使用时进行评估。

In ELisp, you can skip the evaluation of a definition with the autoload cookie. The definition is evaluated only once it's used.

;; File foo.el

;;;###autoload
(defun foo ()
  "Doc"
  42)

(defun bar ()
  "Doc"
  43)

所以, >如果我理解正确,自动加载功能是一个加载文件更快的黑客。但是当我加载 foo.el 时,为了跳过foo的定义,解释器仍然必须读取整个表单。我不明白为什么它更快。

So, if I understand correctly the autoload functionnality is a hack to load file faster. But when I load foo.el, in order to skip the definition of foo the interpreter still has to read the whole form. I don't understand why it's faster.

推荐答案

加载文件内容的最简单的方法 foo.el 要执行加载
但是,这是昂贵的,因为您必须阅读整个文件。

The simplest way to load the content of the file foo.el is to do a load. However, this is costly because you have to read the whole file.

使用 autoload 允许告诉emacs:函数 foo 在文件 foo.el 中定义。
这样emacs不会读取该文件,您不支付加载价格。当您第一次使用函数 foo 时,emacs将通过阅读 foo.el 找到您的定义。

With autoload you are allowed to tell emacs: "function foo is defined in file foo.el". This way emacs does not read the file and you do not pay the loading price. When you use the function foo for the first time, emacs will find the definition for you by reading foo.el.

您的文件中的 ;;; ### autoload 注释不会自动执行任何自动加载。
您需要使用一个可以抓取所有这些定义并将它们放入文件 foo-autoloads.el (或任何其他名称)的程序。
对于每个函数,它将放置一条告诉emacs哪个文件包含它的行。
然后在您的 .emacs 中,您将加载 foo-autoloads.el 而不是 foo.el
foo.el 将首次使用函数 foo 读取emacs。

The ;;;###autoload comment in your file is not doing anything for autoload by itself. You need to use a program that will grab all of these definitions and put them in a file foo-autoloads.el (or any other name). For each function it will put a line telling emacs which file contains it. Then in your .emacs you will load foo-autoloads.el instead of foo.el. foo.el will be read by emacs the first time you use function foo.

注意: require 也可以用来代替 load

Note: require can also be used instead of load in the explanation above.

这篇关于在emacs中使用autoload卸载定义的目的是什么?为什么不自动加载缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆