-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiddler.vim
76 lines (60 loc) · 2.05 KB
/
fiddler.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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"command! StartSeleniumClient call StartSeleniumClient()
command! -complete=custom,ListFiddles -nargs=1 OpenFiddle call OpenFiddle('<args>')
command! NewFiddle call NewFiddle()
command! JSLint call JSLint()
nmap <F4> :JSLint<CR>
function! JSLint()
! jslint % | tee /tmp/vimfiddler.jslint
setlocal errorformat=%-P%f,
\%-G/*jslint\ %.%#*/,
\%*[\ ]%n\ %l\\,%c:\ %m,
\%-G\ \ \ \ %.%#,
\%-GNo\ errors\ found.,
\%-Q
cf /tmp/vimfiddler.jslint
endfunction
function! ListFiddles(A,L,P)
return system("ls fiddles")
endfunction
function! ListTemplates(A,L,P)
return system("ls templates")
endfunction
function! OpenFiddle(fiddlename)
let htmlfile = "fiddles/" . a:fiddlename . "/index.html"
let jsfile = "fiddles/" . a:fiddlename . "/code.js"
execute "edit ". jsfile
execute "split " . htmlfile
call OpenFiddleInBrowser(a:fiddlename)
call WatchFile(jsfile)
call WatchFile(htmlfile)
endfunction
function! NewFiddle()
let fiddlename = input("Name: ")
let templatename = input("Use template: ", "default", "custom,ListTemplates")
call mkdir("fiddles/" . fiddlename)
exe "! cp templates/" . templatename . "/* fiddles/" . fiddlename
call OpenFiddle(fiddlename)
endfunction
function! WatchFile(filename)
exe "autocmd VimFiddler BufWritePost " . a:filename . " call Refresh()"
endfunction
function! OpenFiddleInBrowser(fiddlename)
call OpenURL("http://localhost/~" . $USER . "/vimfiddler/fiddles/" . a:fiddlename . "/")
endfunction
function! StartSeleniumClient()
python from selenium import webdriver
python browser = webdriver.Chrome()
endfunction
function! OpenURL(url)
execute ":python browser.get('" . a:url ."')"
endfunction
function! Refresh()
python browser.refresh()
endfunction
augroup VimFiddler
au!
augroup END
python import sys; sys.path.append(".")
echo 'Commands: StartSeleniumClient, OpenFiddle, NewFiddle'
echo 'Starting selenium webdriver'
call StartSeleniumClient()