blob: e34fe5925d36ef84d90d01cb5c6d97e66ac6aea0 (
plain) (
blame)
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
|
let s:spt = {}
function! s:spt_open() dict abort
botright new
exec "resize " . self.opts.height
try
exec "buffer " . self.bufnr
catch
call termopen(self.opts.exec, {"detach": 0})
let self.bufnr = bufnr('%')
" term style
set nonumber
set norelativenumber
set signcolumn=no
" garbage collect after closing
let b:__split_term = self
execute 'autocmd BufWipeout <buffer> call getbufvar(' . self.bufnr . ', "__split_term").close()'
endtry
startinsert!
let self.winid = win_getid()
endfunction
let s:spt.open = funcref('s:spt_open')
function! s:spt_hide() dict abort
if win_gotoid(self.winid)
hide
else
echoerr 'split term window not found'
endif
endfunction
let s:spt.hide = funcref('s:spt_hide')
function! s:spt_close() dict abort
if win_gotoid(self.winid)
close
endif
unlet self.bufnr
unlet self.winid
endfunction
let s:spt.close = funcref('s:spt_close')
function! split_term#new(opts) abort
let spt = deepcopy(s:spt)
let opts = {
\ 'exec': $SHELL,
\ 'height': 20,
\ }
let spt.opts = extend(opts, a:opts)
return spt
endfunction
function! s:split_term_new(args) abort
if len(a:args) > 0
let opts = {'exec': join(a:args, ' ')}
endif
let g:split_term = split_term#new(exists('opts') ? opts : {})
endfunction
function! s:split_term_toggle(bang, ...) abort
if !a:bang
if !exists('g:split_term')
call s:split_term_new(a:000)
endif
call g:split_term.open()
else
if exists('g:split_term')
call g:split_term.hide()
endif
endif
endfunction
|