YASnippet是Emacs的一个模版系统.容许输入一个缩写,自动为你扩展为相应的功能模版。捆绑的语言模版包括 C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS 等等。代码段的语法灵感源于 TextMate,你甚至能够导入大部分的 TextMate模版。git
Yasnippet 已经迁移到GitHub上了:http://github.com/capitaomorte/yasnippet!!!github
google code上的老版本在这里:api
http://code.google.com/p/yasnippet/downloads/listide
还有个Demo视频:ui
http://code.google.com/p/yasnippet/downloads/detail?name=yas_demo.mp4google
安装spa
There are two archives you can download. To quickly tryout YASnippet, download the simpler "bundle" version. If you plan to modify the bundled templates and/or build your own, download the "normal" package. code
有2个归档供你下载。若是想快速体验下YASnippet,能够只需下载"bundle"版。若是你打算修改打包的模版或者建立你本身的模版,那么要下载"normal"包了。orm
- 下载最新版本的yasnippet-bundle-版本号.el.tgz并解压缩。
- 会获得一个名字为yasnippet-bundle.el的文件把他放到~/.emacs.d/plugins/目录下(若是不存在,自行建立).
- 在Emacs里打开该文件,而后Alt-x eval-buffer命令。
OK,如今打开任意一种语言的源文件,就会看到菜单栏出现一个YASnippet的菜单。视频
固然你能够使用菜单项执行模版扩展替换,也能够使用触发键并按TAB扩展。
为了让Emacs启动时能自动加载YASnippet,须要在你的~/.emacs配置文件里加上这段:
- (add-to-list 'load-path
- "~/.emacs.d/plugins")
- (require 'yasnippet-bundle)
正常安装
为了使用正常的包安装YASnippet,下载解压最新的yasnippet-x.y.z.tar.bz2,获得一个名字相似yasnippet-x.y.z的目录,你能够把它放在 ~/.emacs.d/plugins目录中,
在.emacs文件中添加:
- (add-to-list 'load-path
- "~/.emacs.d/plugins/yasnippet-x.y.z")
- (require 'yasnippet) ;; not yasnippet-bundle
- (yas/initialize)
- (yas/load-directory "~/.emacs.d/plugins/yasnippet-x.y.z/snippets")
完整的定制参照文档。
如何使用YASnippet
自从0.6版本以来,YASnippet提供更多的功能。固然你不必通通搞会每个,但是了解他们会大大提高你的体验。
组织代码段
扩展代码段
书写代码段
使用YASnippet菜单