Emacs and Akka Pi example

· Read in about 2 min · (217 Words)

I was trying The first Akka Example here

Install the TypeSafe stack on RPM distro:

$ sudo yum install typesafe-stack

Setup a g8 project:

$ g8 typesafehub/akka-scala-sbt
Akka 2.0 Project Using Scala and sbt 

organization [org.example]: in.tuxdna
name [Akka Project In Scala]: akka-pi
akka_version [2.0.1]: 
version [0.1-SNAPSHOT]: 

The I added the Pi.scala to src/main/scala folder. Then I tried to compile it from within Emacs, to check if it will be easier navigate compilation errors in the code. I got wierd output. Emacs compilation buffer was printing escape characters.

For this I found two solutions:

Disable the colors generated by SBT in the first place: http://www.scala-lang.org/node/2198

sbt compile -Dsbt.log.noformat=true

Or, enable ANSI colors in Emacs compilation buffer: http://stackoverflow.com/questions/13397737/ansi-coloring-in-compilation-mode

 (require 'ansi-color)
(defun colorize-compilation-buffer ()
  (ansi-color-apply-on-region (point-min) (point-max))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)

And here is the final output after I had resolved all the compilation errors. ( because I didn’t copy/paste all the code, I typed it out ):

Enter number: ~/Downloads/akka-pi$ sbt run 
[info] Loading project definition from /home/saleem/Downloads/akka-pi/project
[info] Set current project to akka-pi (in build file:/home/saleem/Downloads/akka-pi/)

Multiple main classes detected, select one to run:

 [1] in.tuxdna.Akkapi
 [2] Pi

Enter number: 2

[info] Running Pi 

	Pi approximation: 		3.1415926435897874
	Calculation time: 	991.0
[success] Total time: 4 s, completed 15 Mar, 2013 8:04:33 PM

Value of PI : 3.1415926435897874