autoinsertというものを使えば、コードを書くさいにテンプレートを用いることができる。

.emacsに以下のコードを記述するだけでOK。

   1  (require 'autoinsert)
   2  (setq auto-insert-directory "~/.code_template/")
   3  (setq auto-insert-alist
   4        (nconc '( ("\\.c$" . "template.c")
   5                  ("\\.cpp$" . "template.cpp")
   6                  ("\\.js$" . "template.js")
   7                  ("\\.html$" . "template.html")
   8                  ("\\.css$" . "template.css")
   9                  ("\\.rb$" . "template.rb")
  10                  ) auto-insert-alist))
  11  
  12  (add-hook 'find-file-not-found-hooks 'auto-insert)

簡単に説明すると、拡張子が .c のものを新規で作成すると ~/.code_template/template.c というファイルを読み込むという感じ。

あとは.code_template/(別に名前は何でもいいけども)以下にテンプレートを入れていくだけ。

「これは絶対に書く!」ってものをテンプレートに書いておくと、ちょっとはコード書くのが楽になったりするかな。

みんなでテンプレートを公開しあうのもおもしろいかもー。

この記事は2007年3月26日に書いた僕の以前のブログの記事です

posted by Png y_tsuda on Tue 25 Nov 2008 at 23:31 with 2 comments
Contents
テンプレートを使って、コードを書くのを楽しよう!
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ