]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/plugin/31-create-scala.vim
Remove task Warrior
[rbdr/dotfiles] / vim / plugin / 31-create-scala.vim
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
6 "
7 " Author : Stepan Koltsov <yozh@mx1.ru>
8
9 function! MakeScalaFile()
10 if exists("b:template_used") && b:template_used
11 return
12 endif
13
14 let b:template_used = 1
15
16 let filename = expand("<afile>:p")
17 let x = substitute(filename, "\.scala$", "", "")
18
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.", "")
27
28 " ! marks that we found package name.
29 if match(p, "^!") == 0
30 let p = substitute(p, "^!", "", "")
31 else
32 " Don't know package name.
33 let p = "@"
34 endif
35
36 let class = substitute(x, ".*/", "", "")
37
38 if p != "@"
39 call append("0", "package " . p)
40 endif
41
42 "norm G
43 "call append(".", "class " . class . " {")
44
45 "norm G
46 "call append(".", "} /// end of " . class)
47
48 call append(".", "// vim: set ts=4 sw=4 et:")
49 call append(".", "")
50
51 endfunction
52
53 au BufNewFile *.scala call MakeScalaFile()
54
55 " vim: set ts=4 sw=4 et: