Emacs:.emacs 中延迟加载模式的最佳实践?
遇到相关文件扩展名时,是否有关于延迟加载模式的最佳实践?
此时我已经安装了大约 25 种不同的 Emacs 模式,并且启动变得很慢。例如,虽然准备好 clojure 模式很好,但我很少使用它,并且我想完全避免加载它,除非我打开扩展名为 .clj 的文件。这种“惰性需求”功能似乎是一般模式配置的正确方法。
我在网上找不到任何东西,所以我自己尝试了一下。
而不是:
(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 新手,所以欢迎评论!),但我对在网上找不到任何关于这个主题的文章感到不安。这是一个合理的做法吗?
Is there a best practice around lazily loading modes when encountering a relevant file extension?
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.
Instead of:
(require 'clojure-mode)
(require 'tpl-mode)
I have this:
(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)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要的工具称为自动加载。
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:这是一种方式,
同时,
This is one way,
along with,