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菜單