Skip to content

hvesalai/scalatra-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

scalatra-mode - a minor-mode for emacs

This mode provides font-lock for editing scalatra routes. It highlights the http method name and any URL parameters in font-lock-preprocessor-face.

Setting the mode up for use

  1. Install scala-mode2 from http://github.com/hvesalai/scala-mode2

  2. 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
  1. Include the following in your .emacs file after scala-mode2.
(add-to-list 'load-path "/path/to/scalatra-mode/")
(require 'scalatra-mode)
  1. Turn the mode on (see next section)

Turning the mode on for a file

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.

What exactly is highlighted?

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:

  1. the method (get, post, delete, put) is the first on the line

  2. the method is separated from preceding code with at least one empty line, or the preceding code is terminated by one of ;, ) or }

  3. 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).

  4. 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
}

Credits

Mode development: Heikki Vesalainen

See the LICENSE file.

About

A minor-mode for highlighting scalatra routes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published