[Assorted-commits] SF.net SVN: assorted:[1801] configs/trunk/src/vim
Brought to you by:
yangzhang
From: <yan...@us...> - 2011-07-21 04:50:47
|
Revision: 1801 http://assorted.svn.sourceforge.net/assorted/?rev=1801&view=rev Author: yangzhang Date: 2011-07-21 04:50:40 +0000 (Thu, 21 Jul 2011) Log Message: ----------- Add coffeescript vim support Added Paths: ----------- configs/trunk/src/vim/after/syntax/ configs/trunk/src/vim/after/syntax/html.vim configs/trunk/src/vim/ftdetect/coffee.vim configs/trunk/src/vim/ftdetect/eco.vim configs/trunk/src/vim/ftplugin/coffee.vim configs/trunk/src/vim/indent/coffee.vim configs/trunk/src/vim/syntax/coffee.vim configs/trunk/src/vim/syntax/eco.vim Added: configs/trunk/src/vim/after/syntax/html.vim =================================================================== --- configs/trunk/src/vim/after/syntax/html.vim (rev 0) +++ configs/trunk/src/vim/after/syntax/html.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,19 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kc...@gm...> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +if !exists("main_syntax") + let main_syntax = 'html' +endif + +" Syntax highlighting for text/coffeescript script tags +unlet b:current_syntax +syn include @htmlCoffeeScript syntax/coffee.vim +unlet b:current_syntax +syn region javaScript start=+<script [^>]*type *=[^>]*text/coffeescript[^>]*>+ keepend end=+</script>+me=s-1 contains=@htmlCoffeeScript,htmlScriptTag,@htmlPreproc +let b:current_syntax = "html" + +if main_syntax == 'html' + unlet main_syntax +endif Added: configs/trunk/src/vim/ftdetect/coffee.vim =================================================================== --- configs/trunk/src/vim/ftdetect/coffee.vim (rev 0) +++ configs/trunk/src/vim/ftdetect/coffee.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,7 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kc...@gm...> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +autocmd BufNewFile,BufRead *.coffee set filetype=coffee +autocmd BufNewFile,BufRead *Cakefile set filetype=coffee Added: configs/trunk/src/vim/ftdetect/eco.vim =================================================================== --- configs/trunk/src/vim/ftdetect/eco.vim (rev 0) +++ configs/trunk/src/vim/ftdetect/eco.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.eco set filetype=eco Added: configs/trunk/src/vim/ftplugin/coffee.vim =================================================================== --- configs/trunk/src/vim/ftplugin/coffee.vim (rev 0) +++ configs/trunk/src/vim/ftplugin/coffee.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,137 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kc...@gm...> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +if exists("b:did_ftplugin") + finish +endif + +let b:did_ftplugin = 1 + +" Don't let new windows overwrite these. +if !exists("s:coffee_compile_prev_buf") + " Buffer and cursor position before the `CoffeeCompile` buffer was opened + let s:coffee_compile_prev_buf = -1 + let s:coffee_compile_prev_pos = [] + " Previously-opened `CoffeeCompile` buffer + let s:coffee_compile_buf = -1 +endif + +setlocal formatoptions-=t formatoptions+=croql +setlocal comments=:# +setlocal commentstring=#\ %s + +setlocal errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l, + \Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m, + \SyntaxError:\ In\ %f\\,\ %m, + \%-G%.%# + +" Fold by indentation, but only if enabled. +setlocal foldmethod=indent + +if !exists("coffee_folding") + setlocal nofoldenable +endif + +" Extra options passed to `CoffeeMake` +if !exists("coffee_make_options") + let coffee_make_options = "" +endif + +" Update `makeprg` for the current filename. This is needed to support filenames +" with spaces and quotes while also supporting generic `make`. +function! s:SetMakePrg() + let &l:makeprg = "coffee -c " . g:coffee_make_options . ' $* ' + \ . fnameescape(expand('%')) +endfunction + +" Set `makeprg` initially. +call s:SetMakePrg() +" Reset `makeprg` on rename. +autocmd BufFilePost,BufWritePost,FileWritePost <buffer> call s:SetMakePrg() + +" Save the cursor position. +function! s:CoffeeCompileSavePos() + let buf = bufnr('%') + + if buf != s:coffee_compile_buf + let s:coffee_compile_prev_buf = buf + let s:coffee_compile_prev_pos = getpos('.') + endif +endfunction + +" Try to reset the cursor position. +function! s:CoffeeCompileResetPos() + let win = bufwinnr(s:coffee_compile_prev_buf) + + if win != -1 + exec win 'wincmd w' + call setpos('.', s:coffee_compile_prev_pos) + endif + + autocmd! CoffeeCompileSavePos +endfunction + +" Compile some CoffeeScript and show it in a scratch buffer. We handle ranges +" like this to stop the cursor from being moved before the function is called. +function! s:CoffeeCompile(startline, endline) + " Store the current buffer and cursor. + call s:CoffeeCompileSavePos() + + " Build stdin lines. + let lines = join(getline(a:startline, a:endline), "\n") + " Get compiler output. + let output = system('coffee -scb 2>&1', lines) + + " Use at most half of the screen. + let max_height = winheight('%') / 2 + " Try to get the old window. + let win = bufwinnr(s:coffee_compile_buf) + + if win == -1 + " Make a new window and store its ID. + botright new + let s:coffee_compile_buf = bufnr('%') + + setlocal bufhidden=wipe buftype=nofile + setlocal nobuflisted noswapfile nowrap + + autocmd BufWipeout <buffer> call s:CoffeeCompileResetPos() + nnoremap <buffer> <silent> q :hide<CR> + + " Save the cursor position on each buffer switch. + augroup CoffeeCompileSavePos + autocmd BufEnter,BufLeave * call s:CoffeeCompileSavePos() + augroup END + else + " Move to the old window and clear the buffer. + exec win 'wincmd w' + setlocal modifiable + exec '% delete _' + endif + + " Paste in the output and delete the last empty line. + put! =output + exec '$ delete _' + + exec 'resize' min([max_height, line('$') + 1]) + call cursor(1, 1) + + if v:shell_error + " A compile error occurred. + setlocal filetype= + else + " Coffee was compiled successfully. + setlocal filetype=javascript + endif + + setlocal nomodifiable +endfunction + +" Peek at compiled CoffeeScript. +command! -range=% -bar CoffeeCompile call s:CoffeeCompile(<line1>, <line2>) +" Compile the current file. +command! -bang -bar -nargs=* CoffeeMake make<bang> <args> +" Run some CoffeeScript. +command! -range=% -bar CoffeeRun <line1>,<line2>:w !coffee -s Added: configs/trunk/src/vim/indent/coffee.vim =================================================================== --- configs/trunk/src/vim/indent/coffee.vim (rev 0) +++ configs/trunk/src/vim/indent/coffee.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,322 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kc...@gm...> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +if exists("b:did_indent") + finish +endif + +let b:did_indent = 1 + +setlocal autoindent +setlocal indentexpr=GetCoffeeIndent(v:lnum) +" Make sure GetCoffeeIndent is run when these are typed so they can be +" indented or outdented. +setlocal indentkeys+=0],0),0.,=else,=when,=catch,=finally + +" Only define the function once. +if exists("*GetCoffeeIndent") + finish +endif + +" Keywords to indent after +let s:INDENT_AFTER_KEYWORD = '^\%(if\|unless\|else\|for\|while\|until\|' +\ . 'loop\|switch\|when\|try\|catch\|finally\|' +\ . 'class\)\>' + +" Operators to indent after +let s:INDENT_AFTER_OPERATOR = '\%([([{:=]\|[-=]>\)$' + +" Keywords and operators that continue a line +let s:CONTINUATION = '\<\%(is\|isnt\|and\|or\)\>$' +\ . '\|' +\ . '\%(-\@<!-\|+\@<!+\|<\|[-=]\@<!>\|\*\|/\@<!/\|%\||\|' +\ . '&\|,\|\.\@<!\.\)$' + +" Operators that block continuation indenting +let s:CONTINUATION_BLOCK = '[([{:=]$' + +" A continuation dot access +let s:DOT_ACCESS = '^\.' + +" Keywords to outdent after +let s:OUTDENT_AFTER = '^\%(return\|break\|continue\|throw\)\>' + +" A compound assignment like `... = if ...` +let s:COMPOUND_ASSIGNMENT = '[:=]\s*\%(if\|unless\|for\|while\|until\|' +\ . 'switch\|try\|class\)\>' + +" A postfix condition like `return ... if ...`. +let s:POSTFIX_CONDITION = '\S\s\+\zs\<\%(if\|unless\)\>' + +" A single-line else statement like `else ...` but not `else if ... +let s:SINGLE_LINE_ELSE = '^else\s\+\%(\<\%(if\|unless\)\>\)\@!' + +" Max lines to look back for a match +let s:MAX_LOOKBACK = 50 + +" Syntax names for strings +let s:SYNTAX_STRING = 'coffee\%(String\|AssignString\|Embed\|Regex\|Heregex\|' +\ . 'Heredoc\)' + +" Syntax names for comments +let s:SYNTAX_COMMENT = 'coffee\%(Comment\|BlockComment\|HeregexComment\)' + +" Syntax names for strings and comments +let s:SYNTAX_STRING_COMMENT = s:SYNTAX_STRING . '\|' . s:SYNTAX_COMMENT + +" Get the linked syntax name of a character. +function! s:SyntaxName(linenum, col) + return synIDattr(synID(a:linenum, a:col, 1), 'name') +endfunction + +" Check if a character is in a comment. +function! s:IsComment(linenum, col) + return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_COMMENT +endfunction + +" Check if a character is in a string. +function! s:IsString(linenum, col) + return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_STRING +endfunction + +" Check if a character is in a comment or string. +function! s:IsCommentOrString(linenum, col) + return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_STRING_COMMENT +endfunction + +" Check if a whole line is a comment. +function! s:IsCommentLine(linenum) + " Check the first non-whitespace character. + return s:IsComment(a:linenum, indent(a:linenum) + 1) +endfunction + +" Repeatedly search a line for a regex until one is found outside a string or +" comment. +function! s:SmartSearch(linenum, regex) + " Start at the first column. + let col = 0 + + " Search until there are no more matches, unless a good match is found. + while 1 + call cursor(a:linenum, col + 1) + let [_, col] = searchpos(a:regex, 'cn', a:linenum) + + " No more matches. + if !col + break + endif + + if !s:IsCommentOrString(a:linenum, col) + return 1 + endif + endwhile + + " No good match found. + return 0 +endfunction + +" Skip a match if it's in a comment or string, is a single-line statement that +" isn't adjacent, or is a postfix condition. +function! s:ShouldSkip(startlinenum, linenum, col) + if s:IsCommentOrString(a:linenum, a:col) + return 1 + endif + + " Check for a single-line statement that isn't adjacent. + if s:SmartSearch(a:linenum, '\<then\>') && a:startlinenum - a:linenum > 1 + return 1 + endif + + if s:SmartSearch(a:linenum, s:POSTFIX_CONDITION) && + \ !s:SmartSearch(a:linenum, s:COMPOUND_ASSIGNMENT) + return 1 + endif + + return 0 +endfunction + +" Find the farthest line to look back to, capped to line 1 (zero and negative +" numbers cause bad things). +function! s:MaxLookback(startlinenum) + return max([1, a:startlinenum - s:MAX_LOOKBACK]) +endfunction + +" Get the skip expression for searchpair(). +function! s:SkipExpr(startlinenum) + return "s:ShouldSkip(" . a:startlinenum . ", line('.'), col('.'))" +endfunction + +" Search for pairs of text. +function! s:SearchPair(start, end) + " The cursor must be in the first column for regexes to match. + call cursor(0, 1) + + let startlinenum = line('.') + + " Don't need the W flag since MaxLookback caps the search to line 1. + return searchpair(a:start, '', a:end, 'bcn', + \ s:SkipExpr(startlinenum), + \ s:MaxLookback(startlinenum)) +endfunction + +" Try to find a previous matching line. +function! s:GetMatch(curline) + let firstchar = a:curline[0] + + if firstchar == '}' + return s:SearchPair('{', '}') + elseif firstchar == ')' + return s:SearchPair('(', ')') + elseif firstchar == ']' + return s:SearchPair('\[', '\]') + elseif a:curline =~ '^else\>' + return s:SearchPair('\<\%(if\|unless\|when\)\>', '\<else\>') + elseif a:curline =~ '^catch\>' + return s:SearchPair('\<try\>', '\<catch\>') + elseif a:curline =~ '^finally\>' + return s:SearchPair('\<try\>', '\<finally\>') + endif + + return 0 +endfunction + +" Get the nearest previous line that isn't a comment. +function! s:GetPrevNormalLine(startlinenum) + let curlinenum = a:startlinenum + + while curlinenum > 0 + let curlinenum = prevnonblank(curlinenum - 1) + + if !s:IsCommentLine(curlinenum) + return curlinenum + endif + endwhile + + return 0 +endfunction + +" Try to find a comment in a line. +function! s:FindComment(linenum) + let col = 0 + + while 1 + call cursor(a:linenum, col + 1) + let [_, col] = searchpos('#', 'cn', a:linenum) + + if !col + break + endif + + if s:IsComment(a:linenum, col) + return col + endif + endwhile + + return 0 +endfunction + +" Get a line without comments or surrounding whitespace. +function! s:GetTrimmedLine(linenum) + let comment = s:FindComment(a:linenum) + let line = getline(a:linenum) + + if comment + " Subtract 1 to get to the column before the comment and another 1 for + " zero-based indexing. + let line = line[:comment - 2] + endif + + return substitute(substitute(line, '^\s\+', '', ''), + \ '\s\+$', '', '') +endfunction + +function! s:GetCoffeeIndent(curlinenum) + let prevlinenum = s:GetPrevNormalLine(a:curlinenum) + + " Don't do anything if there's no previous line. + if !prevlinenum + return -1 + endif + + let curline = s:GetTrimmedLine(a:curlinenum) + + " Try to find a previous matching statement. This handles outdenting. + let matchlinenum = s:GetMatch(curline) + + if matchlinenum + return indent(matchlinenum) + endif + + " Try to find a matching `when`. + if curline =~ '^when\>' && !s:SmartSearch(prevlinenum, '\<switch\>') + let linenum = a:curlinenum + + while linenum > 0 + let linenum = s:GetPrevNormalLine(linenum) + + if getline(linenum) =~ '^\s*when\>' + return indent(linenum) + endif + endwhile + + return -1 + endif + + let prevline = s:GetTrimmedLine(prevlinenum) + let previndent = indent(prevlinenum) + + " Always indent after these operators. + if prevline =~ s:INDENT_AFTER_OPERATOR + return previndent + &shiftwidth + endif + + " Indent after a continuation if it's the first. + if prevline =~ s:CONTINUATION + let prevprevlinenum = s:GetPrevNormalLine(prevlinenum) + let prevprevline = s:GetTrimmedLine(prevprevlinenum) + + if prevprevline !~ s:CONTINUATION && prevprevline !~ s:CONTINUATION_BLOCK + return previndent + &shiftwidth + endif + + return -1 + endif + + " Indent after these keywords and compound assignments if they aren't a + " single-line statement. + if prevline =~ s:INDENT_AFTER_KEYWORD || prevline =~ s:COMPOUND_ASSIGNMENT + if !s:SmartSearch(prevlinenum, '\<then\>') && prevline !~ s:SINGLE_LINE_ELSE + return previndent + &shiftwidth + endif + + return -1 + endif + + " Indent a dot access if it's the first. + if curline =~ s:DOT_ACCESS && prevline !~ s:DOT_ACCESS + return previndent + &shiftwidth + endif + + " Outdent after these keywords if they don't have a postfix condition or are + " a single-line statement. + if prevline =~ s:OUTDENT_AFTER + if !s:SmartSearch(prevlinenum, s:POSTFIX_CONDITION) || + \ s:SmartSearch(prevlinenum, '\<then\>') + return previndent - &shiftwidth + endif + endif + + " No indenting or outdenting is needed. + return -1 +endfunction + +" Wrap s:GetCoffeeIndent to keep the cursor position. +function! GetCoffeeIndent(curlinenum) + let oldcursor = getpos('.') + let indent = s:GetCoffeeIndent(a:curlinenum) + call setpos('.', oldcursor) + + return indent +endfunction Added: configs/trunk/src/vim/syntax/coffee.vim =================================================================== --- configs/trunk/src/vim/syntax/coffee.vim (rev 0) +++ configs/trunk/src/vim/syntax/coffee.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,214 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kc...@gm...> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +if exists("b:current_syntax") + finish +endif + +if version < 600 + syn clear +endif + +" Include JavaScript for coffeeEmbed. +syn include @coffeeJS syntax/javascript.vim + +" Highlight long strings. +syn sync minlines=100 + +" CoffeeScript allows dollar signs in identifiers. +setlocal isident+=$ + +" These are `matches` instead of `keywords` because vim's highlighting +" priority for keywords is higher than matches. This causes keywords to be +" highlighted inside matches, even if a match says it shouldn't contain them -- +" like with coffeeAssign and coffeeDot. +syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ +hi def link coffeeStatement Statement + +syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ +hi def link coffeeRepeat Repeat + +syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/ +hi def link coffeeConditional Conditional + +syn match coffeeException /\<\%(try\|catch\|finally\)\>/ +hi def link coffeeException Exception + +syntax match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ +hi def link coffeeOperator Operator + +syn match coffeeKeyword /\<\%(new\|in\|of\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|own\|do\)\>/ +hi def link coffeeKeyword Keyword + +syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ +hi def link coffeeBoolean Boolean + +syn match coffeeGlobal /\<\%(null\|undefined\)\>/ +hi def link coffeeGlobal Type + +" Keywords reserved by the language +syn cluster coffeeReserved contains=coffeeStatement,coffeeRepeat, +\ coffeeConditional,coffeeException, +\ coffeeOperator,coffeeKeyword, +\ coffeeBoolean,coffeeGlobal + +" A special variable +syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ +" An @-variable +syn match coffeeSpecialVar /@\%(\I\i*\)\?/ +hi def link coffeeSpecialVar Type + +" A class-like name that starts with a capital letter +syn match coffeeObject /\<\u\w*\>/ +hi def link coffeeObject Structure + +" A constant-like name in SCREAMING_CAPS +syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ +hi def link coffeeConstant Constant + +" A variable name +syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeObject, +\ coffeeConstant,coffeePrototype + +" A non-interpolated string +syn cluster coffeeBasicString contains=@Spell,coffeeEscape +" An interpolated string +syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp + +" Regular strings +syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/ +\ contains=@coffeeInterpString +syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/ +\ contains=@coffeeBasicString +hi def link coffeeString String + +" A integer, including a leading plus or minus +syn match coffeeNumber /\i\@<![-+]\?\d\+\%([eE][+-]\?\d\+\)\?/ +" A hex number +syn match coffeeNumber /\<0[xX]\x\+\>/ +hi def link coffeeNumber Number + +" A floating-point number, including a leading plus or minus +syn match coffeeFloat /\i\@<![-+]\?\d*\.\@<!\.\d\+\%([eE][+-]\?\d\+\)\?/ +hi def link coffeeFloat Float + +syn match coffeeAssignSymbols /:\@<!::\@!\|++\|--\|\%(\s\zs\%(and\|or\)\|&&\|||\|?\|+\|-\|\/\|\*\|%\|<<\|>>\|>>>\|&\||\|\^\)\?=\@<!==\@!>\@!/ +\ contained +hi def link coffeeAssignSymbols SpecialChar + +syn match coffeeAssignBrackets /\[.\+\]/ contained contains=TOP,coffeeAssign + +" A destructuring assignment +syn match coffeeAssign /[}\]]\@<=\s*==\@!>\@!/ contains=coffeeAssignSymbols +" A pre-increment or pre-decrement assignment +syn match coffeeAssign /\%(++\|--\)\s*\%(@\|@\?\I\)\%(\i\|::\|\.\|?\|\[.\+\]\)*/ +\ contains=@coffeeIdentifier,coffeeAssignSymbols, +\ coffeeAssignBrackets +" A normal assignment, or a post-increment or post-decrement assignment +syn match coffeeAssign /\%(@\|@\?\I\)\%(\i\|::\|\.\|?\|\[.\+\]\)*\%(++\|--\|\s*\%(and\|or\|&&\|||\|?\|+\|-\|\/\|\*\|%\|<<\|>>\|>>>\|&\||\|\^\)\?=\@<!==\@!>\@!\)/ +\ contains=@coffeeIdentifier,coffeeAssignSymbols, +\ coffeeAssignBrackets +hi def link coffeeAssign Identifier + +" An error for reserved keywords +if !exists("coffee_no_reserved_words_error") + syn match coffeeReservedError /\<\%(case\|default\|function\|var\|void\|with\|const\|let\|enum\|export\|import\|native\|__hasProp\|__extends\|__slice\|__bind\|__indexOf\)\>/ + hi def link coffeeReservedError Error +endif + +" A normal object assignment +syn match coffeeObjAssign /@\?\I\i*\s*:\@<!::\@!/ +\ contains=@coffeeIdentifier,coffeeAssignSymbols +hi def link coffeeObjAssign coffeeAssign + +" Strings used in string assignments, which can't have interpolations +syn region coffeeAssignString start=/"/ skip=/\\\\\|\\"/ end=/"/ +\ contained contains=@coffeeBasicString +syn region coffeeAssignString start=/'/ skip=/\\\\\|\\'/ end=/'/ +\ contained contains=@coffeeBasicString +hi def link coffeeAssignString String + +" An object-string assignment +syn match coffeeObjStringAssign /\("\|'\)[^\1]*\1\s*;\@<!::\@!'\@!/ +\ contains=coffeeAssignString,coffeeAssignSymbols +" An object-integer assignment +syn match coffeeObjNumberAssign /\d\+\%(\.\d\+\)\?\s*:\@<!::\@!/ +\ contains=coffeeNumber,coffeeAssignSymbols + +syn match coffeePrototype /::/ +hi def link coffeePrototype SpecialChar + +syn match coffeeFunction /[-=]>/ +hi def link coffeeFunction Function + +syn keyword coffeeTodo TODO FIXME XXX contained +hi def link coffeeTodo Todo + +syn match coffeeComment /#.*/ contains=@Spell,coffeeTodo +hi def link coffeeComment Comment + +syn region coffeeBlockComment start=/####\@!/ end=/###/ +\ contains=@Spell,coffeeTodo +hi def link coffeeBlockComment coffeeComment + +" A comment in a heregex +syn region coffeeHeregexComment start=/#/ end=/\ze\/\/\/\|$/ +\ contained contains=@Spell,coffeeTodo +hi def link coffeeHeregexComment coffeeComment + +" Embedded JavaScript +syn region coffeeEmbed matchgroup=coffeeEmbedDelim +\ start=/`/ skip=/\\\\\|\\`/ end=/`/ +\ contains=@coffeeJS +hi def link coffeeEmbedDelim Delimiter + +syn region coffeeInterp matchgroup=coffeeInterpDelim +\ start=/\#{/ end=/}/ +\ contained contains=TOP +hi def link coffeeInterpDelim Delimiter + +" A string escape sequence +syn match coffeeEscape /\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\./ contained +hi def link coffeeEscape SpecialChar + +" A regex -- must not follow a parenthesis, number, or identifier, and must not +" be followed by a number +syn region coffeeRegex start=/\%(\%()\|\i\@<!\d\)\s*\|\i\)\@<!\/\s\@!/ +\ skip=/\[[^\]]\{-}\/[^\]]\{-}\]/ +\ end=/\/[gimy]\{,4}\d\@!/ +\ oneline contains=@coffeeBasicString +hi def link coffeeRegex String + +" A heregex +syn region coffeeHeregex start=/\/\/\// end=/\/\/\/[gimy]\{,4}/ +\ contains=@coffeeInterpString,coffeeHeregexComment +\ fold +hi def link coffeeHeregex coffeeRegex + +" Heredoc strings +syn region coffeeHeredoc start=/"""/ end=/"""/ contains=@coffeeInterpString +\ fold +syn region coffeeHeredoc start=/'''/ end=/'''/ contains=@coffeeBasicString +\ fold +hi def link coffeeHeredoc String + +" An error for trailing whitespace, as long as the line isn't just whitespace +if !exists("coffee_no_trailing_space_error") + syn match coffeeSpaceError /\S\@<=\s\+$/ display + hi def link coffeeSpaceError Error +endif + +" An error for trailing semicolons, for help transitioning from JavaScript +if !exists("coffee_no_trailing_semicolon_error") + syn match coffeeSemicolonError /;$/ display + hi def link coffeeSemicolonError Error +endif + +" Ignore reserved words in dot-properties. +syn match coffeeDot /\.\@<!\.\i\+/ contains=ALLBUT,@coffeeReserved, +\ coffeeReservedError +\ transparent + +let b:current_syntax = "coffee" Property changes on: configs/trunk/src/vim/syntax/coffee.vim ___________________________________________________________________ Added: svn:executable + * Added: configs/trunk/src/vim/syntax/eco.vim =================================================================== --- configs/trunk/src/vim/syntax/eco.vim (rev 0) +++ configs/trunk/src/vim/syntax/eco.vim 2011-07-21 04:50:40 UTC (rev 1801) @@ -0,0 +1,62 @@ +" Vim syntax file +" Language: eco +" Maintainer: Jay Adkisson +" Mostly stolen from eruby.vim + +if !exists("g:eco_default_subtype") + let g:eco_default_subtype = "html" +endif + +if !exists("b:eco_subtype") + let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") + let b:eco_subtype = matchstr(s:lines,'eco_subtype=\zs\w\+') + if b:eco_subtype == '' + let b:eco_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eco\)\+$','',''),'\.\zs\w\+$') + endif + if b:eco_subtype == 'rhtml' + let b:eco_subtype = 'html' + elseif b:eco_subtype == 'rb' + let b:eco_subtype = 'ruby' + elseif b:eco_subtype == 'yml' + let b:eco_subtype = 'yaml' + elseif b:eco_subtype == 'js' || b:eco_subtype == 'json' + let b:eco_subtype = 'javascript' + elseif b:eco_subtype == 'txt' + " Conventional; not a real file type + let b:eco_subtype = 'text' + elseif b:eco_subtype == '' + if exists('b:current_syntax') && b:current_syntax != '' + let b:eco_subtype = b:current_syntax + else + let b:eco_subtype = g:eco_default_subtype + endif + endif +endif + +if exists("b:eco_subtype") && b:eco_subtype != '' && b:eco_subtype != 'eco' + exec "runtime! syntax/".b:eco_subtype.".vim" + let b:current_syntax = "eco" +endif + +syn include @coffeeTop syntax/coffee.vim + +syn cluster ecoRegions contains=ecoBlock,ecoExpression,ecoComment + +syn region ecoBlock matchgroup=ecoDelimiter start=/<%/ end=/%>/ contains=@coffeeTop containedin=ALLBUT,@ecoRegions keepend +syn region ecoExpression matchgroup=ecoDelimiter start=/<%[=\-]/ end=/%>/ contains=@coffeeTop containedin=ALLBUT,@ecoRegions keepend +syn region ecoComment matchgroup=ecoComment start=/<%#/ end=/%>/ contains=@coffeeTodo,@Spell containedin=ALLBUT,@ecoRegions keepend + +" eco features not in coffeescript proper +syn keyword ecoEnd end containedin=@ecoRegions +syn match ecoIndentColon /\s+\w+:/ containedin=@ecoRegions + +" Define the default highlighting. + +hi def link ecoDelimiter Delimiter +hi def link ecoComment Comment +hi def link ecoEnd coffeeConditional +hi def link ecoIndentColon None + +let b:current_syntax = 'eco' + +" vim: nowrap sw=2 sts=2 ts=8: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |