-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrescript.vim
More file actions
62 lines (51 loc) · 1.29 KB
/
rescript.vim
File metadata and controls
62 lines (51 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nolisp
setlocal indentexpr=RescriptIndent(v:lnum)
if exists('*RescriptIndent')
finish
endif
function! SkipRescriptBlanksAndComments(startline)
let lnum = a:startline
while lnum > 1
let lnum = prevnonblank(lnum)
if getline(lnum) =~ '\*/\s*$'
while getline(lnum) !~ '/\*' && lnum > 1
let lnum = lnum - 1
endwhile
if getline(lnum) =~ '^\s*/\*'
let lnum = lnum - 1
else
break
endif
elseif getline(lnum) =~ '^\s*//'
let lnum = lnum - 1
else
break
endif
endwhile
return lnum
endfunction
function! RescriptIndent(lnum)
let l:prevlnum = SkipRescriptBlanksAndComments(a:lnum-1)
if l:prevlnum == 0 " We're at top of file
return 0
endif
echom getline(l:prevlnum)
" Prev and current line with line-comments removed
let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '')
let l:thisl = substitute(getline(a:lnum), '//.*$', '', '')
let l:previ = indent(l:prevlnum)
let l:ind = l:previ
if l:prevl =~ '\v(\(|\{|\[|\=|\=\>)\s*$'
" Opened a block, assignment, fat arrow
let l:ind += shiftwidth()
endif
if l:thisl =~ '^\s*[)}\]]'
" Closed a blocked
let l:ind -= shiftwidth()
endif
return l:ind
endfunction