Skip to content

Commit 0f99f96

Browse files
author
skywind3000
committed
minor updates
1 parent b524b2d commit 0f99f96

File tree

2 files changed

+266
-1
lines changed

2 files changed

+266
-1
lines changed

autoload/asyncrun/compat.vim

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"======================================================================
99

1010

11+
"----------------------------------------------------------------------
12+
" internal
13+
"----------------------------------------------------------------------
14+
let s:windows = has('win32') || has('win95') || has('win64') || has('win16')
15+
let s:scripthome = fnamemodify(resolve(expand('<sfile>:p')), ':h')
16+
let s:python = -1
17+
18+
1119
"----------------------------------------------------------------------
1220
" glob files
1321
"----------------------------------------------------------------------
@@ -43,10 +51,38 @@ function! asyncrun#compat#list(path, ...)
4351
for n in split(part, "\n")
4452
let f = fnamemodify(n, ':t')
4553
if !empty(f)
46-
let candidate += [f]
54+
call add(candidate, f)
4755
endif
4856
endfor
4957
return candidate
5058
endfunc
5159

5260

61+
"----------------------------------------------------------------------
62+
" check python
63+
"----------------------------------------------------------------------
64+
function! asyncrun#compat#check_python()
65+
if s:python >= 0
66+
return s:python
67+
endif
68+
if !has('python3')
69+
if !has('python2')
70+
if !has('python')
71+
let s:python = 0
72+
return 0
73+
endif
74+
endif
75+
endif
76+
let s:python = 0
77+
try
78+
silent! pyx import os as __os
79+
silent! pyx import vim as __vim
80+
silent! pyx __vim.execute('let avail = 1')
81+
silent! let s:python = pyxeval('1')
82+
catch
83+
endtry
84+
return s:python
85+
endfunc
86+
87+
88+

autoload/asyncrun/info.vim

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
"======================================================================
2+
"
3+
" info.vim -
4+
"
5+
" Created by skywind on 2023/08/05
6+
" Last Modified: 2023/08/05 04:02:20
7+
"
8+
"======================================================================
9+
10+
11+
"----------------------------------------------------------------------
12+
" internal
13+
"----------------------------------------------------------------------
14+
let s:windows = has('win32') || has('win95') || has('win64') || has('win16')
15+
let s:scripthome = fnamemodify(resolve(expand('<sfile>:p')), ':h')
16+
17+
18+
"----------------------------------------------------------------------
19+
" list fts
20+
"----------------------------------------------------------------------
21+
function! asyncrun#info#list_fts()
22+
let output = []
23+
for name in asyncrun#compat#list($VIMRUNTIME . '/syntax', 1)
24+
let extname = fnamemodify(name, ':e')
25+
" echo name
26+
if extname == 'vim'
27+
call add(output, fnamemodify(name, ':t:r'))
28+
endif
29+
endfor
30+
return output
31+
endfunc
32+
33+
34+
"----------------------------------------------------------------------
35+
" list environment names
36+
"----------------------------------------------------------------------
37+
function! asyncrun#info#list_envname()
38+
if has('python3') == 0
39+
if has('python2') == 0
40+
return []
41+
endif
42+
endif
43+
let result = []
44+
try
45+
silent! pyx import os as __os
46+
silent! let result = pyxeval('[name for name in __os.environ]')
47+
catch
48+
endtry
49+
return result
50+
endfunc
51+
52+
53+
"----------------------------------------------------------------------
54+
"
55+
"----------------------------------------------------------------------
56+
function! asyncrun#info#list_path()
57+
return split($PATH, s:windows? ';' : ':')
58+
endfunc
59+
60+
61+
"----------------------------------------------------------------------
62+
"
63+
"----------------------------------------------------------------------
64+
function! asyncrun#info#list_exe_py()
65+
pyx << PYEOF
66+
if 1:
67+
import sys, os
68+
_sep = sys.platform[:3] == 'win' and ';' or ':'
69+
_search = os.environ.get('PATH', '').split(_sep)
70+
_exename = {}
71+
for _dirname in _search:
72+
if not os.path.exists(_dirname):
73+
continue
74+
for fn in os.listdir(_dirname):
75+
if _sep == ':':
76+
_exename[fn] = 1
77+
else:
78+
_fn, _ext = os.path.splitext(os.path.split(fn)[-1])
79+
if _ext in ('.exe', '.cmd', '.bat'):
80+
_exename[_fn] = 1
81+
_output = [n for n in _exename]
82+
_output.sort()
83+
PYEOF
84+
return pyxeval('_output')
85+
endfunc
86+
87+
88+
"----------------------------------------------------------------------
89+
"
90+
"----------------------------------------------------------------------
91+
function! asyncrun#info#list_executable()
92+
let output = {}
93+
let check = {'exe': 1, 'cmd':1, 'bat':1}
94+
if asyncrun#compat#check_python()
95+
return asyncrun#info#list_exe_py()
96+
endif
97+
for dirname in asyncrun#info#list_path()
98+
if !isdirectory(dirname)
99+
continue
100+
endif
101+
if s:windows != 0
102+
for ext in ['exe', 'cmd', 'bat']
103+
let part = asyncrun#compat#glob(dirname . '/*.' . ext, 1)
104+
for exename in split(part, "\n")
105+
let fn = fnamemodify(exename, ':t:r')
106+
let output[fn] = 1
107+
endfor
108+
endfor
109+
else
110+
let part = asyncrun#compat#glob(dirname . '/*', 1)
111+
for exename in split(part, "\n")
112+
if executable(exename)
113+
let fn = fnamemodify(exename, ':t')
114+
let output[fn] = 1
115+
endif
116+
endfor
117+
endif
118+
endfor
119+
return keys(output)
120+
endfunc
121+
122+
123+
"----------------------------------------------------------------------
124+
"
125+
"----------------------------------------------------------------------
126+
let g:asyncrun_info_pos = {
127+
\ 'tab': 'open the terminal in a new tab',
128+
\ 'TAB': 'open the terminal in a new tab on the left side',
129+
\ 'curwin': 'open the terminal in the current window',
130+
\ 'top': 'open the terminal above the current window',
131+
\ 'bottom': 'open the terminal below the current window',
132+
\ 'left': 'open the terminal on the left side',
133+
\ 'right': 'open the terminal on the right side',
134+
\ 'hide': "don't open a window, run in background",
135+
\ 'external': 'use an external terminal',
136+
\ }
137+
138+
139+
"----------------------------------------------------------------------
140+
" list runner
141+
"----------------------------------------------------------------------
142+
function! asyncrun#info#list_runner()
143+
let runners = {}
144+
for name in keys(get(g:, 'asyncrun_runner', {}))
145+
let runners[name] = 'runner'
146+
endfor
147+
for rtp in split(&rtp, ',')
148+
let t = rtp . '/autoload/asyncrun/runner'
149+
if isdirectory(t)
150+
for fn in asyncrun#compat#list(t, 1)
151+
let extname = fnamemodify(fn, ':e')
152+
let name = fnamemodify(fn, ':t:r')
153+
if extname == 'vim'
154+
let runners[name] = 'runner script'
155+
endif
156+
endfor
157+
endif
158+
endfor
159+
for fn in asyncrun#compat#list(s:scripthome . '/runner', 1)
160+
let extname = fnamemodify(fn, ':e')
161+
let name = fnamemodify(fn, ':t:r')
162+
if extname == 'vim'
163+
let runners[name] = 'runner script'
164+
endif
165+
endfor
166+
for name in keys(g:asyncrun_info_pos)
167+
let runners[name] = g:asyncrun_info_pos[name]
168+
endfor
169+
return runners
170+
endfunc
171+
172+
173+
"----------------------------------------------------------------------
174+
"
175+
"----------------------------------------------------------------------
176+
let g:asyncrun_info_program = {
177+
\ 'make': 'default makeprg',
178+
\ 'grep': 'default grepprg',
179+
\ }
180+
181+
if s:windows
182+
let g:asyncrun_info_program['wsl'] = 'program wsl'
183+
for t in ['msys', 'mingw32', 'mingw64', 'clang32', 'clang64', 'cygwin']
184+
let g:asyncrun_info_program[t] = 'builtin program'
185+
endfor
186+
endif
187+
188+
189+
"----------------------------------------------------------------------
190+
"
191+
"----------------------------------------------------------------------
192+
function! asyncrun#info#list_program()
193+
let program = {}
194+
for name in keys(get(g:, 'asyncrun_program', {}))
195+
let program[name] = 'program'
196+
endfor
197+
for rtp in split(&rtp, ',')
198+
let t = rtp . '/autoload/asyncrun/program'
199+
if isdirectory(t)
200+
for fn in asyncrun#compat#list(t, 1)
201+
let extname = fnamemodify(fn, ':e')
202+
let name = fnamemodify(fn, ':t:r')
203+
if extname == 'vim'
204+
let program[name] = 'program script'
205+
endif
206+
endfor
207+
endif
208+
endfor
209+
for fn in asyncrun#compat#list(s:scripthome . '/program', 1)
210+
let extname = fnamemodify(fn, ':e')
211+
let name = fnamemodify(fn, ':t:r')
212+
if extname == 'vim'
213+
let program[name] = 'program script'
214+
endif
215+
endfor
216+
for name in keys(g:asyncrun_info_program)
217+
let program[name] = g:asyncrun_info_program[name]
218+
endfor
219+
return program
220+
endfunc
221+
222+
223+
" echo len(asyncrun#info#list_exe_py())
224+
" echo len(asyncrun#info#list_executable())
225+
226+
" echo asyncrun#info#list_runner()
227+
" echo asyncrun#info#list_program()
228+
229+

0 commit comments

Comments
 (0)