From 40ad1b520ee49cd24e99c2682e7a8d429ba86887 Mon Sep 17 00:00:00 2001 From: michener Date: Wed, 17 Mar 2010 02:47:42 +0000 Subject: [PATCH] Add Scala support git-svn-id: http://photonzero.com/dotfiles/trunk@44 23f722f6-122a-0410-8cef-c75bd312dd78 --- .vim/ftdetect/scala.vim | 3 + .vim/indent/scala.vim | 85 ++++++++++++++++++++++ .vim/syntax/go.vim | 190 ++++++++++++++++++++++++++++++++++++++++++++++++ .vim/syntax/scala.vim | 153 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 431 insertions(+) create mode 100644 .vim/ftdetect/scala.vim create mode 100644 .vim/indent/scala.vim create mode 100644 .vim/syntax/go.vim create mode 100644 .vim/syntax/scala.vim diff --git a/.vim/ftdetect/scala.vim b/.vim/ftdetect/scala.vim new file mode 100644 index 0000000..6b35521 --- /dev/null +++ b/.vim/ftdetect/scala.vim @@ -0,0 +1,3 @@ +" $URL$ + +au BufRead,BufNewFile *.scala set filetype=scala diff --git a/.vim/indent/scala.vim b/.vim/indent/scala.vim new file mode 100644 index 0000000..2363b6b --- /dev/null +++ b/.vim/indent/scala.vim @@ -0,0 +1,85 @@ +" Vim indent file +" Language : Scala (http://scala-lang.org/) +" Maintainer : Stefan Matthias Aust +" Last Change: 2006 Apr 13 +" Revision : $Id$ +" $URL$ + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetScalaIndent() + +setlocal indentkeys=0{,0},0),!^F,<>>, + +setlocal autoindent sw=2 et + +if exists("*GetScalaIndent") + finish +endif + +function! CountParens(line) + let line = substitute(a:line, '"\(.\|\\"\)*"', '', 'g') + let open = substitute(line, '[^(]', '', 'g') + let close = substitute(line, '[^)]', '', 'g') + return strlen(open) - strlen(close) +endfunction + +function! GetScalaIndent() + " Find a non-blank line above the current line. + let lnum = prevnonblank(v:lnum - 1) + + " Hit the start of the file, use zero indent. + if lnum == 0 + return 0 + endif + + let ind = indent(lnum) + let prevline = getline(lnum) + + "Indent html literals + if prevline !~ '/>\s*$' && prevline =~ '^\s*<[a-zA-Z][^>]*>\s*$' + return ind + &shiftwidth + endif + + " Add a 'shiftwidth' after lines that start a block + " If if, for or while end with ), this is a one-line block + " If val, var, def end with =, this is a one-line block + if prevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\|va[lr]\|def\)\>.*[)=]\s*$' + \ || prevline =~ '^\s*\\s*$' + \ || prevline =~ '{\s*$' + let ind = ind + &shiftwidth + endif + + " If parenthesis are unbalanced, indent or dedent + let c = CountParens(prevline) + echo c + if c > 0 + let ind = ind + &shiftwidth + elseif c < 0 + let ind = ind - &shiftwidth + endif + + " Dedent after if, for, while and val, var, def without block + let pprevline = getline(prevnonblank(lnum - 1)) + if pprevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\|va[lr]\|def\)\>.*[)=]\s*$' + \ || pprevline =~ '^\s*\\s*$' + let ind = ind - &shiftwidth + endif + + " Align 'for' clauses nicely + if prevline =~ '^\s*\ (.*;\s*$' + let ind = ind - &shiftwidth + 5 + endif + + " Subtract a 'shiftwidth' on '}' or html + let thisline = getline(v:lnum) + if thisline =~ '^\s*[})]' + \ || thisline =~ '^\s*]*>' + let ind = ind - &shiftwidth + endif + + return ind +endfunction diff --git a/.vim/syntax/go.vim b/.vim/syntax/go.vim new file mode 100644 index 0000000..db3903a --- /dev/null +++ b/.vim/syntax/go.vim @@ -0,0 +1,190 @@ +" Copyright 2009 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" go.vim: Vim syntax file for Go. +" +" Options: +" There are some options for customizing the highlighting; the recommended +" settings are the default values, but you can write: +" let OPTION_NAME = 0 +" in your ~/.vimrc file to disable particular options. You can also write: +" let OPTION_NAME = 1 +" to enable particular options. At present, all options default to on. +" +" - go_highlight_array_whitespace_error +" Highlights white space after "[]". +" - go_highlight_chan_whitespace_error +" Highlights white space around the communications operator that don't follow +" the standard style. +" - go_highlight_extra_types +" Highlights commonly used library types (os.Error, etc.). +" - go_highlight_space_tab_error +" Highlights instances of tabs following spaces. +" - go_highlight_trailing_whitespace_error +" Highlights trailing white space. + +" Quit when a (custom) syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +if !exists("go_highlight_array_whitespace_error") + let go_highlight_array_whitespace_error = 1 +endif +if !exists("go_highlight_chan_whitespace_error") + let go_highlight_chan_whitespace_error = 1 +endif +if !exists("go_highlight_extra_types") + let go_highlight_extra_types = 1 +endif +if !exists("go_highlight_space_tab_error") + let go_highlight_space_tab_error = 1 +endif +if !exists("go_highlight_trailing_whitespace_error") + let go_highlight_trailing_whitespace_error = 1 +endif + +syn case match + +syn keyword goDirective package import +syn keyword goDeclaration var const type +syn keyword goDeclType struct interface + +hi def link goDirective Statement +hi def link goDeclaration Keyword +hi def link goDeclType Keyword + +" Keywords within functions +syn keyword goStatement defer go goto return break continue fallthrough +syn keyword goConditional if else switch select +syn keyword goLabel case default +syn keyword goRepeat for range + +hi def link goStatement Statement +hi def link goConditional Conditional +hi def link goLabel Label +hi def link goRepeat Repeat + +" Predefined types +syn keyword goType chan map bool string +syn keyword goSignedInts int int8 int16 int32 int64 +syn keyword goUnsignedInts byte uint uint8 uint16 uint32 uint64 uintptr +syn keyword goFloats float float32 float64 + +hi def link goType Type +hi def link goSignedInts Type +hi def link goUnsignedInts Type +hi def link goFloats Type + +" Treat func specially: it's a declaration at the start of a line, but a type +" elsewhere. Order matters here. +syn match goType /\/ +syn match goDeclaration /^func\>/ + +" Predefined functions and values +syn keyword goBuiltins cap close closed convert copy len make new panic panicln print println +syn keyword goConstants iota true false nil + +hi def link goBuiltins Keyword +hi def link goConstants Keyword + +" Comments; their contents +syn keyword goTodo contained TODO FIXME XXX BUG +syn cluster goCommentGroup contains=goTodo +syn region goComment start="/\*" end="\*/" contains=@goCommentGroup +syn region goComment start="//" end="$" contains=@goCommentGroup + +hi def link goComment Comment +hi def link goTodo Todo + +" Go escapes +syn match goEscapeOctal display contained "\\[0-7]\{3}" +syn match goEscapeC display contained +\\[abfnrtv\\'"]+ +syn match goEscapeX display contained "\\x\x\{2}" +syn match goEscapeU display contained "\\u\x\{4}" +syn match goEscapeBigU display contained "\\U\x\{8}" +syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+ + +hi def link goEscapeOctal goSpecialString +hi def link goEscapeC goSpecialString +hi def link goEscapeX goSpecialString +hi def link goEscapeU goSpecialString +hi def link goEscapeBigU goSpecialString +hi def link goSpecialString Special +hi def link goEscapeError Error + +" Strings and their contents +syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError +syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup +syn region goRawString start=+`+ end=+`+ + +hi def link goString String +hi def link goRawString String + +" Characters; their contents +syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU +syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup + +hi def link goCharacter Character + +" Regions +syn region goBlock start="{" end="}" transparent fold +syn region goParen start='(' end=')' transparent + +" Integers +syn match goDecimalInt "\<\d\+\>" +syn match goHexadecimalInt "\<0x\x\+\>" +syn match goOctalInt "\<0\o\+\>" +syn match goOctalError "\<0\o*[89]\d*\>" + +hi def link goDecimalInt Integer +hi def link goHexadecimalInt Integer +hi def link goOctalInt Integer +hi def link Integer Number + +" Floating point +syn match goFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>" +syn match goFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>" +syn match goFloat "\<\d\+[Ee][-+]\d\+" + +hi def link goFloat Float + +" Spaces after "[]" +if go_highlight_array_whitespace_error != 0 + syn match goSpaceError display "\(\[\]\)\@<=\s\+" +endif + +" Spacing errors around the 'chan' keyword +if go_highlight_chan_whitespace_error != 0 + " receive-only annotation on chan type + syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@=" + " send-only annotation on chan type + syn match goSpaceError display "\(\/ + syn match goExtraType /\/ + syn match goExtraType /\<\(os\.Error\)\>/ + syn match goExtraType /\/ + syn match goExtraType /\/ +endif + +" Space-tab error +if go_highlight_space_tab_error != 0 + syn match goSpaceError display " \+\t"me=e-1 +endif + +" Trailing white space error +if go_highlight_trailing_whitespace_error != 0 + syn match goSpaceError display excludenl "\s\+$" +endif + +hi def link goExtraType Type +hi def link goSpaceError Error + +let b:current_syntax = "go" diff --git a/.vim/syntax/scala.vim b/.vim/syntax/scala.vim new file mode 100644 index 0000000..b19a04f --- /dev/null +++ b/.vim/syntax/scala.vim @@ -0,0 +1,153 @@ +" Vim syntax file +" Language : Scala (http://scala-lang.org/) +" Maintainers: Stefan Matthias Aust, Julien Wetterwald +" Last Change: 2007 June 13 +" Revision : $Id$ +" $URL$ + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +syn case match +syn sync minlines=50 + +" most Scala keywords +syn keyword scalaKeyword abstract case catch do else extends final finally for forSome if implicit lazy match new null override private protected requires return sealed super this throw try type while with yield +syn match scalaKeyword "=>" +syn match scalaKeyword "<-" +syn match scalaKeyword "\<_\>" + +syn match scalaOperator ":\{2,\}" "this is not a type + +" package and import statements +syn keyword scalaPackage package nextgroup=scalaFqn skipwhite +syn keyword scalaImport import nextgroup=scalaFqn skipwhite +syn match scalaFqn "\<[._$a-zA-Z0-9,]*" contained nextgroup=scalaFqnSet +syn region scalaFqnSet start="{" end="}" contained + +" boolean literals +syn keyword scalaBoolean true false + +" definitions +syn keyword scalaDef def nextgroup=scalaDefName skipwhite +syn keyword scalaVal val nextgroup=scalaValName skipwhite +syn keyword scalaVar var nextgroup=scalaVarName skipwhite +syn keyword scalaClass class nextgroup=scalaClassName skipwhite +syn keyword scalaObject object nextgroup=scalaClassName skipwhite +syn keyword scalaTrait trait nextgroup=scalaClassName skipwhite +syn match scalaDefName "[^ =:;([]\+" contained nextgroup=scalaDefSpecializer skipwhite +syn match scalaValName "[^ =:;([]\+" contained +syn match scalaVarName "[^ =:;([]\+" contained +syn match scalaClassName "[^ =:;(\[]\+" contained nextgroup=scalaClassSpecializer skipwhite +syn region scalaDefSpecializer start="\[" end="\]" contained contains=scalaDefSpecializer +syn region scalaClassSpecializer start="\[" end="\]" contained contains=scalaClassSpecializer + +" type constructor (actually anything with an uppercase letter) +syn match scalaConstructor "\<[A-Z][_$a-zA-Z0-9]*\>" nextgroup=scalaConstructorSpecializer +syn region scalaConstructorSpecializer start="\[" end="\]" contained contains=scalaConstructorSpecializer + +" method call +syn match scalaRoot "\<[a-zA-Z][_$a-zA-Z0-9]*\."me=e-1 +syn match scalaMethodCall "\.[a-z][_$a-zA-Z0-9]*"ms=s+1 + +" type declarations in val/var/def +syn match scalaType ":\s*\(=>\s*\)\?[._$a-zA-Z0-9]\+\(\[[^]]*\]\+\)\?\(\s*\(<:\|>:\|#\|=>\)\s*[._$a-zA-Z0-9]\+\(\[[^]]*\]\+\)*\)*"ms=s+1 + +" comments +syn match scalaTodo "[tT][oO][dD][oO]" contained +syn match scalaLineComment "//.*" contains=scalaTodo +syn region scalaComment start="/\*" end="\*/" contains=scalaTodo +syn case ignore +syn include @scalaHtml syntax/html.vim +unlet b:current_syntax +syn case match +syn region scalaDocComment start="/\*\*" end="\*/" contains=scalaDocTags,scalaTodo,@scalaHtml keepend +syn region scalaDocTags start="{@\(link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}" contained +syn match scalaDocTags "@[a-z]\+" contained + +syn match scalaEmptyString "\"\"" + +" multi-line string literals +syn region scalaMultiLineString start="\"\"\"" end="\"\"\"" contains=scalaUnicode +syn match scalaUnicode "\\u[0-9a-fA-F]\{4}" contained + +" string literals with escapes +syn region scalaString start="\"[^"]" skip="\\\"" end="\"" contains=scalaStringEscape " TODO end \n or not? +syn match scalaStringEscape "\\u[0-9a-fA-F]\{4}" contained +syn match scalaStringEscape "\\[nrfvb\\\"]" contained + +" symbol and character literals +syn match scalaSymbol "'[_a-zA-Z0-9][_a-zA-Z0-9]*\>" +syn match scalaChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'" + +" number literals +syn match scalaNumber "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>" +syn match scalaNumber "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\=" +syn match scalaNumber "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>" +syn match scalaNumber "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>" + +" xml literals +syn match scalaXmlTag "<[a-zA-Z]\_[^>]*/>" contains=scalaXmlQuote,scalaXmlEscape,scalaXmlString +syn region scalaXmlString start="\"" end="\"" contained +syn match scalaXmlStart "<[a-zA-Z]\_[^>]*>" contained contains=scalaXmlQuote,scalaXmlEscape,scalaXmlString +syn region scalaXml start="<\([a-zA-Z]\_[^>]*\_[^/]\|[a-zA-Z]\)>" matchgroup=scalaXmlStart end="]\+>" contains=scalaXmlEscape,scalaXmlQuote,scalaXml,scalaXmlStart,scalaXmlComment +syn region scalaXmlEscape matchgroup=scalaXmlEscapeSpecial start="{" matchgroup=scalaXmlEscapeSpecial end="}" contained contains=TOP +syn match scalaXmlQuote "&[^;]\+;" contained +syn match scalaXmlComment "" contained + +syn sync fromstart + +" map Scala groups to standard groups +hi link scalaKeyword Keyword +hi link scalaPackage Include +hi link scalaImport Include +hi link scalaBoolean Boolean +hi link scalaOperator Normal +hi link scalaNumber Number +hi link scalaEmptyString String +hi link scalaString String +hi link scalaChar String +hi link scalaMultiLineString String +hi link scalaStringEscape Special +hi link scalaSymbol Special +hi link scalaUnicode Special +hi link scalaComment Comment +hi link scalaLineComment Comment +hi link scalaDocComment Comment +hi link scalaDocTags Special +hi link scalaTodo Todo +hi link scalaType Type +hi link scalaTypeSpecializer scalaType +hi link scalaXml String +hi link scalaXmlTag Include +hi link scalaXmlString String +hi link scalaXmlStart Include +hi link scalaXmlEscape Normal +hi link scalaXmlEscapeSpecial Special +hi link scalaXmlQuote Special +hi link scalaXmlComment Comment +hi link scalaDef Keyword +hi link scalaVar Keyword +hi link scalaVal Keyword +hi link scalaClass Keyword +hi link scalaObject Keyword +hi link scalaTrait Keyword +hi link scalaDefName Function +hi link scalaDefSpecializer Function +hi link scalaClassName Special +hi link scalaClassSpecializer Special +hi link scalaConstructor Special +hi link scalaConstructorSpecializer scalaConstructor + +let b:current_syntax = "scala" + +" you might like to put these lines in your .vimrc +" +" customize colors a little bit (should be a different file) +" hi scalaNew gui=underline +" hi scalaMethodCall gui=italic +" hi scalaValName gui=underline +" hi scalaVarName gui=underline