There are two major modes for editing Scala programs. For more about Scala, see Scala on Wikipedia and the Scala website.

There is also a minor-mode for editing scala programs that use the Scalatra web application framework (see WikiPedia:Scalatra). The mode is available at

Without Using the Emacs Package System

Here is an example configuration using the old scala-mode with ensime. However ensime now suggests using scala-mode2.

(setq exec-path (append exec-path (list "/home/seth/.opt/scala/bin" ))) ;;change to location of scala bin!!! necessary for comint.
(require 'scala-mode-auto)
(require 'ensime)
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)
(eval-after-load "scala-mode" 
    (define-key scala-mode-map (kbd "<f9>") 'ensime-builder-build)
    (define-key scala-mode-map (kbd "<f10>") 'ensime-inf-switch)))

  (eval-after-load "scala-mode" 
       (add-hook 'scala-mode-hook 'ensime-scala-mode-hook)
       (define-key scala-mode-map (kbd "<f9>") 'scala-run)
       (define-key scala-mode-map (kbd "RET") 'newline-and-indent)

 (defun scala-run () 
   (ensime-sbt-action "run")
   (ensime-sbt-action "~compile")
(let ((c (current-buffer)))
   (get-buffer-create (ensime-sbt-build-buffer-name)))
 (switch-to-buffer-other-window c))) 
 (setq exec-path
        (append exec-path (list "~/.opt/scala/bin"))) ;;REPLACE THIS with the directory of your scalac executable!

I then use ensime and sbt.

Ok, so create a random file in the source directory created by sbt that contains some random code. Run ensime-config-project, follow instructions, etc. It should suggest that the project is of type sbt. Now, run the command ‘ensime’ – it should connect with ensime. Now, type C-c C-v s, this will start the scala sbt process. I suggest opening it in another frame by using ‘C-x 5 2’.

And you can now hit f9 to run your code - ok, so you have to hit it twice for some reason!

CategoryModes ProgrammingModes