1 " Vim plugin that generates new Scala source file when you type
2 " vim nonexistent.scala.
3 " Scripts tries to detect package name from the directory path, e. g.
4 " .../src/main/scala/com/mycompany/myapp/app.scala gets header
5 " package com.mycompany.myapp
7 " Author : Stepan Koltsov <yozh@mx1.ru>
9 function! MakeScalaFile()
10 if exists("b:template_used") && b:template_used
14 let b:template_used = 1
16 let filename = expand("<afile>:p")
17 let x = substitute(filename, "\.scala$", "", "")
19 let p = substitute(x, "/[^/]*$", "", "")
20 let p = substitute(p, "/", ".", "g")
21 let p = substitute(p, ".*\.src$", "@", "") " unnamed package
22 let p = substitute(p, ".*\.src\.", "!", "")
23 let p = substitute(p, "^!main\.scala\.", "!", "") "
24 let p = substitute(p, "^!.*\.ru\.", "!ru.", "")
25 let p = substitute(p, "^!.*\.org\.", "!org.", "")
26 let p = substitute(p, "^!.*\.com\.", "!com.", "")
28 " ! marks that we found package name.
29 if match(p, "^!") == 0
30 let p = substitute(p, "^!", "", "")
32 " Don't know package name.
36 let class = substitute(x, ".*/", "", "")
39 call append("0", "package " . p)
43 "call append(".", "class " . class . " {")
46 "call append(".", "} /// end of " . class)
48 call append(".", "// vim: set ts=4 sw=4 et:")
53 au BufNewFile *.scala call MakeScalaFile()
55 " vim: set ts=4 sw=4 et: