-
Notifications
You must be signed in to change notification settings - Fork 111
/
floaterm.vim
67 lines (61 loc) · 1.98 KB
/
floaterm.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
"======================================================================
"
" floaterm.vim -
"
" Created by skywind on 2021/12/15
" Last Modified: 2023/03/17 12:26:25
"
"======================================================================
" vim: set ts=4 sw=4 tw=78 noet :
function! s:floaterm_close() abort
if &ft == 'floaterm' | return | endif
for b in tabpagebuflist()
if getbufvar(b, '&ft') == 'floaterm' &&
\ getbufvar(b, 'floaterm_jobexists') == v:false
execute b 'bwipeout!'
break
endif
endfor
autocmd! close-floaterm-runner
endfunc
"----------------------------------------------------------------------
" floaterm
"----------------------------------------------------------------------
function! asyncrun#runner#floaterm#run(opts)
if exists(':FloatermNew') != 2
return asyncrun#utils#errmsg('require voldikss/vim-floaterm')
endif
if exists('*asyncrun#script_write') == 0
return asyncrun#utils#errmsg('require asyncrun 2.7.8 or above')
endif
let cmd = 'FloatermNew '
let cmd .= ' --wintype=float'
if has_key(a:opts, 'position')
let cmd .= ' --position=' . fnameescape(a:opts.position)
endif
if has_key(a:opts, 'width')
let cmd .= ' --width=' . fnameescape(a:opts.width)
endif
if has_key(a:opts, 'height')
let cmd .= ' --height=' . fnameescape(a:opts.height)
endif
if has_key(a:opts, 'title')
let cmd .= ' --title=' . fnameescape(a:opts.title)
endif
let cmd .= ' --autoclose=' . get(a:opts, 'autoclose', 0)
let cmd .= ' --silent=' . get(a:opts, 'silent', 0)
let cwd = (a:opts.cwd == '')? getcwd() : (a:opts.cwd)
let cmd .= ' --cwd=' . fnameescape(cwd)
" for precisely arguments passing and shell builtin commands
" a temporary file is introduced
let cmd .= ' ' . fnameescape(asyncrun#script_write(a:opts.cmd, 0))
exec cmd
if get(a:opts, 'focus', 1) == 0
stopinsert | noa wincmd p
augroup close-floaterm-runner
autocmd!
autocmd CursorMoved,InsertEnter * ++nested
\ call timer_start(100, { -> s:floaterm_close() })
augroup END
endif
endfunc