-
Notifications
You must be signed in to change notification settings - Fork 6
/
jsx.vim
35 lines (33 loc) · 791 Bytes
/
jsx.vim
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
function! s:ScanFile()
let n = 1
let nmax = line("$")
if line("$") > 500
let nmax = 500
endif
while n < nmax
if getline(n) =~ "\\v<React\\."
return 1
break
endif
let n = n + 1
endwhile
return 0
endfunction
function! s:DetectJSX(file)
if a:file =~ "\\v\\.html"
if s:ScanFile()
set ft=html.jsx
endif
elseif a:file =~ "\\v(_spec|Spec|-test)\\.js"
if s:ScanFile()
set ft=javascript.jasmine.jsx
endif
elseif a:file =~ "\\v\\.js"
if s:ScanFile()
set ft=javascript.jsx
endif
endif
endfunction
autocmd BufNewFile,BufRead *.jsx set ft=javascript.jsx
autocmd BufNewFile,BufRead *{_spec,Spec,-test}.jsx set ft=javascript.jasmine.jsx
autocmd BufNewFile,BufRead *.html,*.js call s:DetectJSX(expand("<afile>"))