自动加载如何工作?
How autoload works?
假设我在一个包中有 3 个函数:
;;;###autoload
(defun my-funcA () ...)
;;;###autoload
(defun my-funcB () ...)
;;;###autoload
(defun my-func-init () ...)
如果调用其中一个函数,是否会加载所有函数声明?
换句话说,如果必须加载 my-func-init
才能使用此包,是否意味着所有 autoload
都是多余的?
就其本身而言,这些评论只是评论。
一个单独的过程用于将关联的定义提取到一个 loaddefs.el 文件中。加载该文件时,将定义所有这些自动加载。因此,许多库的所有自动加载都可以捆绑到一个文件中,加载速度很快。
M-x elisp-index-search
RET autoload cookie
RET
A magic autoload comment (often called an "autoload cookie")
consists of ‘;;;###autoload’, on a line by itself, just before the
real definition of the function in its autoloadable source file.
The command ‘M-x update-file-autoloads’ writes a corresponding
‘autoload’ call into ‘loaddefs.el’. (The string that serves as the
autoload cookie and the name of the file generated by
‘update-file-autoloads’ can be changed from the above defaults, see
below.) Building Emacs loads ‘loaddefs.el’ and thus calls
‘autoload’. ‘M-x update-directory-autoloads’ is even more powerful;
it updates autoloads for all files in the current directory.
包管理器处理任何给定包的自动加载 cookie,因此包作者可以根据需要简单地添加这些评论。
假设我在一个包中有 3 个函数:
;;;###autoload
(defun my-funcA () ...)
;;;###autoload
(defun my-funcB () ...)
;;;###autoload
(defun my-func-init () ...)
如果调用其中一个函数,是否会加载所有函数声明?
换句话说,如果必须加载 my-func-init
才能使用此包,是否意味着所有 autoload
都是多余的?
就其本身而言,这些评论只是评论。
一个单独的过程用于将关联的定义提取到一个 loaddefs.el 文件中。加载该文件时,将定义所有这些自动加载。因此,许多库的所有自动加载都可以捆绑到一个文件中,加载速度很快。
M-x elisp-index-search
RET autoload cookie
RET
A magic autoload comment (often called an "autoload cookie") consists of ‘;;;###autoload’, on a line by itself, just before the real definition of the function in its autoloadable source file. The command ‘M-x update-file-autoloads’ writes a corresponding ‘autoload’ call into ‘loaddefs.el’. (The string that serves as the autoload cookie and the name of the file generated by ‘update-file-autoloads’ can be changed from the above defaults, see below.) Building Emacs loads ‘loaddefs.el’ and thus calls ‘autoload’. ‘M-x update-directory-autoloads’ is even more powerful; it updates autoloads for all files in the current directory.
包管理器处理任何给定包的自动加载 cookie,因此包作者可以根据需要简单地添加这些评论。