mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 02:30:05 +08:00
Autoscroll runner and repl windows (#3125)
This commit is contained in:
parent
944fe9211f
commit
a146c3ec5f
@ -69,6 +69,27 @@ function! s:self.parse_string(line) abort
|
||||
return join(line, '')
|
||||
endfunction
|
||||
|
||||
|
||||
if exists('*nvim_win_set_cursor')
|
||||
function! s:self.win_set_cursor(win, pos) abort
|
||||
call nvim_win_set_cursor(a:win, a:pos)
|
||||
endfunction
|
||||
else
|
||||
function! s:self.win_set_cursor(win, pos) abort
|
||||
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if exists('*nvim_buf_line_count')
|
||||
function! s:self.buf_line_count(buf) abort
|
||||
return nvim_buf_line_count(a:buf)
|
||||
endfunction
|
||||
else
|
||||
function! s:self.buf_line_count(buf) abort
|
||||
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! SpaceVim#api#vim#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
@ -9,6 +9,7 @@
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:STRING = SpaceVim#api#import('data#string')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
|
||||
augroup spacevim_repl
|
||||
autocmd!
|
||||
@ -96,6 +97,7 @@ if has('nvim') && exists('*chanclose')
|
||||
if bufexists(s:bufnr)
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, map(s:_out_data[:-2], "substitute(v:val, '
$', '', 'g')"))
|
||||
let s:lines += len(s:_out_data) - 1
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
call s:update_statusline()
|
||||
endif
|
||||
let s:_out_data = ['']
|
||||
@ -103,6 +105,7 @@ if has('nvim') && exists('*chanclose')
|
||||
if bufexists(s:bufnr)
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, map(s:_out_data[:-2], "substitute(v:val, '
$', '', 'g')"))
|
||||
let s:lines += len(s:_out_data) - 1
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
call s:update_statusline()
|
||||
endif
|
||||
let s:_out_data = [s:_out_data[-1]]
|
||||
@ -113,6 +116,7 @@ else
|
||||
if bufexists(s:bufnr)
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
|
||||
let s:lines += len(a:data)
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
call s:update_statusline()
|
||||
endif
|
||||
endfunction
|
||||
@ -170,6 +174,7 @@ function! SpaceVim#plugins#repl#status() abort
|
||||
endfunction
|
||||
|
||||
let s:bufnr = 0
|
||||
let s:winid = -1
|
||||
function! s:open_windows() abort
|
||||
if s:bufnr != 0 && bufexists(s:bufnr)
|
||||
exe 'bd ' . s:bufnr
|
||||
@ -181,5 +186,6 @@ function! s:open_windows() abort
|
||||
set filetype=SpaceVimREPL
|
||||
nnoremap <silent><buffer> q :call <SID>close()<cr>
|
||||
let s:bufnr = bufnr('%')
|
||||
let s:winid = win_getid(winnr())
|
||||
wincmd p
|
||||
endfunction
|
||||
|
@ -10,11 +10,13 @@ let s:JOB = SpaceVim#api#import('job')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:STRING = SpaceVim#api#import('data#string')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
|
||||
|
||||
let s:runners = {}
|
||||
|
||||
let s:bufnr = 0
|
||||
let s:winid = -1
|
||||
|
||||
function! s:open_win() abort
|
||||
if s:bufnr != 0 && bufexists(s:bufnr)
|
||||
@ -36,6 +38,7 @@ function! s:open_win() abort
|
||||
nnoremap <silent><buffer> q :call SpaceVim#plugins#runner#close()<cr>
|
||||
nnoremap <silent><buffer> i :call <SID>insert()<cr>
|
||||
let s:bufnr = bufnr('%')
|
||||
let s:winid = win_getid(winnr())
|
||||
wincmd p
|
||||
endfunction
|
||||
|
||||
@ -239,6 +242,7 @@ if has('nvim') && exists('*chanclose')
|
||||
if !empty(lines)
|
||||
let lines = map(lines, "substitute(v:val, '
$', '', 'g')")
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines)
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
endif
|
||||
let s:lines += len(lines)
|
||||
let s:_out_data = ['']
|
||||
@ -257,6 +261,7 @@ if has('nvim') && exists('*chanclose')
|
||||
endif
|
||||
if !empty(lines)
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines)
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
endif
|
||||
let s:lines += len(lines)
|
||||
let s:_out_data = ['']
|
||||
@ -266,6 +271,7 @@ else
|
||||
function! s:on_stdout(job_id, data, event) abort
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
|
||||
let s:lines += len(a:data)
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
call s:update_statusline()
|
||||
endfunction
|
||||
|
||||
@ -273,6 +279,7 @@ else
|
||||
let s:status.has_errors = 1
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
|
||||
let s:lines += len(a:data)
|
||||
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
|
||||
call s:update_statusline()
|
||||
endfunction
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user