Add VtrSendFile command and docs
Closes #30 - Add SendFile command proper
This commit is contained in:
parent
d6a0abcb26
commit
0a80e5bc67
@ -21,6 +21,7 @@ CONTENTS *vtr-contents*
|
|||||||
2.11 ............................... |VtrClearRunner|
|
2.11 ............................... |VtrClearRunner|
|
||||||
2.12 ............................... |VtrFlushCommand|
|
2.12 ............................... |VtrFlushCommand|
|
||||||
2.13 ............................... |VtrSendCtrlD|
|
2.13 ............................... |VtrSendCtrlD|
|
||||||
|
2.14 ............................... |VtrSendFile|
|
||||||
3. Configuration ................... |VTR-Configuration|
|
3. Configuration ................... |VTR-Configuration|
|
||||||
3.1 ................................ |VtrPercentage|
|
3.1 ................................ |VtrPercentage|
|
||||||
3.2 ................................ |VtrOrientation|
|
3.2 ................................ |VtrOrientation|
|
||||||
@ -217,6 +218,29 @@ Send Ctrl-D key sequence to the runner without resetting the current command.
|
|||||||
This is useful if you are repeatedly running a script in the debugger and
|
This is useful if you are repeatedly running a script in the debugger and
|
||||||
regularly need to kill the repl.
|
regularly need to kill the repl.
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*VtrSendFile*
|
||||||
|
:VtrSendFile[!]
|
||||||
|
|
||||||
|
Send a command to execute the current file as a script. The command will be
|
||||||
|
crafted based on the filetype of the current buffer, e.g. for a file "foo.rb"
|
||||||
|
(filetype "ruby"), the command would be "ruby {filename}" with {filename}
|
||||||
|
populated based on the current file. There are default configurations provided
|
||||||
|
for ruby, javascript (via node), python, and sh. You can override and or add
|
||||||
|
by defining a dictionary in your Vimrc, e.g.:
|
||||||
|
|
||||||
|
let g:vtr_filteype_runner_overrides = {
|
||||||
|
\ 'ruby': 'ruby -w {file}',
|
||||||
|
\ 'haskell': 'runhaskell {file}'
|
||||||
|
\ }
|
||||||
|
|
||||||
|
The key for each entry should be the fileype, and the value is a string for
|
||||||
|
which the {file} portion will be replaced by the current file name when run.
|
||||||
|
Any settings in your g:vtr_filteype_runner_overrides will take precedence
|
||||||
|
over the default values.
|
||||||
|
|
||||||
|
This command expects a runner to be attached. Add ! to force a runner.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CONFIGURATION (3) *VTR-Configuration*
|
CONFIGURATION (3) *VTR-Configuration*
|
||||||
|
|
||||||
|
@ -376,6 +376,33 @@ function! s:SendCtrlD()
|
|||||||
call s:SendKeys('')
|
call s:SendKeys('')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendFileViaVtr(ensure_pane)
|
||||||
|
let runners = s:CurrentFiletypeRunners()
|
||||||
|
if has_key(runners, &filetype)
|
||||||
|
write
|
||||||
|
let runner = runners[&filetype]
|
||||||
|
let local_file_path = expand('%')
|
||||||
|
let run_command = substitute(runner, '{file}', local_file_path, 'g')
|
||||||
|
call VtrSendCommand(run_command, a:ensure_pane)
|
||||||
|
else
|
||||||
|
echoerr 'Unable to determine runner'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:CurrentFiletypeRunners()
|
||||||
|
let default_runners = {
|
||||||
|
\ 'ruby': 'ruby {file}',
|
||||||
|
\ 'javascript': 'node {file}',
|
||||||
|
\ 'python': 'python {file}',
|
||||||
|
\ 'sh': 'sh {file}'
|
||||||
|
\ }
|
||||||
|
if exists("g:vtr_filteype_runner_overrides")
|
||||||
|
return extend(copy(default_runners), g:vtr_filteype_runner_overrides)
|
||||||
|
else
|
||||||
|
return default_runners
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! VtrSendCommand(command, ...)
|
function! VtrSendCommand(command, ...)
|
||||||
let ensure_pane = 0
|
let ensure_pane = 0
|
||||||
if exists("a:1")
|
if exists("a:1")
|
||||||
@ -385,9 +412,10 @@ function! VtrSendCommand(command, ...)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:DefineCommands()
|
function! s:DefineCommands()
|
||||||
command! -nargs=? VtrOpenRunner call s:EnsureRunnerPane(<args>)
|
|
||||||
command! -bang -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner(<bang>0, <f-args>)
|
command! -bang -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner(<bang>0, <f-args>)
|
||||||
command! -bang -range VtrSendLinesToRunner <line1>,<line2>call s:SendLinesToRunner(<bang>0)
|
command! -bang -range VtrSendLinesToRunner <line1>,<line2>call s:SendLinesToRunner(<bang>0)
|
||||||
|
command! -bang VtrSendFile call s:SendFileViaVtr(<bang>0)
|
||||||
|
command! -nargs=? VtrOpenRunner call s:EnsureRunnerPane(<args>)
|
||||||
command! VtrKillRunner call s:KillRunnerPane()
|
command! VtrKillRunner call s:KillRunnerPane()
|
||||||
command! VtrFocusRunner call s:FocusRunnerPane()
|
command! VtrFocusRunner call s:FocusRunnerPane()
|
||||||
command! VtrReorientRunner call s:ReorientRunner()
|
command! VtrReorientRunner call s:ReorientRunner()
|
||||||
@ -412,6 +440,7 @@ function! s:DefineKeymaps()
|
|||||||
nnoremap <leader>dr :VtrDetachRunner<cr>
|
nnoremap <leader>dr :VtrDetachRunner<cr>
|
||||||
nnoremap <leader>cr :VtrClearRunner<cr>
|
nnoremap <leader>cr :VtrClearRunner<cr>
|
||||||
nnoremap <leader>fc :VtrFlushCommand<cr>
|
nnoremap <leader>fc :VtrFlushCommand<cr>
|
||||||
|
nnoremap <leader>sf :VtrSendFile<cr>
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -435,7 +464,6 @@ function! s:InitializeVariables()
|
|||||||
let s:vtr_orientation = g:VtrOrientation
|
let s:vtr_orientation = g:VtrOrientation
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
call s:InitializeVariables()
|
call s:InitializeVariables()
|
||||||
call s:DefineCommands()
|
call s:DefineCommands()
|
||||||
call s:DefineKeymaps()
|
call s:DefineKeymaps()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user