Emacs之YASnippet

  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安裝

  1. Download the latest yasnippet-bundle-x.y.z.el.tgzand unpack it.
  2. You'll get a file named yasnippet-bundle.el, put it under~/.emacs.d/plugins/ (create the directory if not exists).
  3. Open the file in Emacs, and type Alt+x eval-buffer.


  
  
  
  
  1. 下載最新版本的yasnippet-bundle-版本號.el.tgz並解壓縮。 
  2.  
  3. 會獲得一個名字爲yasnippet-bundle.el的文件把他放到~/.emacs.d/plugins/目錄下(若是不存在,自行建立). 
  4.  
  5. 在Emacs裏打開該文件,而後Alt-x eval-buffer命令。 

OK,如今打開任意一種語言的源文件,就會看到菜單欄出現一個YASnippet的菜單。視頻

固然你能夠使用菜單項執行模版擴展替換,也能夠使用觸發鍵並按TAB擴展。

爲了讓Emacs啓動時能自動加載YASnippet,須要在你的~/.emacs配置文件里加上這段:

  
  
  
  
  1. (add-to-list 'load-path 
  2.               "~/.emacs.d/plugins"
  3. (require 'yasnippet-bundle) 

正常安裝

爲了使用正常的包安裝YASnippet,下載解壓最新的yasnippet-x.y.z.tar.bz2,獲得一個名字相似yasnippet-x.y.z的目錄,你能夠把它放在 ~/.emacs.d/plugins目錄中,

在.emacs文件中添加:

  
  
  
  
  1. (add-to-list 'load-path 
  2.               "~/.emacs.d/plugins/yasnippet-x.y.z") 
  3. (require 'yasnippet) ;; not yasnippet-bundle 
  4. (yas/initialize) 
  5. (yas/load-directory "~/.emacs.d/plugins/yasnippet-x.y.z/snippets") 

完整的定製參照文檔。

如何使用YASnippet

自從0.6版本以來,YASnippet提供更多的功能。固然你不必通通搞會每個,但是瞭解他們會大大提高你的體驗。

組織代碼段

擴展代碼段

書寫代碼段

使用YASnippet菜單

相關文章
相關標籤/搜索