1- " Language: CoffeeScript
2- " Maintainer: Mick Koch <kchmck@gmail.com>
3- " URL: http://github.com/kchmck/vim-coffee-script
1+ " Language: MoonScript
2+ " Maintainer: leafo <leafot@gmail.com>
3+ " Based On: CoffeeScript by Mick Koch <kchmck@gmail.com>
4+ " URL: http://github.com/leafo/moonscript-vim
45" License: WTFPL
56
67if exists (" b:did_indent" )
@@ -10,19 +11,18 @@ endif
1011let b: did_indent= 1
1112
1213setlocal autoindent
13- setlocal indentexpr = GetCoffeeIndent (v: lnum )
14- " Make sureGetCoffeeIndent is run when these are typed so they can be
14+ setlocal indentexpr = GetMoonIndent (v: lnum )
15+ " Make sureGetMoonIndent is run when these are typed so they can be
1516" indented or outdented.
16- setlocal indentkeys += 0 ],0 ),0 .,= else ,= when, = catch , = finally
17+ setlocal indentkeys += 0 ],0 ),0 .,= else ,= elseif
1718
1819" Only define the function once.
19- if exists (" *GetCoffeeIndent " )
20+ if exists (" *GetMoonIndent " )
2021finish
2122endif
2223
2324" Keywords to indent after
24- let s: INDENT_AFTER_KEYWORD= ' ^\%(if\|unless\|else\|for\|while\|until\|'
25- \ .' loop\|switch\|when\|try\|catch\|finally\|'
25+ let s: INDENT_AFTER_KEYWORD= ' ^\%(if\|else\|for\|while\|with\|elseif\|'
2626\ .' class\)\>'
2727
2828" Operators to indent after
@@ -41,27 +41,27 @@ let s:CONTINUATION_BLOCK = '[([{:=]$'
4141let s: DOT_ACCESS= ' ^\.'
4242
4343" Keywords to outdent after
44- let s: OUTDENT_AFTER= ' ^\%(return\|break\|continue\|throw\ )\>'
44+ let s: OUTDENT_AFTER= ' ^\%(return\|break\)\>'
4545
4646" A compound assignment like `... = if ...`
47- let s: COMPOUND_ASSIGNMENT= ' [:=]\s*\%(if\|unless\| for\|while\|until \|'
48- \ .' switch\|try \|class\)\>'
47+ let s: COMPOUND_ASSIGNMENT= ' [:=]\s*\%(if\|for\|while\|'
48+ \ .' with \|class\)\>'
4949
5050" A postfix condition like `return ... if ...`.
51- let s: POSTFIX_CONDITION= ' \S\s\+\zs\<\%(if\|unless\ )\>'
51+ let s: POSTFIX_CONDITION= ' \S\s\+\zs\<\%(if\)\>'
5252
5353" A single-line else statement like `else ...` but not `else if ...
54- let s: SINGLE_LINE_ELSE= ' ^else\s\+\%(\<\%(if\|unless\ )\>\)\@!'
54+ let s: SINGLE_LINE_ELSE= ' ^else\s\+\%(\<\%(if\)\>\)\@!'
5555
5656" Max lines to look back for a match
5757let s: MAX_LOOKBACK= 50
5858
5959" Syntax names for strings
60- let s: SYNTAX_STRING= ' coffee \%(String\|AssignString\|Embed\|Regex\|Heregex\|'
60+ let s: SYNTAX_STRING= ' moon \%(String\|AssignString\|Embed\|Regex\|Heregex\|'
6161\ .' Heredoc\)'
6262
6363" Syntax names for comments
64- let s: SYNTAX_COMMENT= ' coffee \%(Comment\|BlockComment\|HeregexComment\)'
64+ let s: SYNTAX_COMMENT= ' moon \%(Comment\|BlockComment\|HeregexComment\)'
6565
6666" Syntax names for strings and comments
6767let s: SYNTAX_STRING_COMMENT= s: SYNTAX_STRING .' \|' .s: SYNTAX_COMMENT
@@ -173,10 +173,10 @@ function! s:GetMatch(curline)
173173return s: SearchPair (' \[' ,' \]' )
174174elseif a: curline= ~' ^else\>'
175175return s: SearchPair (' \<\%(if\|unless\|when\)\>' ,' \<else\>' )
176- elseif a: curline= ~' ^catch\>'
177- return s: SearchPair (' \<try\>' ,' \<catch\>' )
178- elseif a: curline= ~' ^finally\>'
179- return s: SearchPair (' \<try\>' ,' \<finally\>' )
176+ " elseif a:curline =~ '^catch\>'
177+ " return s:SearchPair('\<try\>', '\<catch\>')
178+ " elseif a:curline =~ '^finally\>'
179+ " return s:SearchPair('\<try\>', '\<finally\>')
180180endif
181181
182182return 0
@@ -232,7 +232,7 @@ function! s:GetTrimmedLine(linenum)
232232\ ' \s\+$' ,' ' ,' ' )
233233endfunction
234234
235- function ! s: GetCoffeeIndent (curlinenum)
235+ function ! s: GetMoonIndent (curlinenum)
236236let prevlinenum= s: GetPrevNormalLine (a: curlinenum )
237237
238238" Don't do anything if there's no previous line.
@@ -249,20 +249,20 @@ function! s:GetCoffeeIndent(curlinenum)
249249return indent (matchlinenum)
250250endif
251251
252- " Try to find a matching `when`.
253- if curline= ~' ^when\>' && ! s: SmartSearch (prevlinenum,' \<switch\>' )
254- let linenum= a: curlinenum
255-
256- while linenum > 0
257- let linenum= s: GetPrevNormalLine (linenum)
258-
259- if getline (linenum)= ~' ^\s*when\>'
260- return indent (linenum)
261- endif
262- endwhile
263-
264- return -1
265- endif
252+ " " Try to find a matching `when`.
253+ " if curline =~ '^when\>' && !s:SmartSearch(prevlinenum, '\<switch\>')
254+ " let linenum = a:curlinenum
255+ "
256+ " while linenum > 0
257+ " let linenum = s:GetPrevNormalLine(linenum)
258+ "
259+ " if getline(linenum) =~ '^\s*when\>'
260+ " return indent(linenum)
261+ " endif
262+ " endwhile
263+ "
264+ " return -1
265+ " endif
266266
267267let prevline= s: GetTrimmedLine (prevlinenum)
268268let previndent= indent (prevlinenum)
@@ -312,10 +312,10 @@ function! s:GetCoffeeIndent(curlinenum)
312312return -1
313313endfunction
314314
315- " Wrap s:GetCoffeeIndent to keep the cursor position.
316- function ! GetCoffeeIndent (curlinenum)
315+ " Wrap s:GetMoonIndent to keep the cursor position.
316+ function ! GetMoonIndent (curlinenum)
317317let oldcursor= getpos (' .' )
318- let indent = s: GetCoffeeIndent (a: curlinenum )
318+ let indent = s: GetMoonIndent (a: curlinenum )
319319call setpos (' .' , oldcursor)
320320
321321return indent