From 15c6653869b19cc30cb814e61c117577edda3248 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 9 Feb 2018 16:31:54 +0800 Subject: [PATCH] Fix runner for python --- autoload/SpaceVim/layers/lang/python.vim | 16 +++++++++++++++- autoload/SpaceVim/plugins/highlight.vim | 14 ++++++++++++-- autoload/SpaceVim/plugins/iedit.vim | 21 ++++++++++++++++----- autoload/SpaceVim/plugins/runner.vim | 11 +++++++++++ doc/SpaceVim.txt | 10 ++++++++++ 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/python.vim b/autoload/SpaceVim/layers/lang/python.vim index 42a8616f4..2fd349ff2 100644 --- a/autoload/SpaceVim/layers/lang/python.vim +++ b/autoload/SpaceVim/layers/lang/python.vim @@ -41,7 +41,11 @@ function! SpaceVim#layers#lang#python#config() abort " }}} - call SpaceVim#plugins#runner#reg_runner('python', 'python %s') + call SpaceVim#plugins#runner#reg_runner('python', + \ { + \ 'exe' : function('s:getexe'), + \ 'opt' : [], + \ }) call SpaceVim#mapping#space#regesit_lang_mappings('python', function('s:language_specified_mappings')) call SpaceVim#layers#edit#add_ft_head_tamplate('python', \ ['#!/usr/bin/env python', @@ -99,3 +103,13 @@ function! s:language_specified_mappings() abort \ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) endif endfunction + +func! s:getexe() + let line = getline(1) + if line =~ '^#!' + let exe = split(line) + let exe[0] = exe[0][2:] + return exe + endif + return ['python'] +endf diff --git a/autoload/SpaceVim/plugins/highlight.vim b/autoload/SpaceVim/plugins/highlight.vim index 1916ef60c..46ad24948 100644 --- a/autoload/SpaceVim/plugins/highlight.vim +++ b/autoload/SpaceVim/plugins/highlight.vim @@ -7,8 +7,9 @@ "============================================================================= -function! SpaceVim#plugins#highlight#start() +function! SpaceVim#plugins#highlight#start() abort let state = SpaceVim#api#import('transient_state') + let stack = [] call state.set_title('Highlight Transient State') call state.defind_keys( \ { @@ -20,10 +21,19 @@ function! SpaceVim#plugins#highlight#start() \ } \ ) call state.open() - endfunction +function! s:next_item() abort + +endfunction +function! s:previous_item() abort + +endfunction + +function! s:toggle_item() abort + +endfunction " function() wrapper if v:version > 703 || v:version == 703 && has('patch1170') diff --git a/autoload/SpaceVim/plugins/iedit.vim b/autoload/SpaceVim/plugins/iedit.vim index d9a77c5d8..b61dd978b 100644 --- a/autoload/SpaceVim/plugins/iedit.vim +++ b/autoload/SpaceVim/plugins/iedit.vim @@ -60,7 +60,15 @@ endfunction function! s:remove_cursor_highlight() abort call clearmatches() endfunction - +"" +" public API for iedit mode +" > +" KEY: +" expr match expression +" word match word +" stack cursor pos stack +" < +" if only argv 1 is given, use selected word as pattern function! SpaceVim#plugins#iedit#start(...) let save_tve = &t_ve let save_cl = &l:cursorline @@ -81,6 +89,7 @@ function! SpaceVim#plugins#iedit#start(...) let symbol = argv.expr elseif has_key(argv, 'word') let symbol = argv.word + elseif has_key(argv, 'stack') endif elseif type(argv) == 0 && argv == 1 normal! gv"ky @@ -93,10 +102,12 @@ function! SpaceVim#plugins#iedit#start(...) call setpos('.', curpos) let begin = get(a:000, 1, 1) let end = get(a:000, 2, line('$')) - if use_expr - call s:parse_symbol(begin, end, symbol, 1) - else - call s:parse_symbol(begin, end, symbol) + if empty(s:stack) + if use_expr + call s:parse_symbol(begin, end, symbol, 1) + else + call s:parse_symbol(begin, end, symbol) + endif endif call s:highlight_cursor() redrawstatus! diff --git a/autoload/SpaceVim/plugins/runner.vim b/autoload/SpaceVim/plugins/runner.vim index bce1a002b..2e099e811 100644 --- a/autoload/SpaceVim/plugins/runner.vim +++ b/autoload/SpaceVim/plugins/runner.vim @@ -57,6 +57,17 @@ function! s:async_run(runner) abort \ 'on_stderr' : function('s:on_stderr'), \ 'on_exit' : function('s:on_compile_exit'), \ }) + elseif type(a:runner) == type({}) + let exe = call(a:runner.exe, []) + let cmd = exe + a:runner.opt + [bufname('%')] + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[Running] ' . join(cmd), '', repeat('-', 20)]) + let s:lines += 3 + let s:start_time = reltime() + let s:job_id = s:JOB.start(cmd,{ + \ 'on_stdout' : function('s:on_stdout'), + \ 'on_stderr' : function('s:on_stderr'), + \ 'on_exit' : function('s:on_exit'), + \ }) endif endfunction diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index b9945acf4..668a533e0 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -561,6 +561,16 @@ SpaceVim#logger#setLevel({level}) *SpaceVim#logger#setLevel()* SpaceVim#logger#setOutput({file}) *SpaceVim#logger#setOutput()* Set the log output file of SpaceVim. Default is empty. +SpaceVim#plugins#iedit#start() *SpaceVim#plugins#iedit#start()* + public API for iedit mode +> + KEY: + expr match expression + word match word + stack cursor pos stack +< + if only argv 1 is given, use selected word as pattern + ============================================================================== LAYERS *SpaceVim-layers*