From 0a80e5bc67cfab3ce0cdd6fd98c5ac02db791a95 Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Wed, 7 Jan 2015 16:21:35 -0500 Subject: [PATCH] Add VtrSendFile command and docs Closes #30 - Add SendFile command proper --- doc/vim-tmux-runner.txt | 24 ++++++++++++++++++++++++ plugin/vim-tmux-runner.vim | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/doc/vim-tmux-runner.txt b/doc/vim-tmux-runner.txt index 30fb166..82e66a3 100644 --- a/doc/vim-tmux-runner.txt +++ b/doc/vim-tmux-runner.txt @@ -21,6 +21,7 @@ CONTENTS *vtr-contents* 2.11 ............................... |VtrClearRunner| 2.12 ............................... |VtrFlushCommand| 2.13 ............................... |VtrSendCtrlD| + 2.14 ............................... |VtrSendFile| 3. Configuration ................... |VTR-Configuration| 3.1 ................................ |VtrPercentage| 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 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* diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim index 6266b33..d1d3a7f 100644 --- a/plugin/vim-tmux-runner.vim +++ b/plugin/vim-tmux-runner.vim @@ -376,6 +376,33 @@ function! s:SendCtrlD() call s:SendKeys('') 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, ...) let ensure_pane = 0 if exists("a:1") @@ -385,9 +412,10 @@ function! VtrSendCommand(command, ...) endfunction function! s:DefineCommands() - command! -nargs=? VtrOpenRunner call s:EnsureRunnerPane() command! -bang -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner(0, ) command! -bang -range VtrSendLinesToRunner ,call s:SendLinesToRunner(0) + command! -bang VtrSendFile call s:SendFileViaVtr(0) + command! -nargs=? VtrOpenRunner call s:EnsureRunnerPane() command! VtrKillRunner call s:KillRunnerPane() command! VtrFocusRunner call s:FocusRunnerPane() command! VtrReorientRunner call s:ReorientRunner() @@ -412,6 +440,7 @@ function! s:DefineKeymaps() nnoremap dr :VtrDetachRunner nnoremap cr :VtrClearRunner nnoremap fc :VtrFlushCommand + nnoremap sf :VtrSendFile endif endfunction @@ -435,7 +464,6 @@ function! s:InitializeVariables() let s:vtr_orientation = g:VtrOrientation endfunction - call s:InitializeVariables() call s:DefineCommands() call s:DefineKeymaps()