This mode provides font-lock for editing scalatra routes. It highlights the http method name and any URL parameters in font-lock-preprocessor-face.
-
Install scala-mode2 from http://github.com/hvesalai/scala-mode2
-
Download the files to a local directory. You can use the git clone command, this will create a new directory called scalatra-mode.
git clone git://github.com/hvesalai/scalatra-mode.git
- Include the following in your
.emacs
file after scala-mode2.
(add-to-list 'load-path "/path/to/scalatra-mode/")
(require 'scalatra-mode)
- Turn the mode on (see next section)
There are many ways you can turn the mode on for a file. One way is to
turn it on for all scala files. Just add the following to your
.emacs
file:
(add-hook 'scala-mode-hook '(lambda ()
(scalatra-mode)
))
An other way is to use an emacs file variable. Include the following as the first line of your scala file:
// -*- eval: (scalatra-mode) -*-
You can also use the longer format of the file variable, which you are free to place anywhere in the file (e.g. at the end):
// Local Variables:
// eval: (scalatra-mode)
// End:
Lastly you can start the mode manually for any buffer. Just use M-x scalatra-mode to start or stop the mode for a buffer.
The highlighting is particularly picky on what it highlights. This is to avoid it highlighting any other scala code.
A route is highlighted only if all the following conditions are true:
-
the method (get, post, delete, put) is the first on the line
-
the method is separated from preceding code with at least one empty line, or the preceding code is terminated by one of
;
,)
or}
-
the method has two parameter groups. The first parameter group has to be in normal parentheses, the second can be in curly braces or parentheses. The first group has to start right after the method name (no space allowed).
-
The first parameter of the first parameter group is a string.
Examples:
// this will be highlighted
post("/customer/:id") {
}
// the following will not be highlighted
get ("/customer/:id") // breaks rules 3
foo.
get("/customers") { // breaks rule 2
}
/* zot */ get ("/orders") { // breaks rule 1
}
Mode development: Heikki Vesalainen
See the LICENSE file.