emacs 使用 template

折腾了一下午,总算搞好了。

首先是折腾 yasnippet,可是 expand 看不懂,官方大家都说简单,可见我水平一般到什么程度。

再次折腾 template-simple,根本一点也不 simple 好么,但抱着支持国人的决心,挣扎纠结还是放弃了。

最后折腾 template.el,被 emacs 打败了。全是尼玛的傲骄萌物啊。

 

根据 template 中的 INSTALL 安装好即可使用(前提是你将东西都放到了制定的位置,比如 Templates 要放在 ~/.templates 下)。成功后我想简单的定制一下,将 Templates 放在 ~/.emacs.d/template/templates 下,就这简单的一步浪费了一下午。

 

查看 template.el 的源码,如下:

(defcustom template-default-directories
  (cons (if (and (not (file-directory-p "~/.templates/"))
		 (file-directory-p "~/lib/templates"))
	    (expand-file-name "~/lib/templates/")
	  (expand-file-name "~/.templates/"))
	(and (fboundp 'locate-data-directory)
	     (let ((dir (locate-data-directory "template")))
	       (and dir (list dir)))))
  "*List of default directories for template files.
See `template-derivation-alist' for details."
  :group 'template-derivation
  :type '(repeat directory))

 我真的天真的以为这是 template.el 设置查找 Templates 的目录,所以我这样:

(setq template-default-directories "~/.emacs.d/template/templates/“)

 结果尼玛无用啊,还提示错误。

后来在这篇,还有这篇中看出了端弥,需要这样配置:

(setq template-subdirectories '("~/.emacs.d/template/templates"))

完整配置如下:

;; 定义模版
(add-to-list 'load-path "~/.emacs.d/template/")
(require 'template)
;; 必须这么指定 搜索目录,蛋疼
(setq template-subdirectories '("~/.emacs.d/template/templates"))
(setq template-auto-insert t)
(template-initialize)
(add-to-list 'template-find-file-commands
             'ido-exit-minibuffer)
;; 结束

  这样就搞定了,具体原因需要等我过了6级以后在告诉大家.....

上图一张


emacs 使用 template