forked from vim-test/vim-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.vim
182 lines (154 loc) · 4.57 KB
/
strategy.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function! test#strategy#vimscript(cmd) abort
execute a:cmd
endfunction
function! test#strategy#basic(cmd) abort
if s:restorescreen()
execute '!'.s:pretty_command(a:cmd)
else
execute '!'.a:cmd
endif
endfunction
function! test#strategy#make(cmd) abort
let compiler = dispatch#compiler_for_program(a:cmd)
try
let default_makeprg = &l:makeprg
let default_errorformat = &l:errorformat
let default_compiler = get(b:, 'current_compiler', '')
if !empty(compiler)
execute 'compiler ' . compiler
endif
if s:restorescreen()
let &l:makeprg = s:pretty_command(a:cmd)
else
let &l:makeprg = a:cmd
endif
make
finally
let &l:makeprg = default_makeprg
let &l:errorformat = default_errorformat
if empty(default_compiler)
unlet! b:current_compiler
else
let b:current_compiler = default_compiler
endif
endtry
endfunction
function! test#strategy#neomake(cmd) abort
try
let compiler = dispatch#compiler_for_program(a:cmd)
catch
let compiler = ''
endtry
try
if !empty(compiler)
let default_makeprg = &l:makeprg
let default_errorformat = &l:errorformat
let default_compiler = get(b:, 'current_compiler', '')
execute 'compiler ' . compiler
endif
let cmd_parts = split(a:cmd, ' ')
let executable = cmd_parts[0]
let args = join(cmd_parts[1:], ' ')
let maker = {'exe': executable, 'name': executable, 'args': args, 'errorformat': &l:errorformat}
call neomake#Make(0, [maker])
finally
if !empty(compiler)
let &l:makeprg = default_makeprg
let &l:errorformat = default_errorformat
if empty(default_compiler)
unlet! b:current_compiler
else
let b:current_compiler = default_compiler
endif
endif
endtry
endfunction
function! test#strategy#asyncrun(cmd) abort
execute 'AsyncRun '.a:cmd
endfunction
function! test#strategy#dispatch(cmd) abort
execute 'Dispatch '.a:cmd
endfunction
function! test#strategy#vimproc(cmd) abort
execute 'VimProcBang '.a:cmd
endfunction
function! test#strategy#neovim(cmd) abort
let opts = {'suffix': ' # vim-test'}
function! opts.close_terminal()
if bufnr(self.suffix) != -1
execute 'bdelete!' bufnr(self.suffix)
end
endfunction
call opts.close_terminal()
botright new
call termopen(a:cmd . opts.suffix, opts)
au BufDelete <buffer> wincmd p
startinsert
endfunction
function! test#strategy#neoterm(cmd) abort
call neoterm#do(a:cmd)
endfunction
function! test#strategy#vtr(cmd) abort
call VtrSendCommand(s:pretty_command(a:cmd), 1)
endfunction
function! test#strategy#vimux(cmd) abort
if exists('g:test#preserve_screen') && !g:test#preserve_screen
if exists("g:VimuxRunnerIndex") && _VimuxHasRunner(g:VimuxRunnerIndex) != -1
call VimuxRunCommand(!s:Windows() ? 'clear' : 'cls')
call VimuxClearRunnerHistory()
endif
call VimuxRunCommand(s:command(a:cmd))
else
call VimuxRunCommand(s:pretty_command(a:cmd))
endif
endfunction
function! test#strategy#tslime(cmd) abort
call Send_to_Tmux(s:pretty_command(a:cmd)."\n")
endfunction
function! test#strategy#vimshell(cmd) abort
execute 'VimShellExecute '.a:cmd
endfunction
function! test#strategy#terminal(cmd) abort
call s:execute_script('osx_terminal', s:pretty_command(a:cmd))
endfunction
function! test#strategy#iterm(cmd) abort
call s:execute_script('osx_iterm', s:pretty_command(a:cmd))
endfunction
function! s:execute_script(name, cmd) abort
let script_path = g:test#plugin_path . '/bin/' . a:name
let cmd = join([script_path, shellescape(a:cmd)])
execute 'silent !'.cmd
endfunction
function! s:pretty_command(cmd) abort
let clear = !s:Windows() ? 'clear' : 'cls'
let cd = 'cd ' . shellescape(getcwd())
let echo = !s:Windows() ? 'echo -e '.shellescape(a:cmd) : 'Echo '.shellescape(a:cmd)
let separator = !s:Windows() ? '; ' : ' & '
if !get(g:, 'test#preserve_screen')
return join([l:clear, l:cd, l:echo, a:cmd], l:separator)
else
return join([l:cd, l:echo, a:cmd], l:separator)
endif
endfunction
function! s:command(cmd) abort
let cd = 'cd ' . shellescape(getcwd())
let separator = !s:Windows() ? '; ' : ' & '
return join([l:cd, a:cmd], l:separator)
endfunction
function! s:Windows() abort
return has('win32') && fnamemodify(&shell, ':t') ==? 'cmd.exe'
endfunction
function! s:restorescreen() abort
if s:Windows()
return &restorescreen
else
return !empty(&t_ti) || !empty(&t_te)
endif
endfunction
function! s:cat(filename) abort
if s:Windows()
return system('type '.a:filename)
else
return system('cat '.a:filename)
endif
endfunction