emacs23/elisp:如何正确自动加载这个库? [英] emacs23 / elisp: how to properly autoload this library?
问题描述
我正在升级到 emacs23.我发现我的 emacs.el 加载速度要慢得多.
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.
所以我也试图自动加载我的 emacs.el 当前需要"的所有可能的东西.
So I am also trying to autoload everything possible that is currently "required" by my emacs.el.
我有一个公开 12 个入口点的模块 - 我可以调用的交互函数.
I have a module that exposes 12 entry points - interactive functions I can call.
对 autoload
进行 12 次调用以确保无论我调用哪个函数都加载模块是正确的方法吗?这种方法有什么问题吗?它会出现性能问题吗?
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?
推荐答案
您真正想要的是自动为您生成自动加载,以便您的 .emacs 文件保持原始状态.大多数包中已经包含 ;;;###autoload
行,如果没有,您可以轻松添加它们.
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.
为了管理这个,你可以把所有的包放在一个目录中,比如~/emacs/lisp
,在那里有一个名为update-auto-loads.el
的文件代码>,其中包含:
To manage this, you can put all the packages in a directory, say ~/emacs/lisp
, and in there have a file named update-auto-loads.el
which contains:
;; put this path into the load-path automatically
;;;###autoload
(progn
(setq load-path (cons (file-name-directory load-file-name) load-path)))
;;;###autoload
(defun update-autoloads-in-package-area (&optional file)
"Update autoloads for files in the diretory containing this file."
(interactive)
(let ((base (file-truename
(file-name-directory
(symbol-file 'update-autoloads-in-package-area 'defun)))))
(require 'autoload) ;ironic, i know
(let ((generated-autoload-file (concat base "loaddefs.el")))
(when (not (file-exists-p generated-autoload-file))
(with-current-buffer (find-file-noselect generated-autoload-file)
(insert ";;") ;; create the file with non-zero size to appease autoload
(save-buffer)))
(cd base)
(if file
(update-file-autoloads file)
(update-autoloads-from-directories base)))))
;;;###autoload
(defun update-autoloads-for-file-in-package-area (file)
(interactive "f")
(update-autoloads-in-package-area file))
如果您将 'update-autoloads-in-package-area
添加到您的 kill-emacs-hook
,则 loaddefs.el
每次退出 Emacs 时都会自动更新.
If you add 'update-autoloads-in-package-area
to your kill-emacs-hook
, then the loaddefs.el
will automatically be updated every time you exit Emacs.
并且,为了将它们联系在一起,将其添加到您的 .emacs
中:
And, to tie it all together, add this to your .emacs
:
(load-file "~/emacs/lisp/loaddefs.el")
现在,当你下载一个新的包时,只需将它保存在 ~/emacs/lisp
目录中,通过 Mx update-autoloads-in-package-area更新加载定义code>(或退出 emacs),下次运行 Emacs 时它就可用了.无需再更改
.emacs
以加载内容.
Now, when you download a new package, just save it in the ~/emacs/lisp
directory, update the loaddefs via M-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.
有关加速 Emacs 启动的其他替代方案,请参阅此问题:如何我可以让 Emacs 启动得更快吗?
See this question for other alternatives to speeding up Emacs startup: How can I make Emacs start-up faster?
这篇关于emacs23/elisp:如何正确自动加载这个库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!