mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 05:40:05 +08:00
Add SpaceVimRunner
This commit is contained in:
parent
89d7e5324d
commit
228beb038d
@ -12,46 +12,54 @@ else
|
||||
endif
|
||||
|
||||
function! s:self.open(opts) abort
|
||||
let buf = get(a:opts, 'bufname', '')
|
||||
let mode = get(a:opts, 'mode', 'vertical topleft split')
|
||||
let Initfunc = get(a:opts, 'initfunc', '')
|
||||
let cmd = get(a:opts, 'cmd', '')
|
||||
if empty(buf)
|
||||
exe mode | enew
|
||||
else
|
||||
exe mode buf
|
||||
endif
|
||||
if !empty(Initfunc)
|
||||
call call(Initfunc, [])
|
||||
endif
|
||||
let buf = get(a:opts, 'bufname', '')
|
||||
let mode = get(a:opts, 'mode', 'vertical topleft split')
|
||||
let Initfunc = get(a:opts, 'initfunc', '')
|
||||
let cmd = get(a:opts, 'cmd', '')
|
||||
if empty(buf)
|
||||
exe mode | enew
|
||||
else
|
||||
exe mode buf
|
||||
endif
|
||||
if !empty(Initfunc)
|
||||
call call(Initfunc, [])
|
||||
endif
|
||||
|
||||
if !empty(cmd)
|
||||
exe cmd
|
||||
endif
|
||||
if !empty(cmd)
|
||||
exe cmd
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
func! s:self.resize(size, ...) abort
|
||||
let cmd = get(a:000, 0, 'vertical')
|
||||
exe cmd 'resize' a:size
|
||||
let cmd = get(a:000, 0, 'vertical')
|
||||
exe cmd 'resize' a:size
|
||||
endf
|
||||
|
||||
function! s:self.listed_buffers() abort
|
||||
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
|
||||
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:self.filter_do(expr) abort
|
||||
let buffers = range(1, bufnr('$'))
|
||||
for f_expr in a:expr.expr
|
||||
let buffers = filter(buffers, f_expr)
|
||||
endfor
|
||||
for b in buffers
|
||||
exe printf(a:expr.do, b)
|
||||
endfor
|
||||
let buffers = range(1, bufnr('$'))
|
||||
for f_expr in a:expr.expr
|
||||
let buffers = filter(buffers, f_expr)
|
||||
endfor
|
||||
for b in buffers
|
||||
exe printf(a:expr.do, b)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
" just same as nvim_buf_set_lines
|
||||
function! s:self.buf_set_lines(buffer, start, end, strict_indexing, replacement) abort
|
||||
if exists('*nvim_buf_set_lines')
|
||||
call nvim_buf_set_lines(a:buffer, a:start, a:end, a:strict_indexing, a:replacement)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
fu! SpaceVim#api#vim#buffer#get() abort
|
||||
return deepcopy(s:self)
|
||||
return deepcopy(s:self)
|
||||
endf
|
||||
|
@ -251,6 +251,8 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
||||
return '%#SpaceVim_statusline_a# Transient State %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'HelpDescribe'
|
||||
return '%#SpaceVim_statusline_a# HelpDescribe %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'SpaceVimRunner'
|
||||
return '%#SpaceVim_statusline_a# Runner %#SpaceVim_statusline_a_SpaceVim_statusline_b# %{SpaceVim#plugins#runner#status()}'
|
||||
endif
|
||||
if a:0 > 0
|
||||
return s:active()
|
||||
|
@ -22,7 +22,7 @@ function! SpaceVim#layers#lang#python#plugins() abort
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#lang#python#config() abort
|
||||
|
||||
call SpaceVim#plugins#runner#reg_runner('python', 'python %s')
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('python', funcref('s:language_specified_mappings'))
|
||||
call SpaceVim#layers#edit#add_ft_head_tamplate('python',
|
||||
\ ['#!/usr/bin/env python',
|
||||
|
@ -6,24 +6,49 @@
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
|
||||
let s:runners = {}
|
||||
|
||||
let s:bufnr = 0
|
||||
|
||||
function! s:open_win() abort
|
||||
|
||||
botright split __runner__
|
||||
let lines = &lines * 30 / 100
|
||||
exe 'resize ' . lines
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
|
||||
set filetype=SpaceVimRunner
|
||||
let s:bufnr = bufnr('%')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:async_run(runner) abort
|
||||
|
||||
let cmd = printf(a:runner, bufname('#'))
|
||||
call s:JOB.start(cmd,{
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ })
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:update_statusline() abort
|
||||
|
||||
redrawstatus
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#reg_runner(ft, runner)
|
||||
let s:runners[a:ft] = a:runner
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#open()
|
||||
let s:lines = 0
|
||||
let s:status = {
|
||||
\ 'is_running' : 0,
|
||||
\ 'is_exit' : 0,
|
||||
\ 'has_errors' : 0,
|
||||
\ 'exit_code' : 0
|
||||
\ }
|
||||
let runner = get(s:runners, &filetype, '')
|
||||
if !empty(runner)
|
||||
call s:open_win()
|
||||
@ -31,3 +56,29 @@ function! SpaceVim#plugins#runner#open()
|
||||
call s:update_statusline()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
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:update_statusline()
|
||||
endfunction
|
||||
|
||||
function! s:on_stderr(job_id, data, event) abort
|
||||
let s:status.has_errors = 1
|
||||
call s:update_statusline()
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(job_id, data, event) abort
|
||||
let s:status.is_exit = 1
|
||||
let s:status.exit_code = a:data
|
||||
call s:update_statusline()
|
||||
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#plugins#runner#status()
|
||||
if s:status.is_running == 1
|
||||
elseif s:status.is_exit == 1
|
||||
return 'exit code : ' . s:status.exit_code
|
||||
endif
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user