emacs23 / elisp:如何正确自动加载这个库? [英] emacs23 / elisp: how to properly autoload this library?

查看:151
本文介绍了emacs23 / elisp:如何正确自动加载这个库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级到emacs23。我发现我的emacs.el加载速度要慢得多。



这是我自己的错,真的吗?我有很多东西在那里。



所以我也试图自动加载我的emacs.el当前需要的所有可能。



我有一个模块暴露了12个入口点 - 我可以调用的交互式功能。



正确的方法是对 autoload 进行12次调用,以确保模块加载,无论哪个功能我打电话?这种方法有什么问题吗?它会呈现性能问题吗?



如果不是那个方法,那么什么?

解决方案

您真正需要的是自动生成自动加载,以使您的.emacs文件保持原样。大多数包都已经有$ code> ;;; ### autoload 行,如果没有,你可以轻松添加它们。



要管理这个,您可以将所有包放在目录中,例如〜/ emacs / lisp ,还有一个名为 update-auto-loads.el 其中包含:

 ; ;将此路径自动放入加载路径
;;; ### autoload
(progn
(setq load-path(cons(file-name-directory load-file-name)load -path)))

;;; ### autoload
(defun update-autoloads-in-package-area(&可选文件)
更新文件的自动加载包含这个文件的目录
(interactive)
(let((base(file-truename)
(file-name-directory
(symbol-file'update-autoloads -in-package-area'defun)))))
(require'autoload);讽刺的是,我知道
(let((generate-autoload-file(concat baseloaddefs.el)) )
(when(not(file-exist-p generated-autoload-file))
(with-current-buffer(find-file-noselect generated-autoload-file)
;;);;创建非零大小的文件以安抚自动加载
(save-buffer)))
(cd base)
(如果文件
-file-autoloads文件)
(update-autoloads-from-directories base)))))

;;; ### autoloa d
(defun update-autoloads-for-file-in-package-area(file)
(interactivef)
(update-autoloads-in-package-area file))

如果添加'update-autoloads-in-package-area 到您的 kill-emacs-hook ,则$ code> loaddefs.el 将自动每次更新你退出Emacs。



而且,将它们整合在一起,将它添加到你的 .emacs 中:

 (加载文件〜/ emacs / lisp / loaddefs.el)

现在,当您下载新软件包时,只需将其保存在〜/ emacs / lisp 目录,通过 Mx update-autoloads-in-package-area (或退出emacs)更新loaddefs,下次你可以使用运行Emacs。没有更改您的 .emacs 来加载东西。



看到这个问题,为加快Emacs启动的其他选择:如何使Emacs启动更快? / p>

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?

解决方案

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 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))

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.

And, to tie it all together, add this to your .emacs:

(load-file "~/emacs/lisp/loaddefs.el")

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.

See this question for other alternatives to speeding up Emacs startup: How can I make Emacs start-up faster?

这篇关于emacs23 / elisp:如何正确自动加载这个库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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