diff options
Diffstat (limited to 'vim/bundle/vim-snippets/snippets/scala.snippets')
-rw-r--r-- | vim/bundle/vim-snippets/snippets/scala.snippets | 360 |
1 files changed, 360 insertions, 0 deletions
diff --git a/vim/bundle/vim-snippets/snippets/scala.snippets b/vim/bundle/vim-snippets/snippets/scala.snippets new file mode 100644 index 0000000..003081e --- /dev/null +++ b/vim/bundle/vim-snippets/snippets/scala.snippets @@ -0,0 +1,360 @@ +################################################################ +# © Copyright 2011 Konstantin Gorodinskiy. All Rights Reserved.# +# Do What The Fuck You Want To Public License, Version 2. # +# See http://sam.zoy.org/wtfpl/COPYING for more details. # +################################################################ +# Scala lang +#if +snippet if + if (${1}) + ${0} +#if not +snippet ifn + if (!${1}) + ${0} +#if-else +snippet ife + if (${1}) + ${2} + else + ${0} +#if-else-if +snippet ifelif + if (${1}) + ${2} + else if (${3}) + ${0} +snippet eif + else if (${3}) + ${0} +#while loop +snippet wh + while (${1:obj}) { + ${0} + } +#for loop(classic) +snippet for + for (${1:item} <- ${2:obj}) { + ${0} + } +#for loop(indexed) +snippet fori + for (${1:i} <- ${2:0} to ${3:obj}.length) { + ${0} + } +#for comprehension +snippet fory + for { + ${1:item} <- ${2:obj} + } yield ${0} +#exceptions +snippet try + try { + ${1} + } catch { + case e: FileNotFoundException => ${2} + case e: IOException => ${3} + } finally { + ${0} + } +#match +snippet match + ${1: obj} match { + case ${2:e} => ${3} + case _ => ${0} + } +#case +snippet case + case ${1:value} => ${0} +############################ +# methods and arguments +# +#arg +snippet arg + ${1:a}: ${2:T}${0:, arg} +#args +snippet args + ${1:args}: ${0:T}* +#def +snippet def + def ${1:name}(${2:arg}) = ${0:} +#private def +snippet prdef + private def ${1:name}(${2:arg}) = ${0:} +#override def +snippet ovdef + override def ${1:name}(${2:arg}) = ${0:} +#first class function(see scalabook p 188) +snippet fcf + (${1:a}: ${2:T}) => $1 ${0} +snippet => + ${1:name} => ${0} +#recursion +snippet rec + def ${1:name}(${0:arg}) = + if($2) $2 + else $1($2) +#curried method +snippet crdef + def ${1:name}(${2:arg})(${3:arg}) = ${0:} +#main method +#check validity of T +snippet main + def main(args: Array[String]):${1:T} = ${0:} +############################ +# basic types(general purpose) +# you might want to use basic types snippets + +#1 +snippet T Double + dbl +#2 +snippet T Int + int +#3 +snippet T Long + lng +#4 +snippet T Char + chr +#5 +snippet T String + str +#6 +snippet T Array + arr +#7 +snippet T Buffer + buf +#8 +snippet T List + list +#9 +snippet T Tuple + tpl +#10 +snippet T Set + set +#11 +snippet T Map + map +#12 +snippet T HashSet + hset +#13 +snippet T HashMap + hmap +#14 +snippet T Boolean + bool +#end + +#named snippets for types +snippet bool + Boolean +snippet anyr + AnyRef +snippet dbl + Double +snippet int + Int +snippet str + String +snippet chr + Char +snippet lng + Long +snippet arr + Array${1:[T]}${0:()} +snippet buf + Buffer${1:[T]}${0:()} +snippet list + List${1:[T]}${0:()} +snippet tpl + Tuple${1:2}[${2:T},${0:T}] +snippet set + Set${1:[T]}${0:()} +snippet hset + HashSet${1:[T]}${0:()} +snippet mhset + mutable.HashSet${1:[T]}${0:()} +#for maps +snippet keyval + ${1:key}->${2:val}${0:, keyval} +snippet map + Map[${1:T},${2:T}]${0:(keyval)} +snippet hmap + HashMap[${1:T},${2:T}]${0:(keyval)} +snippet mmap + mutable.Map[${1:T},${2:T}]${0:(keyval)} +snippet mhmap + mutable.HashMap[${1:T},${2:T}]${0:(keyval)} +#TODO add TreeMap and TreeSet +#asInstanceOf[] +snippet as + ${1:name}.asInstanceOf[${2:T}] +#isInstanceOf[] +snippet is + ${1:name}.isInstanceOf[${2:T}] + +#collections methods + +#scope() with one arg +snippet (a + (${1:a} => ${0}) +#scope() with two args +snippet {( + {(${1:a},${2:b}) => + ${0} + } +#filter +snippet filter + ${0:name}.filter (a +#map function +snippet mapf + ${0:name}.map (a +#flatmap +snippet flatmap + ${1:name}.flatMap${0:[T]}(a +#fold left +snippet fldl + ${1:name}.foldLeft(${0:first}) {( +#fold right +snippet fldr + ${1:name}.foldRight(${0:first}) {( +#fold left operator(if u wanna reduce readability of ur code) +#use wildcard symbols +snippet /: + (${1:first}/:${2:name})(${0}) +#fold right operator +snippet :\ + (${1:first}:\${2:name})(${0}) +#reduce left +snippet redl + ${1:name}.reduceLeft[${0:T}] {( +#reduce right +snippet redr + ${1:name}.reduceRight[${0:T}] {( +#zipWithIndex(safe way). +#see http://daily-scala.blogspot.com/2010/05/zipwithindex.html +snippet zipwi + ${0:name}.view.zipWithIndex +#split +snippet spl + ${1:name}.split("${0:,}") +#end +snippet val + val ${1:name}${2:: T} = ${0:value} +snippet var + var ${1:name}${2:: T} = ${0:value} +############################ +# classes +# +#extends +snippet extends + extends ${0:what} +#with +snippet with + with ${1:what}${0: with} +#auxiliary constructor(a. this) +snippet athis + def this(arg) = this(arg) +#abstract class +snippet abstract + abstract class ${1:name}${2:(arg)}${3: extends }${4: with} { + ${5:override def toString = "$1"} + ${0} + } +#class +snippet class + class ${1:name}${2:(arg)}${3: extends }${4: with} { + ${5:override def toString = "$1"} + ${0} + } +#object +snippet object + object ${1:name}${2:(arg)}${3: extends }${4: with} ${0:} +#trait +snippet trait + trait ${1:name}${2: extends }${3: with} { + ${0:} + } +#class with trait Ordered(page 265) +snippet ordered + class ${1:name}${2:(arg)} extends Ordered[$1] ${3: with} { + ${4:override def toString = "$1"} + def compare(that: $1) = ${5:this - that} + ${0} + } +#case class +snippet casecl + case class ${1:name}${2:(arg)}${3: extends }${4: with} ${0:} +############################ +# testing +# +#scalatest imports +snippet scalatest + ${1:import org.scalatest.Suite} + ${0:import org.scalatest.FunSuite} +#assert +snippet assert + assert(${1:a} === ${0:b}) +#ensuring(p 296) +snippet ensuring + ifel ensuring(${1:a}==${0:b}) +#expect +snippet expect + expect(${1:what}) { + ${0} + } +#intercept +snippet intercept + intercept[${1:IllegalArgumentException}] { + ${0} + } +#test +snippet test + test("${1:description}") { + ${0} + } +#suite +snippet suite + class ${0:name} extends Suite { + def test() { + } +#funsuite +snippet fsuite + class ${1:name} extends FunSuite { + test("${0:description}") { + } +############################ +# SBT +# +snippet webproject + import sbt._ + + class ${1:Name}(info: ProjectInfo) extends DefaultWebProject(info) { + val liftVersion = "${0:2.3}" + + override def libraryDependencies = Set( + + ) ++ super.libraryDependencies + + val snapshots = ScalaToolsSnapshots + } +#depencies +snippet liftjar + "net.liftweb" %% "${0:lib}" % liftVersion % "compile->default", +snippet jettyjar + "org.mortbay.jetty" % "jetty" % "${0:version}" % "test->default", +############################ +# Lift +# +#lift imports +snippet liftimports + import _root_.net.liftweb.http._ + import S._ + import _root_.net.liftweb.util._ + import Helpers._ + import _root_.scala.xml._ +#TODO LIFT,SBT,WEB.XML,HTML snippets |