気が向いたらなんか書く

そんな感じです

Emacs+Ensime環境を使ってPlay Framework2.0で遊ぶ

とりあえず…

EmacsVimが幾ら使い慣れているからって言っても、モノによってはEclipse使ったりIntelliJ使ったりしたほうが当然便利な場合もあるわけで、特にJavaに関してはEmacs+JDEEは既にオワコンなので、わざわざEmacsで書くのも馬鹿らしい感じもするわけですが、それでもEmacsVimを使うのは単なるオナニーであることを認識している人だけが、この高みを望める訳です(はぁ?

取ってくる

Ensimeはgithubで公開されています。ここで思わずcloneとかしたくなっちゃいますが、Ensimeは利用するScalaのバージョンに強く依存しているようで、開発の先端を取ってくるよりちゃんとDownload用として用意しているものを使ったほうが、経験上、安定していていいようです。

https://github.com/aemoncannon/ensime/downloads

現時点ではScalaの最新安定版が2.9.2なので、2.9.2用で枝番が最新のやつを持ってくれば問題ないと思います

ここではensime_2.9.2-0.9.8.1.tar.gzを使います

scala-mode

おっとその前に、EnsimeはScalaに付属しているscala-modeに依存しますので、予めscala-modeが入っていることが前提になります。まぁ、当然入っているとは思うがニャー

え?無い?実はstable版の2.9.2のパッケージには入っていません!説明はここにありますが

Subsequently, we moved our repository to GitHub and changed our distribution packaging infrastructure. At this time, "tool-support" it is not by default part of the 2.9.2 distribution, but it will be made available again in the next releases. In the meantime, you can find the source repository at this address: http://www.scala-lang.org/node/91#tool_support

ということなので、そこから取ってきて入れます。

こんな感じに書いておけば動くでしょう

いれてみる

取ってきたensimeを適当な場所に展開し、設定でload-pathを通しておけばとりあえずOKです。

Play! Frameworkで遊ぶ為に

当然ですがPlayFrameworkが既にInstallされているとします。まぁ、Play自体は展開してPATH通せばいいだけなので、特に問題ないかと思います。とりあえず新しいプロジェクトを作成します。

$ play new testapp
       _            _
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/

play! 2.0.4, http://www.playframework.org

The new application will be created in /home/misty/dev/scala/testapp

What is the application name?
> testapp

Which template do you want to use for this new application?

  1 - Create a simple Scala application
  2 - Create a simple Java application
  3 - Create an empty project

> 1

OK, application testapp is created.

Have fun!

$

はい、できました。現在、defaultのSkeletonでプロジェクトを作成するとこんな感じです。次にensimeで使うためにPlay自体を解析してensime上から補完出来るようにします。その為に、作成したプロジェクトディレクトリ内のproject/plugins.sbtにpluginの設定します。

$ cat plugins.sbt
// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0.4")

addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "0.1.0")  // <-これ

ここまでしたらplay consoleを起動してensime generateを実行します。

[testapp] $ ensime generate
[info] Gathering project information...
[info] Processing project: ProjectRef(file:/home/misty/Develop/scala/testapp/,testapp)...
[info]  Reading setting: name...

(略)

[info]  Reading setting: class-directory...
[info]  Reading setting: ensime-config...
[info] Wrote configuration to .ensime
[testapp] $ 

これでensimeの利用準備完了です。

Emacs + Ensime

とりあえず先ほど作ったプロジェクトで作成されたソースを開こうとすると

error Not connected. M-x ensime to connect

みたいなことを言われるので

M-x ensime

を起動します。特に問題がなければうまいこと起動して使えるようになるはずです!続きは気が向いたら書きます。