遇到相关文件扩展名时,是否有关于延迟加载模式的最佳做法?
此时我安装了大约25种不同的Emacs模式,启动变慢.例如,尽管准备好clojure模式很棒,但我很少使用它,除非我打开扩展名为.clj的文件,否则我想避免加载它.这种"懒惰的需求"功能似乎是正确的模式配置方式.
我在网上找不到任何东西,所以我自己也搞砸了.
代替:
(require 'clojure-mode)
(require 'tpl-mode)
Run Code Online (Sandbox Code Playgroud)
我有这个:
(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)
Run Code Online (Sandbox Code Playgroud)
这似乎工作(我是一个elisp新手,所以欢迎评论!),但我对在网上找不到关于这个主题的书面感到不安.这是一种合理的方法吗?