How to setup a fairly comprehensive emacs environment for Scala development.

Setup Overview

The core setup involves that standard Scala mode, CEDET, ECB, MVN, SBT and Yasnippit emacs lisp. We’ll go through each piece one at a time.

At the completion we should have something like the following.

http://imagebin.ca/view/BObUKpq.html


Note: I am assuming some basic emacs chops and executing some brevity in this how-to. My goal for now is getting the gist laid out here and expand on an add-needed basis. For questions: ray dot racine atthe google dothere com.


Step #0 Install Emacs

I recommend installing a recent version, even building emacs from CVS. Version 23 for emacs should be out today (July 29, 2009) and well worth installing for the anti-aliasing font support alone. Everything below works on my Linux system under the latest emacs from CVS.

Step #1 Basic Emacs

This is pretty much optional, but I like a clean emacs, just the text if you please, with a black background and bold colors. Your .emacs should look like this.

(global-font-lock-mode t)

(windmove-default-keybindings)

(setq use-file-dialog nil)

;; "y or n" instead of "yes or no"
(fset 'yes-or-no-p 'y-or-n-p)

;; Highlight regions and add special behaviors to regions.
;; "C-h d transient" for more info
(setq transient-mark-mode t)

;; Display line and column numbers
(setq line-number-mode t)
(setq column-number-mode t)

(global-set-key "\C-c\C-w" 'backward-kill-word)

;; Remove unnecessary gui stuff
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode 1))

(blink-cursor-mode 0) ;; no blink

(set-background-color "black")
(set-face-background 'default "black")
(set-face-background 'region "black")
(set-face-foreground 'default "white")
(set-face-foreground 'region "gray60")
(set-foreground-color "white")
(set-cursor-color "red")

The windmov-default-keybindings is a godsend. Hold down the shift key and use arrows to move around the windows.

Step #2 Scala Mode

Install the basic Scala mode from the Scala folks. They did a nice job.

Check it out here. svn co http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/emacs

The standard Scala distribution includes an Emacs mode. By default it does not expand tabs into spaces, so you might want to add the following code to your .emacs file:

(defun me-turn-off-indent-tabs-mode ()
  (setq indent-tabs-mode nil))
(add-hook 'scala-mode-hook 'me-turn-off-indent-tabs-mode)

Follow the readme and install. The yasnippit stuff is not bad, but I don’t use it extensively, but give it a whirl and decide yourself.

My ~/.emacs file looks (sorta) like the following after I installed basic scala-mode and yasnippit for Scala.


;; Scala Mode

(let ((path "/usr/local/share/emacs/site-lisp/scala"))
  (setq load-path (cons path load-path))
  (load "scala-mode-auto.el"))

(defun scala-turnoff-indent-tabs-mode ()
  (setq indent-tabs-mode nil))

;; scala mode hooks
(add-hook 'scala-mode-hook 'scala-turnoff-indent-tabs-mode)

;; YASNIPPIT

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/yasnippet-0.5.7")
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "/usr/local/share/emacs/site-lisp/yasnippet-0.5.7")

Step #3 Install Ex. CTags

Install Exuberant Ctags from

http://ctags.sourceforge.net/

ectags are necessary for CEDET to parse the Scala code. Using ctags gives us a mininal parsing capability for the CEDET semantic database. By enhancing the parsing, we enhance the semantic intellisense, completion etc. Ideally, parsing the output of the Scala compiler would maximize the capabilities of CEDET. For now, ctags with regexp parsing is what we have and it is not too bad.

If you already have exuberant ctags installed for Scala you _must_ remove or rename your ~/.ctags file (or remove any Scalaisms in it). All the ctags args are passed in the CEDET/contrib/semantic-ectag-scala.el file in the CEDET install from CVS.

If ectags is not found (M-x semantic-ectag-version), then CEDET/semantic/ctags/semantic-ectag-util.el file needs to be updated. Update semantic-ectag-program to have the absolute location of ectags. After you update the file, you need to run the make command.


;;semantic-ectag-util.el

(defcustom semantic-ectag-program "/usr/local/bin/ectags" 
  "The Exuberent CTags program to use."
  :group 'semantic
  :type 'program)

Step #4 CEDET and ECB

Checkout CEDET and ECB at

http://cedet.sourceforge.net/

and

http://ecb.sourceforge.net/

For CEDET a simple $ make worked great. For ECB edit the Makefile, set the path to CEDET and $ make.

Just that easy.

I have the following in my .emacs


;; CEDET

(load "/code/cedet/cedet/common/cedet.el")
(load "/code/cedet/cedet/contrib/semantic-ectag-scala.el")
;;(global-ede-mode 1)                      ; Enable the Project management system
(semantic-load-enable-code-helpers)      ; Enable prototype help and smart completion 
(global-srecode-minor-mode 1)            ; Enable template insertion menu
(semantic-load-enable-primary-exuberent-ctags-support)

;; ECB

(add-to-list 'load-path
             "/code/ecb/ecb")

(require 'ecb)

Step #5 SBT

Download sbt.el from here.

http://github.com/RayRacine/scallap/tree/master/tools/emacs


(load "/path/to/elisp/sbt.el")

Load it from where ever you put it through any number of means. A simple load like the above works.

Step #6 Feel THE POWER

OK at this point you have _tons_ of stuff that can be configured endlessly. My configuration looks something like this in my ~/.emacs file.


(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(dabbrev-case-fold-search nil)
 '(ecb-options-version "2.40")
 '(global-semantic-decoration-mode nil nil (semantic-decorate-mode))
 '(global-semantic-highlight-edits-mode nil nil (semantic-util-modes))
 '(global-semantic-highlight-func-mode nil nil (semantic-util-modes))
 '(global-semantic-idle-completions-mode t nil (semantic-idle))
 '(global-semantic-idle-scheduler-mode nil nil (semantic-idle))
 '(global-semantic-idle-summary-mode nil nil (semantic-idle))
 '(global-semantic-idle-tag-highlight-mode nil nil (semantic-idle))
 '(global-semantic-mru-bookmark-mode t nil (semantic-util-modes))
 '(global-semantic-show-parser-state-mode nil nil (semantic-util-modes))
 '(global-semantic-show-unmatched-syntax-mode nil nil (semantic-util-modes))
 '(global-semantic-stickyfunc-mode nil nil (semantic-util-modes))
 '(global-senator-minor-mode t nil (senator))
 '(inhibit-startup-screen t)
 '(semantic-complete-inline-analyzer-displayor-class (quote semantic-displayor-tooltip))
 '(semantic-complete-inline-analyzer-idle-displayor-class (quote semantic-displayor-tooltip))
 '(semantic-idle-scheduler-verbose-flag t)
 '(semantic-imenu-sort-bucket-function (quote semantic-sort-tags-by-name-increasing))
 '(semanticdb-global-mode t nil (semanticdb))
 '(show-paren-mode t)
 '(transient-mark-mode t)
 '(which-function-mode nil))

Try the following. Go to the root directory of your Scala project, this would be where your sbt project/, src/, target/ resides.

Start emacs and edit a file.


M-x ecb-activate
M-x ecb-toggle-compile-window
M-x sbt-shell

For configuration options please read the CEDET and ECB doc.

If you have questions hit me up at the email above or catch me on freenode IRC #scala.

 
tools/emacs.txt · Last modified: 2010/06/11 12:52 by 71.252.163.165
 
Recent changes RSS feed Valid XHTML 1.0 Driven by DokuWiki