Emacs:.emacs中延迟加载模式的最佳实践? [英] Emacs: Best-practice for lazy loading modes in .emacs?
问题描述
遇到相关文件扩展名时,是否有关于延迟加载模式的最佳实践?
Is there a best practice around lazily loading modes when encountering a relevant file extension?
此时,我安装了大约25种不同的Emacs模式,启动变慢了。例如,虽然有很好的clojure模式准备好了,我很少使用它,我想避免加载它,除非我打开一个扩展名为.clj的文件。这样的懒惰需求功能似乎是正确的方式做模式配置一般..
At this point I have roughly 25 different Emacs modes installed, and startup has become slow. For example, although it's great to have clojure-mode at the ready, I rarely use it, and I want to avoid loading it at all unless I open a file with extension .clj. Such a "lazy require" functionality seems like the right way do mode configuration in general..
我没有在网上发现,所以我自己采取了一个裂缝。
I found nothing online, so I've taken a crack at it myself.
而不是:
(require 'clojure-mode)
(require 'tpl-mode)
我有这个:
(defun lazy-require (ext mode)
(add-hook
'find-file-hook
`(lambda ()
(when (and (stringp buffer-file-name)
(string-match (concat "\\." ,ext "\\'") buffer-file-name))
(require (quote ,mode))
(,mode)))))
(lazy-require "soy" 'soy-mode)
(lazy-require "tpl" 'tpl-mode)
一个elisp新手,所以评论是欢迎!),但我不知道在网上找不到任何关于这个话题。这是一个合理的方法吗?
This seems to work (I'm an elisp newbie so comments are welcome!), but I'm unnerved about finding nothing written about this topic online. Is this a reasonable approach?
推荐答案
您想要的工具名为自动加载。 clojure-mode
源文件, clojure-mode.el ,包括如何安排此注释:
The facility you want is called autoloading. The clojure-mode
source file, clojure-mode.el, includes a comment for how to arrange this:
;; Add these lines to your .emacs:
;; (autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
;; (add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
这篇关于Emacs:.emacs中延迟加载模式的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!